From 3fb249bc9fec7c202908a92497bd897b10989aba Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Wed, 1 Aug 2018 14:39:28 -0400 Subject: [PATCH 01/11] add oauth providers via cli --- cmd/admin.go | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/cmd/admin.go b/cmd/admin.go index 4fb0810c660dc..e20f9dc94cd9d 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/git" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/auth/oauth2" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -26,6 +27,7 @@ var ( subcmdChangePassword, subcmdRepoSyncReleases, subcmdRegenerate, + subcmdAuth, }, } @@ -121,6 +123,82 @@ var ( }, }, } + + subcmdAuth = cli.Command{ + Name: "auth", + Usage: "add auth sources", + Subcommands: []cli.Command{ + microcmdAuthOauth, + }, + } + + microcmdAuthOauth = cli.Command{ + Name: "oauth", + Usage: "Add new Oauth authentication source", + Action: runAddOauth, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, + cli.StringFlag{ + Name: "name", + Value: "", + Usage: "Application Name", + }, + cli.StringFlag{ + Name: "provider", + Value: "", + Usage: "OAuth2 Provider", + }, + cli.StringFlag{ + Name: "key", + Value: "", + Usage: "Client ID (Key)", + }, + cli.StringFlag{ + Name: "secret", + Value: "", + Usage: "Client Secret", + }, + cli.StringFlag{ + Name: "secret", + Value: "", + Usage: "Client Secret", + }, + cli.StringFlag{ + Name: "auto-discover-url", + Value: "", + Usage: "OpenID Connect Auto Discovery URL (only required when using OpenID Connect as provider)", + }, + cli.StringFlag{ + Name: "use-custom-urls", + Value: "false", + Usage: "Use custom URLs for GitLab/GitHub OAuth endpoints", + }, + cli.StringFlag{ + Name: "custom-auth-url", + Value: "", + Usage: "Use a custom Authorize URL (option for GitLab/GitHub)", + }, + cli.StringFlag{ + Name: "custom-token-url", + Value: "", + Usage: "Use a custom Token URL (option for GitLab/GitHub)", + }, + cli.StringFlag{ + Name: "custom-profile-url", + Value: "", + Usage: "Use a custom Profile URL (option for GitLab/GitHub)", + }, + cli.StringFlag{ + Name: "custom-email-url", + Value: "", + Usage: "Use a custom Email URL (option for GitHub)", + }, + }, + } ) func runChangePassword(c *cli.Context) error { @@ -262,3 +340,45 @@ func runRegenerateKeys(c *cli.Context) error { } return models.RewriteAllPublicKeys() } + +func parseOAuth2Config(c *cli.Context) *models.OAuth2Config { + var customURLMapping *oauth2.CustomURLMapping + if c.IsSet("use-custom-urls") { + customURLMapping = &oauth2.CustomURLMapping{ + TokenURL: c.String("custom-token-url"), + AuthURL: c.String("custom-auth-url"), + ProfileURL: c.String("custom-profile-url"), + EmailURL: c.String("custom-email-url"), + } + } else { + customURLMapping = nil + } + return &models.OAuth2Config{ + Provider: c.String("provider"), + ClientID: c.String("key"), + ClientSecret: c.String("secret"), + OpenIDConnectAutoDiscoveryURL: c.String("auto-discover-url"), + CustomURLMapping: customURLMapping, + } +} + +func runAddOauth(c *cli.Context) error { + if c.IsSet("config") { + setting.CustomConf = c.String("config") + } + + if err := initDB(); err != nil { + return err + } + + if err := models.CreateLoginSource(&models.LoginSource{ + Type: models.LoginOAuth2, + Name: c.String("name"), + IsActived: true, + Cfg: parseOAuth2Config(c), + }); err != nil { + return err + } + + return nil +} From c14da072077a07807a7dca72463198b7643c3e6d Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 23 Aug 2018 16:19:04 -0400 Subject: [PATCH 02/11] update text, and change command to `add` --- cmd/admin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index e20f9dc94cd9d..ebbe6f4e38de1 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -133,7 +133,7 @@ var ( } microcmdAuthOauth = cli.Command{ - Name: "oauth", + Name: "add-oauth", Usage: "Add new Oauth authentication source", Action: runAddOauth, Flags: []cli.Flag{ @@ -180,7 +180,7 @@ var ( cli.StringFlag{ Name: "custom-auth-url", Value: "", - Usage: "Use a custom Authorize URL (option for GitLab/GitHub)", + Usage: "Use a custom Authorization URL (option for GitLab/GitHub)", }, cli.StringFlag{ Name: "custom-token-url", From 081c943bfb739f3aed302d8361d691b57d4f5c08 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Thu, 23 Aug 2018 16:59:11 -0400 Subject: [PATCH 03/11] add update command, and list command --- cmd/admin.go | 145 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 142 insertions(+), 3 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index ebbe6f4e38de1..5063684fe1cec 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -7,6 +7,8 @@ package cmd import ( "fmt" + "os" + "text/tabwriter" "code.gitea.io/git" "code.gitea.io/gitea/models" @@ -126,13 +128,98 @@ var ( subcmdAuth = cli.Command{ Name: "auth", - Usage: "add auth sources", + Usage: "Modify external auth providers", Subcommands: []cli.Command{ - microcmdAuthOauth, + microcmdAuthAddOauth, }, } - microcmdAuthOauth = cli.Command{ + microcmdAuthList = cli.Command{ + Name: "list", + Usage: "List auth sources", + Action: runListAuth, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, + }, + } + + microcmdAuthUpdateOauth = cli.Command{ + Name: "update-oauth", + Usage: "Update existing Oauth authentication source", + Action: runUpdateOauth, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, + cli.Int64Flag{ + Name: "id", + Usage: "ID of Oauth authentication source that will be updated", + }, + cli.StringFlag{ + Name: "name", + Value: "", + Usage: "Application Name", + }, + cli.StringFlag{ + Name: "provider", + Value: "", + Usage: "OAuth2 Provider", + }, + cli.StringFlag{ + Name: "key", + Value: "", + Usage: "Client ID (Key)", + }, + cli.StringFlag{ + Name: "secret", + Value: "", + Usage: "Client Secret", + }, + cli.StringFlag{ + Name: "secret", + Value: "", + Usage: "Client Secret", + }, + cli.StringFlag{ + Name: "auto-discover-url", + Value: "", + Usage: "OpenID Connect Auto Discovery URL (only required when using OpenID Connect as provider)", + }, + cli.StringFlag{ + Name: "use-custom-urls", + Value: "false", + Usage: "Use custom URLs for GitLab/GitHub OAuth endpoints", + }, + cli.StringFlag{ + Name: "custom-auth-url", + Value: "", + Usage: "Use a custom Authorization URL (option for GitLab/GitHub)", + }, + cli.StringFlag{ + Name: "custom-token-url", + Value: "", + Usage: "Use a custom Token URL (option for GitLab/GitHub)", + }, + cli.StringFlag{ + Name: "custom-profile-url", + Value: "", + Usage: "Use a custom Profile URL (option for GitLab/GitHub)", + }, + cli.StringFlag{ + Name: "custom-email-url", + Value: "", + Usage: "Use a custom Email URL (option for GitHub)", + }, + }, + } + + microcmdAuthAddOauth = cli.Command{ Name: "add-oauth", Usage: "Add new Oauth authentication source", Action: runAddOauth, @@ -382,3 +469,55 @@ func runAddOauth(c *cli.Context) error { return nil } + +func runUpdateOauth(c *cli.Context) error { + if c.IsSet("config") { + setting.CustomConf = c.String("config") + } + + if !c.IsSet("id") { + return fmt.Errorf("--id flag is missing") + } + + if err := initDB(); err != nil { + return err + } + + if err := models.UpdateSource(&models.LoginSource{ + ID: c.Int64("id"), + Type: models.LoginOAuth2, + Name: c.String("name"), + IsActived: true, + Cfg: parseOAuth2Config(c), + }); err != nil { + return err + } + + return nil +} + +func runListAuth(c *cli.Context) error { + if c.IsSet("config") { + setting.CustomConf = c.String("config") + } + + if err := initDB(); err != nil { + return err + } + + loginSources, err := models.LoginSources() + + if err != nil { + return err + } + + // loop through each source and print + w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight) + fmt.Fprintf(w, "ID\tName\tType\tEnabled") + for _, source := range loginSources { + fmt.Fprintf(w, "%d\t%s\t%s\t%t", source.ID, source.Name, models.LoginNames[source.Type], source.IsActived) + } + w.Flush() + + return nil +} From 60613edccfcddf7b21bca3b108693529ff7c07d7 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Thu, 23 Aug 2018 17:04:00 -0400 Subject: [PATCH 04/11] add delete function --- cmd/admin.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/cmd/admin.go b/cmd/admin.go index 5063684fe1cec..163c56f6c6079 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -131,6 +131,9 @@ var ( Usage: "Modify external auth providers", Subcommands: []cli.Command{ microcmdAuthAddOauth, + microcmdAuthUpdateOauth, + microcmdAuthList, + microcmdAuthDelete, }, } @@ -147,6 +150,23 @@ var ( }, } + microcmdAuthDelete = cli.Command{ + Name: "delete", + Usage: "Delete specific auth source", + Action: runDeleteAuth, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, + cli.Int64Flag{ + Name: "id", + Usage: "ID of authentication source that will be deleted", + }, + }, + } + microcmdAuthUpdateOauth = cli.Command{ Name: "update-oauth", Usage: "Update existing Oauth authentication source", @@ -521,3 +541,27 @@ func runListAuth(c *cli.Context) error { return nil } + +func runDeleteAuth(c *cli.Context) error { + if c.IsSet("config") { + setting.CustomConf = c.String("config") + } + + if !c.IsSet("id") { + return fmt.Errorf("--id flag is missing") + } + + if err := initDB(); err != nil { + return err + } + + source, err := models.GetLoginSourceByID(c.Int64("id")) + if err != nil { + return err + } + + if err = models.DeleteSource(source); err != nil { + return err + } + return nil +} From df3e058f864bfe2a556c05fdfe81c1dab3c7903b Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Thu, 23 Aug 2018 17:27:41 -0400 Subject: [PATCH 05/11] allow updating of individual settings --- cmd/admin.go | 70 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index 163c56f6c6079..dd12fb502725f 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -201,11 +201,6 @@ var ( Value: "", Usage: "Client Secret", }, - cli.StringFlag{ - Name: "secret", - Value: "", - Usage: "Client Secret", - }, cli.StringFlag{ Name: "auto-discover-url", Value: "", @@ -269,11 +264,6 @@ var ( Value: "", Usage: "Client Secret", }, - cli.StringFlag{ - Name: "secret", - Value: "", - Usage: "Client Secret", - }, cli.StringFlag{ Name: "auto-discover-url", Value: "", @@ -503,13 +493,59 @@ func runUpdateOauth(c *cli.Context) error { return err } - if err := models.UpdateSource(&models.LoginSource{ - ID: c.Int64("id"), - Type: models.LoginOAuth2, - Name: c.String("name"), - IsActived: true, - Cfg: parseOAuth2Config(c), - }); err != nil { + source, err := models.GetLoginSourceByID(c.Int64("id")) + if err != nil { + return err + } + + if c.IsSet("name") { + source.Name = c.String("name") + } + + if c.IsSet("provider") { + source.Cfg.Provider = c.String("provider") + } + + if c.IsSet("key") { + source.Cfg.ClientID = c.String("key") + } + + if c.IsSet("secret") { + source.Cfg.ClientSecret = c.String("secret") + } + + if c.IsSet("auto-discover-url") { + source.Cfg.OpenIDConnectAutoDiscoveryURL = c.String("auto-discover-url") + } + + // update custom URL mapping + var customURLMapping *oauth2.CustomURLMapping + + if source.Cfg.CustomURLMapping != nil { + customURLMapping.TokenURL = source.Cfg.CustomURLMapping.TokenURL + customURLMapping.AuthURL = source.Cfg.CustomURLMapping.AuthURL + customURLMapping.ProfileURL = source.Cfg.CustomURLMapping.ProfileURL + customURLMapping.Email = source.Cfg.CustomURLMapping.Email + } + if c.IsSet("use-custom-urls") && c.IsSet("custom-token-url") { + customURLMapping.TokenURL = c.String("custom-token-url") + } + + if c.IsSet("use-custom-urls") && c.IsSet("custom-auth-url") { + customURLMapping.AuthURL = c.String("custom-auth-url") + } + + if c.IsSet("use-custom-urls") && c.IsSet("custom-profile-url") { + customURLMapping.ProfileURL = c.String("custom-profile-url") + } + + if c.IsSet("use-custom-urls") && c.IsSet("custom-email-url") { + customURLMapping.EmailURL = c.String("custom-email-url") + } + + source.Cfg.CustomURLMapping = customURLMapping + + if err := models.UpdateSource(source); err != nil { return err } From 0ea1516bfeacb409fba1d39b26a2b7f11bb7d3b6 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Thu, 23 Aug 2018 17:28:03 -0400 Subject: [PATCH 06/11] add docs --- docs/content/doc/usage/command-line.md | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/docs/content/doc/usage/command-line.md b/docs/content/doc/usage/command-line.md index a7a10b4e47b3b..90e1ae2514967 100644 --- a/docs/content/doc/usage/command-line.md +++ b/docs/content/doc/usage/command-line.md @@ -72,6 +72,50 @@ Admin operations: - Examples: - `gitea admin regenerate hooks` - `gitea admin regenerate keys` + - `auth`: + - `list`: + - Description: lists all external authentication sources that exist + - Options: + - `--config path`: Gitea configuration file path. Optional. (default: custom/conf/app.ini). + - Examples: + - `gitea auth list` + - `delete`: + - Options: + - `--id`: ID of source to be deleted. Required. + - `--config path`: Gitea configuration file path. Optional. (default: custom/conf/app.ini). + - Examples: + - `gitea auth delete --id 1` + - `add-oauth`: + - Options: + - `--config path`: Gitea configuration file path. Optional. (default: custom/conf/app.ini). + - `--name`: Application Name. + - `--provider`: OAuth2 Provider. + - `--key`: Client ID (Key). + - `--secret`: Client Secret. + - `--auto-discover-url`: OpenID Connect Auto Discovery URL (only required when using OpenID Connect as provider). + - `--use-custom-urls`: Use custom URLs for GitLab/GitHub OAuth endpoints. + - `--custom-auth-url`: Use a custom Authorization URL (option for GitLab/GitHub). + - `--custom-token-url`: Use a custom Token URL (option for GitLab/GitHub). + - `--custom-profile-url`: Use a custom Profile URL (option for GitLab/GitHub). + - `--custom-email-url`: Use a custom Email URL (option for GitHub). + - Examples: + - `gitea auth add-oauth --name external-github --provider github --key OBTAIN_FROM_SOURCE --secret OBTAIN_FROM_SOURCE` + - `update-oauth`: + - Options: + - `--id`: ID of source to be updated. Required. + - `--config path`: Gitea configuration file path. Optional. (default: custom/conf/app.ini). + - `--name`: Application Name. + - `--provider`: OAuth2 Provider. + - `--key`: Client ID (Key). + - `--secret`: Client Secret. + - `--auto-discover-url`: OpenID Connect Auto Discovery URL (only required when using OpenID Connect as provider). + - `--use-custom-urls`: Use custom URLs for GitLab/GitHub OAuth endpoints. + - `--custom-auth-url`: Use a custom Authorization URL (option for GitLab/GitHub). + - `--custom-token-url`: Use a custom Token URL (option for GitLab/GitHub). + - `--custom-profile-url`: Use a custom Profile URL (option for GitLab/GitHub). + - `--custom-email-url`: Use a custom Email URL (option for GitHub). + - Examples: + - `gitea auth update-oauth --id 1 --name external-github-updated` #### cert From f47d5f20a7d87274829c2bc4021ffd0f83f07f23 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Thu, 23 Aug 2018 17:41:45 -0400 Subject: [PATCH 07/11] fix build errors --- cmd/admin.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index dd12fb502725f..c0bc8d95a51ed 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -498,34 +498,36 @@ func runUpdateOauth(c *cli.Context) error { return err } + oAuth2Config := source.OAuth2() + if c.IsSet("name") { source.Name = c.String("name") } if c.IsSet("provider") { - source.Cfg.Provider = c.String("provider") + oAuth2Config.Provider = c.String("provider") } if c.IsSet("key") { - source.Cfg.ClientID = c.String("key") + oAuth2Config.ClientID = c.String("key") } if c.IsSet("secret") { - source.Cfg.ClientSecret = c.String("secret") + oAuth2Config.ClientSecret = c.String("secret") } if c.IsSet("auto-discover-url") { - source.Cfg.OpenIDConnectAutoDiscoveryURL = c.String("auto-discover-url") + oAuth2Config.OpenIDConnectAutoDiscoveryURL = c.String("auto-discover-url") } // update custom URL mapping var customURLMapping *oauth2.CustomURLMapping - if source.Cfg.CustomURLMapping != nil { - customURLMapping.TokenURL = source.Cfg.CustomURLMapping.TokenURL - customURLMapping.AuthURL = source.Cfg.CustomURLMapping.AuthURL - customURLMapping.ProfileURL = source.Cfg.CustomURLMapping.ProfileURL - customURLMapping.Email = source.Cfg.CustomURLMapping.Email + if oAuth2Config.CustomURLMapping != nil { + customURLMapping.TokenURL = oAuth2Config.CustomURLMapping.TokenURL + customURLMapping.AuthURL = oAuth2Config.CustomURLMapping.AuthURL + customURLMapping.ProfileURL = oAuth2Config.CustomURLMapping.ProfileURL + customURLMapping.EmailURL = oAuth2Config.CustomURLMapping.EmailURL } if c.IsSet("use-custom-urls") && c.IsSet("custom-token-url") { customURLMapping.TokenURL = c.String("custom-token-url") @@ -543,7 +545,8 @@ func runUpdateOauth(c *cli.Context) error { customURLMapping.EmailURL = c.String("custom-email-url") } - source.Cfg.CustomURLMapping = customURLMapping + oAuth2Config.CustomURLMapping = customURLMapping + source.Cfg = oAuth2Config if err := models.UpdateSource(source); err != nil { return err From 6de8c909bbe90c69dfa803b28f61a18162c04856 Mon Sep 17 00:00:00 2001 From: Matti Ranta Date: Fri, 24 Aug 2018 17:15:46 -0400 Subject: [PATCH 08/11] split oauth CLIs out of cmd to reduce duplication --- cmd/admin.go | 182 ++++++++++++++++++--------------------------------- 1 file changed, 64 insertions(+), 118 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index c0bc8d95a51ed..01a91fa203e8a 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -167,134 +167,80 @@ var ( }, } + oauthCLIFlags = []cli.Flag{ + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, + cli.Int64Flag{ + Name: "id", + Usage: "ID of Oauth authentication source (used in update command)", + }, + cli.StringFlag{ + Name: "name", + Value: "", + Usage: "Application Name", + }, + cli.StringFlag{ + Name: "provider", + Value: "", + Usage: "OAuth2 Provider", + }, + cli.StringFlag{ + Name: "key", + Value: "", + Usage: "Client ID (Key)", + }, + cli.StringFlag{ + Name: "secret", + Value: "", + Usage: "Client Secret", + }, + cli.StringFlag{ + Name: "auto-discover-url", + Value: "", + Usage: "OpenID Connect Auto Discovery URL (only required when using OpenID Connect as provider)", + }, + cli.StringFlag{ + Name: "use-custom-urls", + Value: "false", + Usage: "Use custom URLs for GitLab/GitHub OAuth endpoints", + }, + cli.StringFlag{ + Name: "custom-auth-url", + Value: "", + Usage: "Use a custom Authorization URL (option for GitLab/GitHub)", + }, + cli.StringFlag{ + Name: "custom-token-url", + Value: "", + Usage: "Use a custom Token URL (option for GitLab/GitHub)", + }, + cli.StringFlag{ + Name: "custom-profile-url", + Value: "", + Usage: "Use a custom Profile URL (option for GitLab/GitHub)", + }, + cli.StringFlag{ + Name: "custom-email-url", + Value: "", + Usage: "Use a custom Email URL (option for GitHub)", + }, + } + microcmdAuthUpdateOauth = cli.Command{ Name: "update-oauth", Usage: "Update existing Oauth authentication source", Action: runUpdateOauth, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "config, c", - Value: "custom/conf/app.ini", - Usage: "Custom configuration file path", - }, - cli.Int64Flag{ - Name: "id", - Usage: "ID of Oauth authentication source that will be updated", - }, - cli.StringFlag{ - Name: "name", - Value: "", - Usage: "Application Name", - }, - cli.StringFlag{ - Name: "provider", - Value: "", - Usage: "OAuth2 Provider", - }, - cli.StringFlag{ - Name: "key", - Value: "", - Usage: "Client ID (Key)", - }, - cli.StringFlag{ - Name: "secret", - Value: "", - Usage: "Client Secret", - }, - cli.StringFlag{ - Name: "auto-discover-url", - Value: "", - Usage: "OpenID Connect Auto Discovery URL (only required when using OpenID Connect as provider)", - }, - cli.StringFlag{ - Name: "use-custom-urls", - Value: "false", - Usage: "Use custom URLs for GitLab/GitHub OAuth endpoints", - }, - cli.StringFlag{ - Name: "custom-auth-url", - Value: "", - Usage: "Use a custom Authorization URL (option for GitLab/GitHub)", - }, - cli.StringFlag{ - Name: "custom-token-url", - Value: "", - Usage: "Use a custom Token URL (option for GitLab/GitHub)", - }, - cli.StringFlag{ - Name: "custom-profile-url", - Value: "", - Usage: "Use a custom Profile URL (option for GitLab/GitHub)", - }, - cli.StringFlag{ - Name: "custom-email-url", - Value: "", - Usage: "Use a custom Email URL (option for GitHub)", - }, - }, + Flags: oauthCLIFlags, } microcmdAuthAddOauth = cli.Command{ Name: "add-oauth", Usage: "Add new Oauth authentication source", Action: runAddOauth, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "config, c", - Value: "custom/conf/app.ini", - Usage: "Custom configuration file path", - }, - cli.StringFlag{ - Name: "name", - Value: "", - Usage: "Application Name", - }, - cli.StringFlag{ - Name: "provider", - Value: "", - Usage: "OAuth2 Provider", - }, - cli.StringFlag{ - Name: "key", - Value: "", - Usage: "Client ID (Key)", - }, - cli.StringFlag{ - Name: "secret", - Value: "", - Usage: "Client Secret", - }, - cli.StringFlag{ - Name: "auto-discover-url", - Value: "", - Usage: "OpenID Connect Auto Discovery URL (only required when using OpenID Connect as provider)", - }, - cli.StringFlag{ - Name: "use-custom-urls", - Value: "false", - Usage: "Use custom URLs for GitLab/GitHub OAuth endpoints", - }, - cli.StringFlag{ - Name: "custom-auth-url", - Value: "", - Usage: "Use a custom Authorization URL (option for GitLab/GitHub)", - }, - cli.StringFlag{ - Name: "custom-token-url", - Value: "", - Usage: "Use a custom Token URL (option for GitLab/GitHub)", - }, - cli.StringFlag{ - Name: "custom-profile-url", - Value: "", - Usage: "Use a custom Profile URL (option for GitLab/GitHub)", - }, - cli.StringFlag{ - Name: "custom-email-url", - Value: "", - Usage: "Use a custom Email URL (option for GitHub)", - }, - }, + Flags: oauthCLIFlags, } ) From 20f65ba15ebf23d0f8f9eb2f139c5803bc375bbf Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 10 Sep 2018 13:08:21 -0400 Subject: [PATCH 09/11] Update admin.go --- cmd/admin.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index 01a91fa203e8a..45a054546bee6 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -150,6 +150,11 @@ var ( }, } + IDFlag = cli.Int64Flag{ + Name: "id", + Usage: "ID of OAuth authentication source", + } + microcmdAuthDelete = cli.Command{ Name: "delete", Usage: "Delete specific auth source", @@ -160,10 +165,7 @@ var ( Value: "custom/conf/app.ini", Usage: "Custom configuration file path", }, - cli.Int64Flag{ - Name: "id", - Usage: "ID of authentication source that will be deleted", - }, + IDFlag, }, } @@ -173,10 +175,6 @@ var ( Value: "custom/conf/app.ini", Usage: "Custom configuration file path", }, - cli.Int64Flag{ - Name: "id", - Usage: "ID of Oauth authentication source (used in update command)", - }, cli.StringFlag{ Name: "name", Value: "", @@ -233,7 +231,7 @@ var ( Name: "update-oauth", Usage: "Update existing Oauth authentication source", Action: runUpdateOauth, - Flags: oauthCLIFlags, + Flags: append(oauthCLIFlags, IDFlag), } microcmdAuthAddOauth = cli.Command{ From 96c106227dfb04bb59e094859b94c70610f253a3 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 10 Sep 2018 13:11:16 -0400 Subject: [PATCH 10/11] Update admin.go --- cmd/admin.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index 45a054546bee6..c01bbad4c48eb 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -150,7 +150,7 @@ var ( }, } - IDFlag = cli.Int64Flag{ + idFlag = cli.Int64Flag{ Name: "id", Usage: "ID of OAuth authentication source", } @@ -165,7 +165,7 @@ var ( Value: "custom/conf/app.ini", Usage: "Custom configuration file path", }, - IDFlag, + idFlag, }, } @@ -231,7 +231,7 @@ var ( Name: "update-oauth", Usage: "Update existing Oauth authentication source", Action: runUpdateOauth, - Flags: append(oauthCLIFlags, IDFlag), + Flags: append(oauthCLIFlags, idFlag), } microcmdAuthAddOauth = cli.Command{ From 2aec1ab699bd7aa67139d2b0890a3a58420aeeae Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 11 Sep 2018 10:17:26 -0400 Subject: [PATCH 11/11] Update admin.go --- cmd/admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/admin.go b/cmd/admin.go index c01bbad4c48eb..047f3befccf28 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -231,7 +231,7 @@ var ( Name: "update-oauth", Usage: "Update existing Oauth authentication source", Action: runUpdateOauth, - Flags: append(oauthCLIFlags, idFlag), + Flags: append(oauthCLIFlags[:1], append([]cli.Flag{idFlag}, oauthCLIFlags[1:]...)...), } microcmdAuthAddOauth = cli.Command{