Skip to content
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

Merged
merged 22 commits into from
Mar 29, 2018
Merged

Auth list providers #1187

merged 22 commits into from
Mar 29, 2018

Conversation

br-lewis
Copy link
Contributor

Adds the list-providers command to the auth subcommand. It also makes some changes to how the CLI finds the config file in the new clusters/... directory structure.

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)
@br-lewis br-lewis requested a review from bamarni March 27, 2018 14:46
pkg/cmd/dcos.go Outdated
@@ -9,16 +9,20 @@ import (

"github.com/dcos/dcos-cli/pkg/config"
"github.com/spf13/cobra"
"io"
Copy link
Contributor

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
Copy link
Contributor

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?

providers, err := getProviders()
if err != nil {
fmt.Println(err)
os.Exit(1)
Copy link
Contributor

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.

AuthTypeOIDCImplicitFlow = "oidc-implicit-flow"
)

var jsonOutput bool
Copy link
Contributor

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).

AuthTypeDCOSUidPasswordLDAP = "dcos-uid-password-ldap"
AuthTypeSAMLSpInitiated = "saml-sp-initiated"
AuthTypeOIDCAuthCodeFlow = "oidc-authorization-code-flow"
AuthTypeOIDCImplicitFlow = "oidc-implicit-flow"
Copy link
Contributor

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.

"github.com/dcos/dcos-cli/pkg/httpclient"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"os"
Copy link
Contributor

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.

func init() {
authCmd.AddCommand(authListProvidersCmd)
authListProvidersCmd.Flags().BoolVar(&jsonOutput, "json", false,
"returns providers in json format")
Copy link
Contributor

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.

}

if jsonOutput {
// re-marshal it into json with indents added in for pretty printing
Copy link
Contributor

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.


func getProviders() (*map[string]authProvider, error) {
var config = dcosConfig.Config
var client = httpclient.New(config)
Copy link
Contributor

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

return nil, err
}

return &resp, nil
Copy link
Contributor

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

@br-lewis
Copy link
Contributor Author

Build failed due to a linter error (used Url instead of URL in a variable name) but why did only 1 fail?

@bamarni
Copy link
Contributor

bamarni commented Mar 28, 2018

Build failed due to a linter error (used Url instead of URL in a variable name) but why did only 1 fail?

I added Go tests on the linux builder Jenkinsfile, I will work on creating its own status check for the new CLI.

Copy link
Contributor

@bamarni bamarni left a 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).

}

func listProviders(cmd *cobra.Command, args []string) error {
conf := attachedCluster().Config
Copy link
Contributor

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?

var desc string
switch loginType {
case LoginTypeDCOSUidPassword:
desc = "Log in using a standard DC/OS user account (username and password)"
Copy link
Contributor

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.

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"

"github.com/dcos/dcos-cli/pkg/httpclient"
Copy link
Contributor

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

Copy link
Contributor

@bamarni bamarni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@bamarni bamarni merged commit fe1fd6f into dcos:master Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants