createExternalAuthResponse creates an ExternalAuthResponse based on the provider type. This is to support legacy `/workspaceagents/me/gitauth` which uses `Username` and `Password`.
(typ, token string, extra pqtype.NullRawMessage)
| 2380 | // provider type. This is to support legacy `/workspaceagents/me/gitauth` |
| 2381 | // which uses `Username` and `Password`. |
| 2382 | func createExternalAuthResponse(typ, token string, extra pqtype.NullRawMessage) (agentsdk.ExternalAuthResponse, error) { |
| 2383 | var resp agentsdk.ExternalAuthResponse |
| 2384 | switch typ { |
| 2385 | case string(codersdk.EnhancedExternalAuthProviderGitLab): |
| 2386 | // https://stackoverflow.com/questions/25409700/using-gitlab-token-to-clone-without-authentication |
| 2387 | resp = agentsdk.ExternalAuthResponse{ |
| 2388 | Username: "oauth2", |
| 2389 | Password: token, |
| 2390 | } |
| 2391 | case string(codersdk.EnhancedExternalAuthProviderBitBucketCloud), string(codersdk.EnhancedExternalAuthProviderBitBucketServer): |
| 2392 | // The string "bitbucket" was a legacy parameter that needs to still be supported. |
| 2393 | // https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/#Cloning-a-repository-with-an-access-token |
| 2394 | resp = agentsdk.ExternalAuthResponse{ |
| 2395 | Username: "x-token-auth", |
| 2396 | Password: token, |
| 2397 | } |
| 2398 | default: |
| 2399 | resp = agentsdk.ExternalAuthResponse{ |
| 2400 | Username: token, |
| 2401 | } |
| 2402 | } |
| 2403 | resp.AccessToken = token |
| 2404 | resp.Type = typ |
| 2405 | |
| 2406 | var err error |
| 2407 | if extra.Valid { |
| 2408 | err = json.Unmarshal(extra.RawMessage, &resp.TokenExtra) |
| 2409 | } |
| 2410 | return resp, err |
| 2411 | } |
| 2412 | |
| 2413 | func convertWorkspaceAgentLogs(logs []database.WorkspaceAgentLog) []codersdk.WorkspaceAgentLog { |
| 2414 | sdk := make([]codersdk.WorkspaceAgentLog, 0, len(logs)) |
no test coverage detected