Skip to content

Commit

Permalink
Merge pull request #34 from gini/builtin_default_provider
Browse files Browse the repository at this point in the history
Support build time provider specification
  • Loading branch information
dkerwin authored Nov 27, 2019
2 parents 29238e1 + 75afff0 commit b83a8e9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
// default injected at build time. This is optional
buildTimeClientID string
buildTimeClientSecret string
buildTimeProvider string

// commandline flags
clientID string
Expand All @@ -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"`
Expand Down

0 comments on commit b83a8e9

Please sign in to comment.