Skip to content

Commit

Permalink
Cleanup for adding --dry-run option
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Dec 16, 2023
1 parent 9be130c commit f2af7c4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 39 deletions.
39 changes: 20 additions & 19 deletions cmd/clace/app_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func initAppCommand(commonFlags []cli.Flag, clientConfig *utils.ClientConfig) *c
func appCreateCommand(commonFlags []cli.Flag, clientConfig *utils.ClientConfig) *cli.Command {
flags := make([]cli.Flag, 0, len(commonFlags)+2)
flags = append(flags, commonFlags...)
flags = append(flags, newBoolFlag("is_dev", "", "Is the application in development mode", false))
flags = append(flags, newBoolFlag("approve", "", "Approve the app permissions", false))
flags = append(flags, newStringFlag("auth_type", "", "The authentication type to use: can be default or none", "default"))
flags = append(flags, newStringFlag("branch", "", "The branch to checkout if using git source", "main"))
flags = append(flags, newStringFlag("commit", "", "The commit SHA to checkout if using git source. This takes precedence over branch", ""))
flags = append(flags, newStringFlag("git_auth", "", "The name of the git_auth entry to use", ""))
flags = append(flags, newBoolFlag("dev", "d", "Is the application in development mode", false))
flags = append(flags, newBoolFlag("approve", "a", "Approve the app permissions", false))
flags = append(flags, newStringFlag("auth-type", "", "The authentication type to use: can be default or none", "default"))
flags = append(flags, newStringFlag("branch", "b", "The branch to checkout if using git source", "main"))
flags = append(flags, newStringFlag("commit", "c", "The commit SHA to checkout if using git source. This takes precedence over branch", ""))
flags = append(flags, newStringFlag("git-auth", "g", "The name of the git_auth entry to use", ""))

return &cli.Command{
Name: "create",
Expand All @@ -50,12 +50,12 @@ func appCreateCommand(commonFlags []cli.Flag, clientConfig *utils.ClientConfig)
Create app from github source: clace app create --approve /disk_usage github.com/claceio/clace/examples/memory_usage/
Create app from local disk: clace app create --approve /disk_usage $HOME/clace_source/clace/examples/memory_usage/
Create app for development (source has to be disk): clace app create --approve --is_dev /disk_usage $HOME/clace_source/clace/examples/memory_usage/
Create app for development (source has to be disk): clace app create --approve --dev /disk_usage $HOME/clace_source/clace/examples/memory_usage/
Create app from a git commit: clace app create --approve --commit 1234567890 /disk_usage github.com/claceio/clace/examples/memory_usage/
Create app from a git branch: clace app create --approve --branch main /disk_usage github.com/claceio/clace/examples/memory_usage/
Create app using git url: clace app create --approve /disk_usage [email protected]:claceio/clace.git/examples/disk_usage
Create app using git url, with git private key auth: clace app create --approve --git_auth mykey /disk_usage [email protected]:claceio/privaterepo.git/examples/disk_usage
Create app for specified domain, no auth : clace app create --approve --auth_type=none clace.example.com:/ github.com/claceio/clace/examples/memory_usage/`,
Create app using git url, with git private key auth: clace app create --approve --git-auth mykey /disk_usage [email protected]:claceio/privaterepo.git/examples/disk_usage
Create app for specified domain, no auth : clace app create --approve --auth-type=none clace.example.com:/ github.com/claceio/clace/examples/memory_usage/`,
Action: func(cCtx *cli.Context) error {
if cCtx.NArg() != 2 {
return fmt.Errorf("require two arguments: <app_path> <app_source_url>")
Expand All @@ -68,11 +68,11 @@ Create app for specified domain, no auth : clace app create --approve --auth_typ

body := utils.CreateAppRequest{
SourceUrl: cCtx.Args().Get(1),
IsDev: cCtx.Bool("is_dev"),
AppAuthn: utils.AppAuthnType(cCtx.String("auth_type")),
IsDev: cCtx.Bool("dev"),
AppAuthn: utils.AppAuthnType(cCtx.String("auth-type")),
GitBranch: cCtx.String("branch"),
GitCommit: cCtx.String("commit"),
GitAuthName: cCtx.String("git_auth"),
GitAuthName: cCtx.String("git-auth"),
}
var auditResult utils.AuditResult
err := client.Post("/_clace/app", values, body, &auditResult)
Expand Down Expand Up @@ -235,7 +235,7 @@ func appDeleteCommand(commonFlags []cli.Flag, clientConfig *utils.ClientConfig)
func appAuditCommand(commonFlags []cli.Flag, clientConfig *utils.ClientConfig) *cli.Command {
flags := make([]cli.Flag, 0, len(commonFlags)+2)
flags = append(flags, commonFlags...)
flags = append(flags, newBoolFlag("approve", "", "Approve the app permissions", false))
flags = append(flags, newBoolFlag("approve", "a", "Approve the app permissions", false))

return &cli.Command{
Name: "audit",
Expand Down Expand Up @@ -288,11 +288,12 @@ func appAuditCommand(commonFlags []cli.Flag, clientConfig *utils.ClientConfig) *
func appReloadCommand(commonFlags []cli.Flag, clientConfig *utils.ClientConfig) *cli.Command {
flags := make([]cli.Flag, 0, len(commonFlags)+2)
flags = append(flags, commonFlags...)
flags = append(flags, newBoolFlag("approve", "", "Approve the app permissions", false))
flags = append(flags, newBoolFlag("promote", "", "Promote the change from stage to prod", false))
flags = append(flags, newStringFlag("branch", "", "The branch to checkout if using git source", ""))
flags = append(flags, newStringFlag("commit", "", "The commit SHA to checkout if using git source. This takes precedence over branch", ""))
flags = append(flags, newStringFlag("git_auth", "", "The name of the git_auth entry to use", ""))
flags = append(flags, newBoolFlag("approve", "a", "Approve the app permissions", false))
flags = append(flags, newBoolFlag("promote", "p", "Promote the change from stage to prod", false))
flags = append(flags, newStringFlag("branch", "b", "The branch to checkout if using git source", ""))
flags = append(flags, newStringFlag("commit", "c", "The commit SHA to checkout if using git source. This takes precedence over branch", ""))
flags = append(flags, newStringFlag("git-auth", "g", "The name of the git_auth entry to use", ""))
flags = append(flags, newBoolFlag("dry-run", "n", "Whether to run in dry run (check only) mode", false))

return &cli.Command{
Name: "reload",
Expand All @@ -312,7 +313,7 @@ func appReloadCommand(commonFlags []cli.Flag, clientConfig *utils.ClientConfig)
values.Add("promote", strconv.FormatBool(cCtx.Bool("promote")))
values.Add("branch", cCtx.String("branch"))
values.Add("commit", cCtx.String("commit"))
values.Add("gitAuth", cCtx.String("git_auth"))
values.Add("gitAuth", cCtx.String("git-auth"))

var response map[string]any
err := client.Post("/_clace/reload", values, nil, &response)
Expand Down
8 changes: 4 additions & 4 deletions cmd/clace/client_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func getClientCommands(clientConfig *utils.ClientConfig) ([]*cli.Command, error)
}

flags := []cli.Flag{
newAltStringFlag("server_uri", "s", "The server connection uri", defaultClientConfig.ServerUri, &clientConfig.ServerUri),
newAltStringFlag("admin_user", "u", "The admin user name", defaultClientConfig.AdminUser, &clientConfig.AdminUser),
newAltStringFlag("admin_password", "w", "The admin user password", defaultClientConfig.AdminPassword, &clientConfig.AdminPassword),
newAltBoolFlag("skip_cert_check", "k", "Skip TLS certificate verification", defaultClientConfig.SkipCertCheck, &clientConfig.SkipCertCheck),
newAltStringFlag("server-uri", "s", "The server connection uri", defaultClientConfig.ServerUri, &clientConfig.ServerUri),
newAltStringFlag("admin-user", "u", "The admin user name", defaultClientConfig.AdminUser, &clientConfig.AdminUser),
newAltStringFlag("admin-password", "w", "The admin user password", defaultClientConfig.AdminPassword, &clientConfig.AdminPassword),
newAltBoolFlag("skip-cert-check", "k", "Skip TLS certificate verification", defaultClientConfig.SkipCertCheck, &clientConfig.SkipCertCheck),
}

commands := make([]*cli.Command, 0, 6)
Expand Down
6 changes: 3 additions & 3 deletions tests/commander/test_load_app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tests:
load0010: # copy sample app
command: cp -r ../examples/disk_usage .
load0020: # create dev app
command: ../clace app create --is_dev /disk_usage_dev ./disk_usage
command: ../clace app create --dev /disk_usage_dev ./disk_usage
stderr:
line-count: 0
stdout: "App audit results /disk_usage_dev : app"
Expand Down Expand Up @@ -86,12 +86,12 @@ tests:
exit-code: 0
load0070: # Update app code
command: perl -pi -e 's/Disk Usage/DiskTest Usage/g' ./disk_usage/app.star && sleep 1
load0080: # with --is_dev, changes are picked up immediately
load0080: # with --dev, changes are picked up immediately
command: curl -su "admin:qwerty" localhost:25222/disk_usage_dev
stderr:
line-count: 0
stdout: "DiskTest Usage"
load0090: # without --is_dev, changes are not picked up
load0090: # without --dev, changes are not picked up
command: curl -su "admin:qwerty" localhost:25222/disk_usage_prod
stderr:
line-count: 0
Expand Down
2 changes: 1 addition & 1 deletion tests/commander/test_password.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests:
passwd0010:
command: ../clace app list --admin_password=abcd /invalid # Wrong password, but password is ignored over UDS
command: ../clace app list --admin-password=abcd /invalid # Wrong password, but password is ignored over UDS
stdout:
line-count: 1
exit-code: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/commander/test_reload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tests:
reload0010: # copy sample app
command: cp -r ./testapp reloadtest
reload0020: # create dev app
command: ../clace app create --is_dev /reload_dev ./reloadtest
command: ../clace app create --dev /reload_dev ./reloadtest
reload0030: # create local1 app
command: ../clace app create /reload_local1 ./reloadtest
reload0040: # create local2 app
Expand Down Expand Up @@ -155,7 +155,7 @@ tests:
stdout:
exactly: "0" # no apps at 1c119e7c5845e19845dd1d794268b350ced5b71b
reload0504: # app reload with invalid auth
command: ../clace app reload --git_auth=abc "/reload_git*"
command: ../clace app reload --git-auth=abc "/reload_git*"
exit-code: 1

# TODO test reload stdout messages
Expand Down
14 changes: 7 additions & 7 deletions tests/test_basics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ tests:
line-count: 1 # Only header is printed
exit-code: 0
basic020:
command: ../clace app list --server_uri=http://localhost:9154 /invalid # Wrong password
command: ../clace app list --server-uri=http://localhost:9154 /invalid # Wrong password
stderr:
exactly: "error: 404 page not found" # admin api's are disabled over http
stdout:
line-count: 0
exit-code: 1

basic030:
command: ../clace app list --server_uri=http://localhost:9154 --admin_password=abcd /invalid # No app
command: ../clace app list --server-uri=http://localhost:9154 --admin-password=abcd /invalid # No app
stderr:
exactly: "error: 404 page not found" # admin api's are disabled over http
stdout:
line-count: 0
exit-code: 1

basic040:
command: ../clace app list --server_uri=https://localhost:9155 --admin_password=abcd /invalid # Test TLS
command: ../clace app list --server-uri=https://localhost:9155 --admin-password=abcd /invalid # Test TLS
stderr: "tls: failed to verify certificate"
stdout:
line-count: 0
exit-code: 1

basic050:
command: ../clace app list --server_uri=https://localhost:9155 --admin_password=abcd --skip_cert_check /invalid # TLS with skip_cert_check
command: ../clace app list --server-uri=https://localhost:9155 --admin-password=abcd --skip-cert-check /invalid # TLS with skip_cert_check
stderr: "error: 404 page not found" # admin api's are disabled over http
stdout:
line-count: 0
Expand Down Expand Up @@ -58,7 +58,7 @@ tests:
exactly: "Authentication failed"

basic160: ## create test2 app with authentication disabled
command: ../clace app create --auth_type=none /test2 ./testapp
command: ../clace app create --auth-type=none /test2 ./testapp
exit-code: 0

basic161: ## Check static files are using optimized fetch path (no compression/decompression)
Expand Down Expand Up @@ -88,8 +88,8 @@ tests:
command: rm -rf ./testapp/static/gen ./testapp/index_gen.go.html ./testapp/config_gen.lock ./testapp/clace_gen.go.html
exit-code: 0

basic260: # create test3 app with auth specifically enabled. is_dev is used to check if files are created fine
command: ../clace app create --is_dev --auth_type=default /test3 ./testapp
basic260: # create test3 app with auth specifically enabled. dev is used to check if files are created fine
command: ../clace app create --dev --auth-type=default /test3 ./testapp
exit-code: 0

basic270: # check curl works with password
Expand Down
6 changes: 3 additions & 3 deletions tests/test_github_auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ tests:
stderr: "SSH_AUTH_SOCK not-specified"
exit-code: 1
github0030: # Create app, git url with commit id, with auth
command: ../clace app create --git_auth infoclace --approve /ghauth2 [email protected]:claceio/clace.git/examples/disk_usage
command: ../clace app create --git-auth infoclace --approve /ghauth2 [email protected]:claceio/clace.git/examples/disk_usage
stderr: ""
exit-code: 0
github0040: # Create app, git url with commit id, with auth
command: ../clace app create --git_auth infoclace --approve --commit fdda2c5dce481bee052810ad300adc23a9a53170 /ghauth3 [email protected]:claceio/clace.git/examples/disk_usage
command: ../clace app create --git-auth infoclace --approve --commit fdda2c5dce481bee052810ad300adc23a9a53170 /ghauth3 [email protected]:claceio/clace.git/examples/disk_usage
stderr: ""
exit-code: 0
github0050: # Create app, git url with commit id, with invalid auth
command: ../clace app create --git_auth invalid --approve --commit fdda2c5dce481bee052810ad300adc23a9a53170 /ghauth4 [email protected]:claceio/clace.git/examples/disk_usage
command: ../clace app create --git-auth invalid --approve --commit fdda2c5dce481bee052810ad300adc23a9a53170 /ghauth4 [email protected]:claceio/clace.git/examples/disk_usage
stderr: "git auth entry invalid not found in server config"
exit-code: 1

Expand Down

0 comments on commit f2af7c4

Please sign in to comment.