Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Refactor external auth providers to re-generate headers on de… #6792

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ sealed class AuthenticationError {
"network-error" -> context.deserialize<NetworkAuthError>(element, NetworkAuthError::class.java)
"invalid-access-token" -> context.deserialize<InvalidAccessTokenError>(element, InvalidAccessTokenError::class.java)
"enterprise-user-logged-into-dotcom" -> context.deserialize<EnterpriseUserDotComError>(element, EnterpriseUserDotComError::class.java)
"auth-config-error" -> context.deserialize<AuthConfigError>(element, AuthConfigError::class.java)
"external-auth-provider-error" -> context.deserialize<ExternalAuthProviderError>(element, ExternalAuthProviderError::class.java)
else -> throw Exception("Unknown discriminator ${element}")
}
}
Expand Down Expand Up @@ -52,23 +50,3 @@ data class EnterpriseUserDotComError(
}
}

data class AuthConfigError(
val type: TypeEnum, // Oneof: auth-config-error
val message: String,
) : AuthenticationError() {

enum class TypeEnum {
@SerializedName("auth-config-error") `Auth-config-error`,
}
}

data class ExternalAuthProviderError(
val type: TypeEnum, // Oneof: external-auth-provider-error
val message: String,
) : AuthenticationError() {

enum class TypeEnum {
@SerializedName("external-auth-provider-error") `External-auth-provider-error`,
}
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport")
package com.sourcegraph.cody.agent.protocol_generated;

import com.google.gson.annotations.SerializedName;

data class CodyContextFilterItem(
val repoNamePattern: RepoNamePatternEnum, // Oneof: .*
val repoNamePattern: String,
val filePathPatterns: List<String>? = null,
) {

enum class RepoNamePatternEnum {
@SerializedName(".*") Wildcard,
}
}
)

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package com.sourcegraph.cody.agent.protocol_generated;

