gitlabDefaults returns a static config if using the gitlab cloud offering. The values are dynamic if using a self-hosted gitlab. When the decision is not obvious, just defer to the cloud defaults. Any user specific fields will override this if provided.
(config *codersdk.ExternalAuthConfig)
| 1123 | // When the decision is not obvious, just defer to the cloud defaults. |
| 1124 | // Any user specific fields will override this if provided. |
| 1125 | func gitlabDefaults(config *codersdk.ExternalAuthConfig) codersdk.ExternalAuthConfig { |
| 1126 | cloud := codersdk.ExternalAuthConfig{ |
| 1127 | AuthURL: "https://gitlab.com/oauth/authorize", |
| 1128 | TokenURL: "https://gitlab.com/oauth/token", |
| 1129 | ValidateURL: "https://gitlab.com/oauth/token/info", |
| 1130 | RevokeURL: "https://gitlab.com/oauth/revoke", |
| 1131 | DisplayName: "GitLab", |
| 1132 | DisplayIcon: "/icon/gitlab.svg", |
| 1133 | Regex: `^(https?://)?gitlab\.com(/.*)?$`, |
| 1134 | Scopes: []string{"write_repository", "read_api"}, |
| 1135 | CodeChallengeMethodsSupported: []string{string(promoauth.PKCEChallengeMethodSha256)}, |
| 1136 | } |
| 1137 | |
| 1138 | if config.AuthURL == "" || config.AuthURL == cloud.AuthURL { |
| 1139 | return cloud |
| 1140 | } |
| 1141 | |
| 1142 | au, err := url.Parse(config.AuthURL) |
| 1143 | if err != nil || au.Host == "gitlab.com" { |
| 1144 | // If the AuthURL is not a valid URL or is using the cloud, |
| 1145 | // use the cloud static defaults. |
| 1146 | return cloud |
| 1147 | } |
| 1148 | |
| 1149 | // At this point, assume it is self-hosted and use the AuthURL |
| 1150 | return codersdk.ExternalAuthConfig{ |
| 1151 | DisplayName: cloud.DisplayName, |
| 1152 | Scopes: cloud.Scopes, |
| 1153 | DisplayIcon: cloud.DisplayIcon, |
| 1154 | AuthURL: au.ResolveReference(&url.URL{Path: "/oauth/authorize"}).String(), |
| 1155 | TokenURL: au.ResolveReference(&url.URL{Path: "/oauth/token"}).String(), |
| 1156 | ValidateURL: au.ResolveReference(&url.URL{Path: "/oauth/token/info"}).String(), |
| 1157 | RevokeURL: au.ResolveReference(&url.URL{Path: "/oauth/revoke"}).String(), |
| 1158 | Regex: fmt.Sprintf(`^(https?://)?%s(/.*)?$`, strings.ReplaceAll(au.Host, ".", `\.`)), |
| 1159 | CodeChallengeMethodsSupported: []string{string(promoauth.PKCEChallengeMethodSha256)}, |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | func jfrogArtifactoryDefaults(config *codersdk.ExternalAuthConfig) codersdk.ExternalAuthConfig { |
| 1164 | defaults := codersdk.ExternalAuthConfig{ |
no test coverage detected