Skip to content

Commit

Permalink
aaaa
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-hajek committed Jun 5, 2020
1 parent d0bbd38 commit 5221149
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func deployCmd() *cobra.Command {
defer closeFunc()

httpClient := httpClient.New(httpClient.Config{
HttpTimeout: time.Second * 10,
HttpTimeout: time.Minute * 15,
})

zipClient := zipClient.New(zipClient.Config{})
Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func ExecuteRootCmd(builtinToken string) {
Use: "zcli",
}

params.RegisterString(rootCmd, "restApiAddress", "https://api.zerops.io", "address of rest of zerops.io", paramsPackage.Persistent())
params.RegisterString(rootCmd, "grpcApiAddress", "api.zerops.io:20902", "address of grpc api of zerops.io", paramsPackage.Persistent())
params.RegisterString(rootCmd, "vpnAddress", "vpn.zerops.io", "address of vpn of zerops.io", paramsPackage.Persistent())
params.RegisterString(rootCmd, "restApiAddress", "https://api.zerops.io", "address of rest api", paramsPackage.Persistent())
params.RegisterString(rootCmd, "grpcApiAddress", "api.zerops.io:20902", "address of grpc api", paramsPackage.Persistent())
params.RegisterString(rootCmd, "vpnApiAddress", "vpn.zerops.io", "address of vpn api", paramsPackage.Persistent())
params.RegisterString(
rootCmd, "token", builtinToken, "authentication token",
paramsPackage.Persistent(),
Expand All @@ -53,7 +53,7 @@ func ExecuteRootCmd(builtinToken string) {

err = rootCmd.Execute()
if err != nil {
return
os.Exit(1)
}
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/startVpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func startVpnCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "startVpn projectId",
Use: "startVpn projectName",
SilenceUsage: true,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -42,15 +42,15 @@ func startVpnCmd() *cobra.Command {

return startVpn.New(
startVpn.Config{
VpnAddress: params.GetString("vpnAddress"),
VpnAddress: params.GetString("vpnApiAddress"),
UserId: certReader.UserId,
},
logger,
apiGrpcClient,
sudoers,
storage,
).Run(ctx, startVpn.RunConfig{
ProjectId: args[0],
ProjectName: args[0],
})
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/command/login/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (h *Handler) Run(_ context.Context, runConfig RunConfig) error {
return errors.New("param zeropsLogin must be set")
}
if runConfig.ZeropsPassword == "" {
return errors.New("param ZeropsPassword must be set")
return errors.New("param zeropsPassword must be set")
}

loginData, err := json.Marshal(struct {
Expand Down
34 changes: 28 additions & 6 deletions src/command/startVpn/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Config struct {
}

type RunConfig struct {
ProjectId string
ProjectName string
}

type Handler struct {
Expand Down Expand Up @@ -52,13 +52,35 @@ func New(

func (h *Handler) Run(ctx context.Context, config RunConfig) error {

if h.storage.Data.ProjectId != "" && config.ProjectId != h.storage.Data.ProjectId {
if config.ProjectName == "" {
return errors.New("project name must be filled")
}

projectsResponse, err := h.apiGrpcClient.GetProjectsByName(ctx, &zeropsApiProtocol.GetProjectsByNameRequest{
Name: config.ProjectName,
})
if err := helpers.HandleGrpcApiError(projectsResponse, err); err != nil {
return err
}

projectsResponse.GetOutput().GetProjects()

projects := projectsResponse.GetOutput().GetProjects()
if len(projects) == 0 {
return errors.New("project not found")
}
if len(projects) > 1 {
return errors.New("there are multiple project with same name")
}
project := projects[0]

if h.storage.Data.ProjectId != "" && project.GetId() != h.storage.Data.ProjectId {
if h.isVpnAlive() {
return errors.New("vpn is started for another project, use stopVpn first")
}
}

err := h.cleanVpn()
err = h.cleanVpn()
if err != nil {
return err
}
Expand All @@ -69,7 +91,7 @@ func (h *Handler) Run(ctx context.Context, config RunConfig) error {
}

apiVpnRequestResponse, err := h.apiGrpcClient.PostVpnRequest(ctx, &zeropsApiProtocol.PostVpnRequestRequest{
Id: config.ProjectId,
Id: project.GetId(),
ClientPublicKey: publicKey,
})
if err := helpers.HandleGrpcApiError(apiVpnRequestResponse, err); err != nil {
Expand Down Expand Up @@ -97,7 +119,7 @@ func (h *Handler) Run(ctx context.Context, config RunConfig) error {
defer closeFunc()

startVpnResponse, err := vpnGrpcClient.StartVpn(ctx, &zeropsVpnProtocol.StartVpnRequest{
InstanceId: config.ProjectId,
InstanceId: project.GetId(),
UserId: h.config.UserId,
ClientPublicKey: publicKey,
Signature: signature,
Expand All @@ -114,7 +136,7 @@ func (h *Handler) Run(ctx context.Context, config RunConfig) error {

h.logger.Info("\nclient is connected \n")

h.storage.Data.ProjectId = config.ProjectId
h.storage.Data.ProjectId = project.GetId()
err = h.storage.Save()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion src/service/sudoers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func runCommand(cmd *exec.Cmd) ([]byte, error) {
}
}
}
return nil, errors.New(errOutput.String())
return nil, err
}

return output.Bytes(), nil
Expand Down
2 changes: 1 addition & 1 deletion src/service/zipClient/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (h *Handler) Zip(source string, w io.Writer) error {

info, err := os.Stat(source)
if err != nil {
return nil
return err
}

var baseDir string
Expand Down

0 comments on commit 5221149

Please sign in to comment.