Skip to content

Commit

Permalink
vpn down fix - missing conf
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-hajek committed Mar 9, 2024
1 parent c701fd1 commit acc42ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/zeropsio/zcli/src/cmdBuilder"
"github.com/zeropsio/zcli/src/constants"
repository2 "github.com/zeropsio/zcli/src/entity/repository"
"github.com/zeropsio/zcli/src/entity/repository"
"github.com/zeropsio/zcli/src/errorsx"
"github.com/zeropsio/zcli/src/i18n"
"github.com/zeropsio/zcli/src/uxBlock"
Expand Down Expand Up @@ -61,7 +61,7 @@ func rootCmd() *cmdBuilder.Cmd {
if cmdData.CliStorage.Data().ScopeProjectId.Filled() {
// project scope is set
projectId, _ := cmdData.CliStorage.Data().ScopeProjectId.Get()
project, err := repository2.GetProjectById(ctx, cmdData.RestApiClient, projectId)
project, err := repository.GetProjectById(ctx, cmdData.RestApiClient, projectId)
if err != nil {
if errorsx.IsUserError(err) {
cmdData.UxBlocks.PrintWarning(styles.WarningLine(i18n.T(i18n.ScopedProjectNotFound)))
Expand Down
18 changes: 16 additions & 2 deletions src/cmd/vpnDown.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package cmd

import (
"context"
"os"
"os/exec"

"github.com/zeropsio/zcli/src/cmdBuilder"
"github.com/zeropsio/zcli/src/cmdRunner"
"github.com/zeropsio/zcli/src/constants"
"github.com/zeropsio/zcli/src/i18n"
"github.com/zeropsio/zcli/src/uxBlock/styles"
)
Expand All @@ -18,12 +20,24 @@ func vpnDownCmd() *cmdBuilder.Cmd {
LoggedUserRunFunc(func(ctx context.Context, cmdData *cmdBuilder.LoggedUserCmdData) error {
uxBlocks := cmdData.UxBlocks

filePath, err := constants.WgConfigFilePath()
if err != nil {
return err
}

// create empty file if not exists, only thing wg-quick needs is a proper file name
f, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return err
}
defer f.Close()

// TODO - janhajek check if vpn is connected
// TODO - janhajek get somehow a meaningful output
// TODO - janhajek check if wg-quick is installed
// TODO - janhajek a configurable path to wg-quick
c := exec.CommandContext(ctx, "wg-quick", "down", "zerops")
_, err := cmdRunner.Run(c)
c := exec.CommandContext(ctx, "wg-quick", "down", filePath)
_, err = cmdRunner.Run(c)
if err != nil {
return err
}
Expand Down

0 comments on commit acc42ca

Please sign in to comment.