From a7616e167c88c720b63ab16fb6d36161f843e25b Mon Sep 17 00:00:00 2001 From: Trent Clarke Date: Mon, 4 Sep 2023 09:59:03 +1000 Subject: [PATCH] Adds default Github API urls to SSO connector. `tctl sso configure github` was producing an untestable connector spec, or at least a spec that would _always fail_ when tested with `tctl ssl test`, due to missing GitHub endpoints in the generated spec. This change adds the default GitHub endpoint URLs as default values for the endpoint flags in `tctl sso configure github` so that the produces spec is valis and testable. Note: Our WebUI appears to magically add these values when saving a connector, so this issue only really effects `tctl sso test` Includes doc update to match new output. Fixes: #31396 Changelog: `tctl sso configure github` now includes default Github endpoints --- api/types/github.go | 8 ++++---- docs/pages/access-controls/sso/github-sso.mdx | 4 ++-- tool/tctl/sso/configure/github.go | 11 +++++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/api/types/github.go b/api/types/github.go index 5b49e32a766e0..762447e3f04ac 100644 --- a/api/types/github.go +++ b/api/types/github.go @@ -28,8 +28,8 @@ import ( ) const ( - githubURL = "https://github.com" - githubAPIURL = "https://api.github.com" + GithubURL = "https://github.com" + GithubAPIURL = "https://api.github.com" ) // GithubConnector defines an interface for a Github OAuth2 connector @@ -269,12 +269,12 @@ func (c *GithubConnectorV3) SetDisplay(display string) { // GetEndpointURL returns the endpoint URL func (c *GithubConnectorV3) GetEndpointURL() string { - return githubURL + return GithubURL } // GetEndpointURL returns the API endpoint URL func (c *GithubConnectorV3) GetAPIEndpointURL() string { - return githubAPIURL + return GithubAPIURL } // MapClaims returns a list of logins based on the provided claims, diff --git a/docs/pages/access-controls/sso/github-sso.mdx b/docs/pages/access-controls/sso/github-sso.mdx index a8d856fcae29b..a5dda1ba7b29e 100644 --- a/docs/pages/access-controls/sso/github-sso.mdx +++ b/docs/pages/access-controls/sso/github-sso.mdx @@ -92,11 +92,11 @@ kind: github metadata: name: github spec: - api_endpoint_url: "" + api_endpoint_url: https://api.github.com client_id: client_secret: display: GitHub - endpoint_url: "" + endpoint_url: https://github.com redirect_url: https:///v1/webapi/github/callback teams_to_logins: null teams_to_roles: diff --git a/tool/tctl/sso/configure/github.go b/tool/tctl/sso/configure/github.go index 89708deb146ad..e5f28a32079ba 100644 --- a/tool/tctl/sso/configure/github.go +++ b/tool/tctl/sso/configure/github.go @@ -49,8 +49,15 @@ func addGithubCommand(cmd *SSOConfigureCommand) *AuthKindCommand { sub.Flag("display", "Sets the connector display name.").StringVar(&spec.Display) sub.Flag("id", "GitHub app client ID.").PlaceHolder("ID").Required().StringVar(&spec.ClientID) sub.Flag("secret", "GitHub app client secret.").Required().PlaceHolder("SECRET").StringVar(&spec.ClientSecret) - sub.Flag("endpoint-url", "Endpoint URL for GitHub instance.").StringVar(&spec.EndpointURL) - sub.Flag("api-endpoint-url", "API endpoint URL for GitHub instance.").StringVar(&spec.APIEndpointURL) + sub.Flag("endpoint-url", "Endpoint URL for GitHub instance."). + PlaceHolder("URL"). + Default(types.GithubURL). + StringVar(&spec.EndpointURL) + + sub.Flag("api-endpoint-url", "API endpoint URL for GitHub instance."). + PlaceHolder("URL"). + Default(types.GithubAPIURL). + StringVar(&spec.APIEndpointURL) // auto sub.Flag("redirect-url", "Authorization callback URL.").PlaceHolder("URL").StringVar(&spec.RedirectURL)