MCPcopy Index your code
hub / github.com/coder/coder / convertAPIKey

Function convertAPIKey

coderd/users.go:2107–2139  ·  view source on GitHub ↗
(k database.APIKey)

Source from the content-addressed store, hash-verified

2105}
2106
2107func convertAPIKey(k database.APIKey) codersdk.APIKey {
2108 // Derive a single legacy scope name for response compatibility.
2109 // Historically, the API exposed only two scope strings: "all" and
2110 // "application_connect". Continue to return those for clients even
2111 // though the database stores canonical values (e.g. "coder:all")
2112 // and may include low-level scopes.
2113 var legacyScope codersdk.APIKeyScope
2114 if k.Scopes.Has(database.ApiKeyScopeCoderApplicationConnect) {
2115 legacyScope = codersdk.APIKeyScopeApplicationConnect
2116 } else if k.Scopes.Has(database.ApiKeyScopeCoderAll) {
2117 legacyScope = codersdk.APIKeyScopeAll
2118 }
2119
2120 scopes := make([]codersdk.APIKeyScope, 0, len(k.Scopes))
2121 for _, s := range k.Scopes {
2122 scopes = append(scopes, codersdk.APIKeyScope(s))
2123 }
2124
2125 return codersdk.APIKey{
2126 ID: k.ID,
2127 UserID: k.UserID,
2128 LastUsed: k.LastUsed,
2129 ExpiresAt: k.ExpiresAt,
2130 CreatedAt: k.CreatedAt,
2131 UpdatedAt: k.UpdatedAt,
2132 LoginType: codersdk.LoginType(k.LoginType),
2133 Scope: legacyScope,
2134 Scopes: scopes,
2135 LifetimeSeconds: k.LifetimeSeconds,
2136 TokenName: k.TokenName,
2137 AllowList: slice.List(k.AllowList, db2sdk.APIAllowListTarget),
2138 }
2139}

Callers 3

apiKeyByIDMethod · 0.85
apiKeyByNameMethod · 0.85
tokensMethod · 0.85

Calls 4

APIKeyScopeTypeAlias · 0.92
LoginTypeTypeAlias · 0.92
ListFunction · 0.92
HasMethod · 0.45

Tested by

no test coverage detected