-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auth list providers #1187
Auth list providers #1187
Conversation
that returns a struct because this will very likely be needed for other CLI functions like `auth login`
the auth name rather than the type described in the provider object (in line with the Python CLI)
pkg/cmd/dcos.go
Outdated
@@ -9,16 +9,20 @@ import ( | |||
|
|||
"github.com/dcos/dcos-cli/pkg/config" | |||
"github.com/spf13/cobra" | |||
"io" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should go in the previous import section (https://github.com/golang/go/wiki/CodeReviewComments#imports).
pkg/cmd/dcos.go
Outdated
) | ||
|
||
// rootCmd represents the base command when called without any subcommands. | ||
var rootCmd = &cobra.Command{ | ||
Use: "dcos", | ||
} | ||
|
||
var dcosConfig *Cluster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should avoid global variables in general, I know there are already some but this will be refactored. How about calling attachedCluster()
at the beginning of the list-provider command into a local variable?
pkg/cmd/dcos_auth_listproviders.go
Outdated
providers, err := getProviders() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of printing and calling exit like here or below, other commands define the RunE
func field and it can return an error.
pkg/cmd/dcos_auth_listproviders.go
Outdated
AuthTypeOIDCImplicitFlow = "oidc-implicit-flow" | ||
) | ||
|
||
var jsonOutput bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require having constructor-based commands rather than global variables like authListProviders
, but once this is done that'd be nice to have structs for options. Similar to the pattern here : https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/auth/cani.go#L39-L53
(I'm leaving this comment for reference not necessarily to tackle in this PR).
pkg/cmd/dcos_auth_listproviders.go
Outdated
AuthTypeDCOSUidPasswordLDAP = "dcos-uid-password-ldap" | ||
AuthTypeSAMLSpInitiated = "saml-sp-initiated" | ||
AuthTypeOIDCAuthCodeFlow = "oidc-authorization-code-flow" | ||
AuthTypeOIDCImplicitFlow = "oidc-implicit-flow" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JP suggests using the "login provider" semantic here, as authentication is only about sending the ACS token to DC/OS. We still have quite some docs using "auth provider" wording, but I'd rather use the wording recommended by the security team.
pkg/cmd/dcos_auth_listproviders.go
Outdated
"github.com/dcos/dcos-cli/pkg/httpclient" | ||
"github.com/olekukonko/tablewriter" | ||
"github.com/spf13/cobra" | ||
"os" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imports should be sorted as mentioned before.
pkg/cmd/dcos_auth_listproviders.go
Outdated
func init() { | ||
authCmd.AddCommand(authListProvidersCmd) | ||
authListProvidersCmd.Flags().BoolVar(&jsonOutput, "json", false, | ||
"returns providers in json format") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no line-length limit in Go, we use ~110 characters as a rule of thumb, a single line is fine here.
pkg/cmd/dcos_auth_listproviders.go
Outdated
} | ||
|
||
if jsonOutput { | ||
// re-marshal it into json with indents added in for pretty printing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use sentences starting with uppercase and ending with a dot. The cmd package was a quick proof of concept but we started doing this in other packages.
pkg/cmd/dcos_auth_listproviders.go
Outdated
|
||
func getProviders() (*map[string]authProvider, error) { | ||
var config = dcosConfig.Config | ||
var client = httpclient.New(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
httpclient
has been changed recently: 3560d63
pkg/cmd/dcos_auth_listproviders.go
Outdated
return nil, err | ||
} | ||
|
||
return &resp, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, this is enough as callers must check for the error and not for the pointer to be nil :
err = json.NewDecoder(response.Body).Decode(&resp)
return &resp, err
accurate here (oops)
to reduce usage of globals
making the config easier to swap out for testing or for the dcos_url argument that this will need to support
needing a config and update the list-providers command to allow it to take a custom cluster baseurl as an argument
Build failed due to a linter error (used |
I added Go tests on the linux builder Jenkinsfile, I will work on creating its own status check for the new CLI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few minor comments, in general it looks good to me.
Some things will most likely get refactored later on (extracting some parts of the command to a package, moving away from global vars).
pkg/cmd/dcos_auth_listproviders.go
Outdated
} | ||
|
||
func listProviders(cmd *cobra.Command, args []string) error { | ||
conf := attachedCluster().Config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary when an argument is passed, could you execute this only when no arg is passed?
pkg/cmd/dcos_auth_listproviders.go
Outdated
var desc string | ||
switch loginType { | ||
case LoginTypeDCOSUidPassword: | ||
desc = "Log in using a standard DC/OS user account (username and password)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: returning directly from switch cases removes the need for the lines surrounding the switch block.
pkg/cmd/dcos_auth_listproviders.go
Outdated
"github.com/olekukonko/tablewriter" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/dcos/dcos-cli/pkg/httpclient" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for separating this import from the other github imports? they should be grouped AFAIK
able to find a matching description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Adds the
list-providers
command to theauth
subcommand. It also makes some changes to how the CLI finds the config file in the newclusters/...
directory structure.