Skip to content

Commit 863ea20

Browse files
committed
Merge branch '87-cli-insecure-configuration-parameter' into 'master'
Allow specifying "insecure" flag in the configuration for a particular Database Lab instance. (#87) # Examples ``` ./bin/dblab config create --url "http://stage.example.com" --token "stage_token" --insecure=true stage ``` See merge request postgres-ai/database-lab!70
2 parents 8fd529a + 90724e9 commit 863ea20

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ For stable Docker images see [postgresai/dblab-server](https://hub.docker.com/re
7070

7171
## Client CLI
7272
### Installation
73-
Install Database Lab client CLI on a Linux acrhitecture (e.g., Ubuntu):
73+
Install Database Lab client CLI on a Linux architecture (e.g., Ubuntu):
7474
```bash
7575
curl https://gitlab.com/postgres-ai/database-lab/-/raw/master/cli-install.sh | bash
7676
```

cmd/cli/commands/config/command_list.go

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func CommandList() []*cli.Command {
3333
Usage: "verification token of Database Lab instance",
3434
Required: true,
3535
},
36+
&cli.BoolFlag{
37+
Name: "insecure",
38+
Usage: "allow insecure server connections when using SSL",
39+
},
3640
},
3741
},
3842
{
@@ -49,6 +53,10 @@ func CommandList() []*cli.Command {
4953
Name: "token",
5054
Usage: "verification token of Database Lab instance",
5155
},
56+
&cli.BoolFlag{
57+
Name: "insecure",
58+
Usage: "allow insecure server connections when using SSL",
59+
},
5260
},
5361
},
5462
{

cmd/cli/commands/config/environment.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Environment struct {
2323
EnvironmentID string `yaml:"-" json:"environment_id"`
2424
URL string `yaml:"url" json:"url"`
2525
Token string `yaml:"token" json:"token"`
26+
Insecure bool `yaml:"insecure" json:"insecure"`
2627
}
2728

2829
// AddEnvironmentToConfig adds a new environment to CLIConfig.
@@ -36,8 +37,9 @@ func AddEnvironmentToConfig(c *cli.Context, cfg *CLIConfig, environmentID string
3637
}
3738

3839
env := Environment{
39-
URL: c.String(commands.URLKey),
40-
Token: c.String(commands.TokenKey),
40+
URL: c.String(commands.URLKey),
41+
Token: c.String(commands.TokenKey),
42+
Insecure: c.Bool(commands.InsecureKey),
4143
}
4244

4345
if cfg.Environments == nil {
@@ -67,14 +69,18 @@ func updateEnvironmentInConfig(c *cli.Context, cfg *CLIConfig, environmentID str
6769

6870
newEnvironment := environment
6971

70-
if c.String(commands.URLKey) != "" {
72+
if c.IsSet(commands.URLKey) {
7173
newEnvironment.URL = c.String(commands.URLKey)
7274
}
7375

74-
if c.String(commands.TokenKey) != "" {
76+
if c.IsSet(commands.TokenKey) {
7577
newEnvironment.Token = c.String(commands.TokenKey)
7678
}
7779

80+
if c.IsSet(commands.InsecureKey) {
81+
newEnvironment.Insecure = c.Bool(commands.InsecureKey)
82+
}
83+
7884
if newEnvironment == environment {
7985
return errors.New("config unchanged. Set different option values to update.") // nolint
8086
}

cmd/cli/main.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"os"
7+
"strconv"
78

89
"github.com/urfave/cli/v2"
910

@@ -17,7 +18,7 @@ import (
1718
)
1819

1920
const (
20-
version = "v0.0.1"
21+
version = "v0.2.1"
2122
)
2223

2324
func main() {
@@ -81,17 +82,23 @@ func loadEnvironmentParams(c *cli.Context) error {
8182

8283
currentEnv := cfg.CurrentEnvironment
8384
if env, ok := cfg.Environments[currentEnv]; ok {
84-
if c.String(commands.URLKey) == "" {
85+
if !c.IsSet(commands.URLKey) {
8586
if err := c.Set(commands.URLKey, env.URL); err != nil {
8687
return err
8788
}
8889
}
8990

90-
if c.String(commands.TokenKey) == "" {
91+
if !c.IsSet(commands.TokenKey) {
9192
if err := c.Set(commands.TokenKey, env.Token); err != nil {
9293
return err
9394
}
9495
}
96+
97+
if !c.IsSet(commands.InsecureKey) {
98+
if err := c.Set(commands.InsecureKey, strconv.FormatBool(env.Insecure)); err != nil {
99+
return err
100+
}
101+
}
95102
}
96103

97104
return nil

0 commit comments

Comments
 (0)