From 75afff0b1447fb849cb1bc4ad2b877648e97bf42 Mon Sep 17 00:00:00 2001 From: Daniel Kerwin Date: Wed, 27 Nov 2019 10:55:39 +0100 Subject: [PATCH] Support build time provider specification --- Makefile | 3 ++- README.md | 8 ++++++++ cmd/auth.go | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 36bef6a..df3c9e2 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,8 @@ bin/$(ARCH)/$(BIN): -X $(PKG)/version.GITHASH=$(GIT_HASH) \ -X $(PKG)/version.DOB=$(DOB) \ -X $(PKG)/cmd.buildTimeClientID=$(CLIENT_ID) \ - -X $(PKG)/cmd.buildTimeClientSecret=$(CLIENT_SECRET)" + -X $(PKG)/cmd.buildTimeClientSecret=$(CLIENT_SECRET) \ + -X $(PKG)/cmd.buildTimeProvider=$(DEFAULT_PROVIDER)" # Run go vet on repo vet: diff --git a/README.md b/README.md index bed74d7..810435e 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,14 @@ It is possible to embed your Google credentials into the resulting binary. CLIENT_ID=abc123.apps.googleusercontent.com CLIENT_SECRET=mySecret OS=linux make ``` +You can streamline your user experience even more by also specifying a +default provider. `dexter auth` will then run the specified provider. +Valid choices are `google` and `azure`. + +``` +DEFAULT_PROVIDER=google make +``` + ## Run dexter Run `dexter` without a command to access the help screen/intro. diff --git a/cmd/auth.go b/cmd/auth.go index 20ee19c..c31c869 100644 --- a/cmd/auth.go +++ b/cmd/auth.go @@ -32,6 +32,7 @@ var ( // default injected at build time. This is optional buildTimeClientID string buildTimeClientSecret string + buildTimeProvider string // commandline flags clientID string @@ -48,9 +49,30 @@ var ( Long: `Use a provider sub-command to authenticate against your identity provider of choice. For details go to: https://blog.gini.net/ `, + RunE: DefaultCommand, } ) +// support build time providers. If the variable buildTimeProvider is set run the provider. +// FR: https://github.com/gini/dexter/issues/29 +func DefaultCommand(cmd *cobra.Command, args []string) error { + var realCommand func(cmd *cobra.Command, args []string) error + + // simple approach to select the provider + switch buildTimeProvider { + case "google": + realCommand = GoogleCommand + case "azure": + realCommand = AzureCommand + default: + // no valid provider found: default to usage + return cmd.Usage() + } + + log.Infof("Build time provider set to '%s'. Use flag --help for more options.", buildTimeProvider) + return realCommand(cmd, args) +} + // helper type to render the k8s config type CustomClaim struct { Email string `json:"email"`