object Constants {
const val Wildcard = ".*"
const val Applied = "Applied"
const val Applying = "Applying"
const val Automatic = "Automatic"
Expand All @@ -16,7 +15,6 @@ object Constants {
const val agentic = "agentic"
const val ask = "ask"
const val assistant = "assistant"
const val `auth-config-error` = "auth-config-error"
const val authenticated = "authenticated"
const val autocomplete = "autocomplete"
const val balanced = "balanced"
Expand All @@ -41,7 +39,6 @@ object Constants {
const val `enterprise-user-logged-into-dotcom` = "enterprise-user-logged-into-dotcom"
const val error = "error"
const val experimental = "experimental"
const val `external-auth-provider-error` = "external-auth-provider-error"
const val file = "file"
const val free = "free"
const val function = "function"
Expand Down
80 changes: 0 additions & 80 deletions agent/scripts/reverse-proxy.py

This file was deleted.

21 changes: 0 additions & 21 deletions agent/scripts/simple-external-auth-provider.py

This file was deleted.

2 changes: 1 addition & 1 deletion agent/src/AgentWorkspaceConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class AgentWorkspaceConfiguration implements vscode.WorkspaceConfiguratio

function mergeWithBaseConfig(config: any) {
for (const [key, value] of Object.entries(config)) {
if (typeof value === 'object' && !Array.isArray(value)) {
if (typeof value === 'object') {
const existing = _.get(baseConfig, key) ?? {}
const merged = _.merge(existing, value)
_.set(baseConfig, key, merged)
Expand Down
9 changes: 4 additions & 5 deletions agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1486,10 +1486,11 @@ export class Agent extends MessageHandler implements ExtensionClient {
config: ExtensionConfiguration,
params?: { forceAuthentication: boolean }
): Promise<AuthStatus> {
const isAuthChange = vscode_shim.isTokenOrEndpointChange(config)
const isAuthChange = vscode_shim.isAuthenticationChange(config)
vscode_shim.setExtensionConfiguration(config)

// If this is an token or endpoint change we need to save them prior to firing events that update the clients
// If this is an authentication change we need to reauthenticate prior to firing events
// that update the clients
try {
if ((isAuthChange || params?.forceAuthentication) && config.serverEndpoint) {
await authProvider.validateAndStoreCredentials(
Expand All @@ -1499,9 +1500,7 @@ export class Agent extends MessageHandler implements ExtensionClient {
},
auth: {
serverEndpoint: config.serverEndpoint,
credentials: config.accessToken
? { token: config.accessToken, source: 'paste' }
: undefined,
accessToken: config.accessToken ?? null,
},
clientState: {
anonymousUserID: config.anonymousUserID ?? null,
Expand Down
5 changes: 1 addition & 4 deletions agent/src/cli/command-auth/AuthenticatedAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export class AuthenticatedAccount {
): Promise<AuthenticatedAccount | Error> {
const graphqlClient = SourcegraphGraphQLAPIClient.withStaticConfig({
configuration: { telemetryLevel: 'agent' },
auth: {
credentials: { token: options.accessToken },
serverEndpoint: options.endpoint,
},
auth: { accessToken: options.accessToken, serverEndpoint: options.endpoint },
clientState: { anonymousUserID: null },
})
const userInfo = await graphqlClient.getCurrentUserInfo()
Expand Down
4 changes: 2 additions & 2 deletions agent/src/cli/command-auth/command-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async function loginAction(
: await captureAccessTokenViaBrowserRedirect(serverEndpoint, spinner)
const client = SourcegraphGraphQLAPIClient.withStaticConfig({
configuration: { telemetryLevel: 'agent' },
auth: { credentials: { token: options.accessToken }, serverEndpoint: serverEndpoint },
auth: { accessToken: token, serverEndpoint: serverEndpoint },
clientState: { anonymousUserID: null },
})
const userInfo = await client.getCurrentUserInfo()
Expand Down Expand Up @@ -256,7 +256,7 @@ async function promptUserAboutLoginMethod(spinner: Ora, options: LoginOptions):
try {
const client = SourcegraphGraphQLAPIClient.withStaticConfig({
configuration: { telemetryLevel: 'agent' },
auth: { credentials: { token: options.accessToken }, serverEndpoint: options.endpoint },
auth: { accessToken: options.accessToken, serverEndpoint: options.endpoint },
clientState: { anonymousUserID: null },
})
const userInfo = await client.getCurrentUserInfo()
Expand Down
2 changes: 1 addition & 1 deletion agent/src/cli/command-bench/command-bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export const benchCommand = new commander.Command('bench')
setStaticResolvedConfigurationWithAuthCredentials({
configuration: { customHeaders: {} },
auth: {
credentials: { token: options.srcAccessToken },
accessToken: options.srcAccessToken,
serverEndpoint: options.srcEndpoint,
},
})
Expand Down
5 changes: 1 addition & 4 deletions agent/src/cli/command-bench/llm-judge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export class LlmJudge {
localStorage.setStorage('noop')
setStaticResolvedConfigurationWithAuthCredentials({
configuration: { customHeaders: undefined },
auth: {
credentials: { token: options.srcAccessToken },
serverEndpoint: options.srcEndpoint,
},
auth: { accessToken: options.srcAccessToken, serverEndpoint: options.srcEndpoint },
})
setClientCapabilities({ configuration: {}, agentCapabilities: undefined })
this.client = new SourcegraphNodeCompletionsClient()
Expand Down
2 changes: 1 addition & 1 deletion agent/src/cli/scip-codegen/emitters/KotlinEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class KotlinFormatter extends Formatter {
}

override formatFieldName(name: string): string {
const escaped = name.replace('.*', 'Wildcard').replace(':', '_').replace('/', '_')
const escaped = name.replace(':', '_').replace('/', '_')
const isKeyword = this.options.reserved.has(escaped)
const needsBacktick = isKeyword || !/^[a-zA-Z0-9_]+$/.test(escaped)
// Replace all non-alphanumeric characters with underscores
Expand Down
5 changes: 1 addition & 4 deletions agent/src/local-e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ export class LocalSGInstance {
// for checking the LLM configuration section.
this.gqlclient = SourcegraphGraphQLAPIClient.withStaticConfig({
configuration: { customHeaders: headers, telemetryLevel: 'agent' },
auth: {
credentials: { token: this.params.accessToken },
serverEndpoint: this.params.serverEndpoint,
},
auth: { accessToken: this.params.accessToken, serverEndpoint: this.params.serverEndpoint },
clientState: { anonymousUserID: null },
})
}
Expand Down
3 changes: 1 addition & 2 deletions agent/src/vscode-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ export let extensionConfiguration: ExtensionConfiguration | undefined
export function setExtensionConfiguration(newConfig: ExtensionConfiguration): void {
extensionConfiguration = newConfig
}

export function isTokenOrEndpointChange(newConfig: ExtensionConfiguration): boolean {
export function isAuthenticationChange(newConfig: ExtensionConfiguration): boolean {
if (!extensionConfiguration) {
return true
}
Expand Down
27 changes: 1 addition & 26 deletions lib/shared/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,7 @@ export interface EnterpriseUserDotComError {
enterprise: string
}

export interface AuthConfigError {
type: 'auth-config-error'
message: string
}

export interface ExternalAuthProviderError {
type: 'external-auth-provider-error'
message: string
}

export type AuthenticationError =
| NetworkAuthError
| InvalidAccessTokenError
| EnterpriseUserDotComError
| AuthConfigError
| ExternalAuthProviderError
export type AuthenticationError = NetworkAuthError | InvalidAccessTokenError | EnterpriseUserDotComError

export interface AuthenticationErrorMessage {
title?: string
Expand Down Expand Up @@ -105,16 +90,6 @@ export function getAuthErrorMessage(error: AuthenticationError): AuthenticationE
"in through your organization's enterprise instance instead. If you need assistance " +
'please contact your Sourcegraph admin.',
}
case 'auth-config-error':
return {
title: 'Auth Config Error',
message: error.message,
}
case 'external-auth-provider-error':
return {
title: 'External Auth Provider Error',
message: error.message,
}
}
}

Expand Down
29 changes: 2 additions & 27 deletions lib/shared/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ export type TokenSource = 'redirect' | 'paste'
*/
export interface AuthCredentials {
serverEndpoint: string
credentials: HeaderCredential | TokenCredential | undefined
error?: any
}

export interface HeaderCredential {
// We use function instead of property to prevent accidential top level serialization - we never want to store this data
getHeaders(): Promise<Record<string, string>>
}

export interface TokenCredential {
token: string
source?: TokenSource
accessToken: string | null
tokenSource?: TokenSource | undefined
}

export interface AutoEditsTokenLimit {
Expand Down Expand Up @@ -81,19 +71,6 @@ export interface AgenticContextConfiguration {
}
}

export interface ExternalAuthCommand {
commandLine: readonly string[]
environment?: Record<string, string>
shell?: string
timeout?: number
windowsHide?: boolean
}

export interface ExternalAuthProvider {
endpoint: string
executable: ExternalAuthCommand
}

interface RawClientConfiguration {
net: NetConfiguration
codebase?: string
Expand Down Expand Up @@ -188,8 +165,6 @@ interface RawClientConfiguration {
*/
overrideServerEndpoint?: string | undefined
overrideAuthToken?: string | undefined

authExternalProviders: ExternalAuthProvider[]
}

/**
Expand Down
Loading
Loading