Skip to content

Commit

Permalink
Merge pull request #509 from versity/ben/admin_insecure
Browse files Browse the repository at this point in the history
feat: optional disable cert check for admin cli actions
  • Loading branch information
benmcclelland authored Apr 9, 2024
2 parents 020b2db + ffe1fc4 commit 936ba1f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cmd/versitygw/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"bytes"
"crypto/sha256"
"crypto/tls"
"encoding/hex"
"encoding/json"
"fmt"
Expand All @@ -37,6 +38,7 @@ var (
adminAccess string
adminSecret string
adminEndpoint string
allowInsecure bool
)

func adminCommand() *cli.Command {
Expand Down Expand Up @@ -154,10 +156,24 @@ func adminCommand() *cli.Command {
Required: true,
Destination: &adminEndpoint,
},
&cli.BoolFlag{
Name: "allow-insecure",
Usage: "disable tls certificate verification for the admin endpoint",
EnvVars: []string{"ADMIN_ALLOW_INSECURE"},
Aliases: []string{"ai"},
Destination: &allowInsecure,
},
},
}
}

func initHTTPClient() *http.Client {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: allowInsecure},
}
return &http.Client{Transport: tr}
}

func createUser(ctx *cli.Context) error {
access, secret, role := ctx.String("access"), ctx.String("secret"), ctx.String("role")
userID, groupID, projectID := ctx.Int("user-id"), ctx.Int("group-id"), ctx.Int("projectID")
Expand Down Expand Up @@ -199,7 +215,7 @@ func createUser(ctx *cli.Context) error {
return fmt.Errorf("failed to sign the request: %w", err)
}

client := http.Client{}
client := initHTTPClient()

resp, err := client.Do(req)
if err != nil {
Expand Down Expand Up @@ -244,7 +260,7 @@ func deleteUser(ctx *cli.Context) error {
return fmt.Errorf("failed to sign the request: %w", err)
}

client := http.Client{}
client := initHTTPClient()

resp, err := client.Do(req)
if err != nil {
Expand Down Expand Up @@ -284,7 +300,7 @@ func listUsers(ctx *cli.Context) error {
return fmt.Errorf("failed to sign the request: %w", err)
}

client := http.Client{}
client := initHTTPClient()

resp, err := client.Do(req)
if err != nil {
Expand Down Expand Up @@ -399,7 +415,7 @@ func listBuckets(ctx *cli.Context) error {
return fmt.Errorf("failed to sign the request: %w", err)
}

client := http.Client{}
client := initHTTPClient()

resp, err := client.Do(req)
if err != nil {
Expand Down

0 comments on commit 936ba1f

Please sign in to comment.