Skip to content

Commit

Permalink
feat: add support for insecure skip verify on cli http clients
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteenb2 committed Nov 14, 2019
1 parent 1a28a32 commit 039ceca
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 53 deletions.
5 changes: 3 additions & 2 deletions cmd/influx/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,9 @@ func newAuthorizationService(f Flags) (platform.AuthorizationService, error) {
return newLocalKVService()
}
return &http.AuthorizationService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/influx/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ func newBucketService(f Flags) (platform.BucketService, error) {
return newLocalKVService()
}
return &http.BucketService{
Addr: f.host,
Token: f.token,
Addr: f.host,
Token: f.token,
InsecureSkipVerify: f.skipVerify,
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/influx/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func fluxDeleteF(cmd *cobra.Command, args []string) error {
}

s := &http.DeleteService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

ctx = signals.WithStandardSignals(ctx)
Expand Down
9 changes: 6 additions & 3 deletions cmd/influx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func init() {

influxCmd.PersistentFlags().BoolVar(&flags.local, "local", false, "Run commands locally against the filesystem")

influxCmd.PersistentFlags().BoolVar(&flags.skipVerify, "skip-verify", false, "SkipVerify controls whether a client verifies the server's certificate chain and host name.")

// Override help on all the commands tree
walk(influxCmd, func(c *cobra.Command) {
c.Flags().BoolP("help", "h", false, fmt.Sprintf("Help for the %s command ", c.Name()))
Expand All @@ -78,9 +80,10 @@ func main() {

// Flags contains all the CLI flag values for influx.
type Flags struct {
token string
host string
local bool
token string
host string
local bool
skipVerify bool
}

var flags Flags
Expand Down
5 changes: 3 additions & 2 deletions cmd/influx/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ func newOrganizationService(f Flags) (platform.OrganizationService, error) {
return newLocalKVService()
}
return &http.OrganizationService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}, nil
}

Expand Down
15 changes: 9 additions & 6 deletions cmd/influx/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ func newDashboardService(f Flags) (influxdb.DashboardService, error) {
return newLocalKVService()
}
return &http.DashboardService{
Addr: f.host,
Token: f.token,
Addr: f.host,
Token: f.token,
InsecureSkipVerify: flags.skipVerify,
}, nil
}

Expand All @@ -135,8 +136,9 @@ func newLabelService(f Flags) (influxdb.LabelService, error) {
return newLocalKVService()
}
return &http.LabelService{
Addr: f.host,
Token: f.token,
Addr: f.host,
Token: f.token,
InsecureSkipVerify: flags.skipVerify,
}, nil
}

Expand All @@ -145,8 +147,9 @@ func newVariableService(f Flags) (influxdb.VariableService, error) {
return newLocalKVService()
}
return &http.VariableService{
Addr: f.host,
Token: f.token,
Addr: f.host,
Token: f.token,
InsecureSkipVerify: flags.skipVerify,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/influx/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func fluxQueryF(cmd *cobra.Command, args []string) error {

flux.FinalizeBuiltIns()

r, err := getFluxREPL(flags.host, flags.token, orgID)
r, err := getFluxREPL(flags.host, flags.token, flags.skipVerify, orgID)
if err != nil {
return fmt.Errorf("failed to get the flux REPL: %v", err)
}
Expand Down
14 changes: 8 additions & 6 deletions cmd/influx/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func replF(cmd *cobra.Command, args []string) error {

flux.FinalizeBuiltIns()

r, err := getFluxREPL(flags.host, flags.token, orgID)
r, err := getFluxREPL(flags.host, flags.token, flags.skipVerify, orgID)
if err != nil {
return err
}
Expand All @@ -84,8 +84,9 @@ func replF(cmd *cobra.Command, args []string) error {

func findOrgID(ctx context.Context, org string) (platform.ID, error) {
svc := &http.OrganizationService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

o, err := svc.FindOrganization(ctx, platform.OrganizationFilter{
Expand All @@ -98,10 +99,11 @@ func findOrgID(ctx context.Context, org string) (platform.ID, error) {
return o.ID, nil
}

func getFluxREPL(addr, token string, orgID platform.ID) (*repl.REPL, error) {
func getFluxREPL(addr, token string, skipVerify bool, orgID platform.ID) (*repl.REPL, error) {
qs := &http.FluxQueryService{
Addr: addr,
Token: token,
Addr: addr,
Token: token,
InsecureSkipVerify: skipVerify,
}
q := &query.REPLQuerier{
OrganizationID: orgID,
Expand Down
35 changes: 21 additions & 14 deletions cmd/influx/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ func taskCreateF(cmd *cobra.Command, args []string) error {
}

s := &http.TaskService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

flux, err := repl.LoadQuery(args[0])
Expand Down Expand Up @@ -163,8 +164,9 @@ func init() {

func taskFindF(cmd *cobra.Command, args []string) error {
s := &http.TaskService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

filter := platform.TaskFilter{}
Expand Down Expand Up @@ -265,8 +267,9 @@ func init() {

func taskUpdateF(cmd *cobra.Command, args []string) error {
s := &http.TaskService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

var id platform.ID
Expand Down Expand Up @@ -339,8 +342,9 @@ func init() {

func taskDeleteF(cmd *cobra.Command, args []string) error {
s := &http.TaskService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

var id platform.ID
Expand Down Expand Up @@ -408,8 +412,9 @@ func init() {

func taskLogFindF(cmd *cobra.Command, args []string) error {
s := &http.TaskService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

var filter platform.LogFilter
Expand Down Expand Up @@ -482,8 +487,9 @@ func init() {

func taskRunFindF(cmd *cobra.Command, args []string) error {
s := &http.TaskService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

filter := platform.RunFilter{
Expand Down Expand Up @@ -570,8 +576,9 @@ func init() {

func runRetryF(cmd *cobra.Command, args []string) error {
s := &http.TaskService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

var taskID, runID platform.ID
Expand Down
22 changes: 12 additions & 10 deletions cmd/influx/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,30 @@ func init() {
userCmd.AddCommand(userUpdateCmd)
}

func newUserService(f Flags) (platform.UserService, error) {
func newUserService() (platform.UserService, error) {
if flags.local {
return newLocalKVService()
}
return &http.UserService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}, nil
}

func newUserResourceMappingService(f Flags) (platform.UserResourceMappingService, error) {
func newUserResourceMappingService() (platform.UserResourceMappingService, error) {
if flags.local {
return newLocalKVService()
}
return &http.UserResourceMappingService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}, nil
}

func userUpdateF(cmd *cobra.Command, args []string) error {
s, err := newUserService(flags)
s, err := newUserService()
if err != nil {
return err
}
Expand Down Expand Up @@ -116,7 +118,7 @@ func init() {
}

func userCreateF(cmd *cobra.Command, args []string) error {
s, err := newUserService(flags)
s, err := newUserService()
if err != nil {
return err
}
Expand Down Expand Up @@ -165,7 +167,7 @@ func init() {
}

func userFindF(cmd *cobra.Command, args []string) error {
s, err := newUserService(flags)
s, err := newUserService()
if err != nil {
return err
}
Expand Down Expand Up @@ -224,7 +226,7 @@ func init() {
}

func userDeleteF(cmd *cobra.Command, args []string) error {
s, err := newUserService(flags)
s, err := newUserService()
if err != nil {
return err
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/influx/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ func fluxWriteF(cmd *cobra.Command, args []string) error {
}

bs := &http.BucketService{
Addr: flags.host,
Token: flags.token,
Addr: flags.host,
Token: flags.token,
InsecureSkipVerify: flags.skipVerify,
}

var err error
Expand Down Expand Up @@ -144,9 +145,10 @@ func fluxWriteF(cmd *cobra.Command, args []string) error {

s := write.Batcher{
Service: &http.WriteService{
Addr: flags.host,
Token: flags.token,
Precision: writeFlags.Precision,
Addr: flags.host,
Token: flags.token,
Precision: writeFlags.Precision,
InsecureSkipVerify: flags.skipVerify,
},
}

Expand Down

0 comments on commit 039ceca

Please sign in to comment.