-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Agent: add new
secrets
capability to implement secret storage
Previously, the agent only supported stateless secret storage, where the agent server stored secrets in a temporary hashmap that was lost whenever the agent started. Now, clients can optionally declare that they're able to store secrets using the `secrets: 'client-managed'` capability. With this new capability, client can store/retrieve/delete/change secrets using the new JSON-RPC methods: * `secrets/get` * `secrets/store` * `secrets/delete` * `secrets/didChange`
- Loading branch information
Showing
13 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...lib/src/main/kotlin/com/sourcegraph/cody/agent/protocol_generated/Secrets_DeleteParams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport") | ||
package com.sourcegraph.cody.agent.protocol_generated; | ||
|
||
data class Secrets_DeleteParams( | ||
val key: String, | ||
) | ||
|
7 changes: 7 additions & 0 deletions
7
.../src/main/kotlin/com/sourcegraph/cody/agent/protocol_generated/Secrets_DidChangeParams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport") | ||
package com.sourcegraph.cody.agent.protocol_generated; | ||
|
||
data class Secrets_DidChangeParams( | ||
val key: String, | ||
) | ||
|
7 changes: 7 additions & 0 deletions
7
...in/lib/src/main/kotlin/com/sourcegraph/cody/agent/protocol_generated/Secrets_GetParams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport") | ||
package com.sourcegraph.cody.agent.protocol_generated; | ||
|
||
data class Secrets_GetParams( | ||
val key: String, | ||
) | ||
|
8 changes: 8 additions & 0 deletions
8
.../lib/src/main/kotlin/com/sourcegraph/cody/agent/protocol_generated/Secrets_StoreParams.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport") | ||
package com.sourcegraph.cody.agent.protocol_generated; | ||
|
||
data class Secrets_StoreParams( | ||
val key: String, | ||
val value: String, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type * as vscode from 'vscode' | ||
import { emptyEvent } from '../../vscode/src/testutils/emptyEvent' | ||
import type { MessageHandler } from './jsonrpc-alias' | ||
|
||
export class AgentStatelessSecretStorage implements vscode.SecretStorage { | ||
private readonly inMemorySecretStorageMap = new Map<string, string>() | ||
public get(key: string): Thenable<string | undefined> { | ||
return Promise.resolve(this.inMemorySecretStorageMap.get(key)) | ||
} | ||
public store(key: string, value: string): Thenable<void> { | ||
this.inMemorySecretStorageMap.set(key, value) | ||
return Promise.resolve() | ||
} | ||
public delete(key: string): Thenable<void> { | ||
this.inMemorySecretStorageMap.delete(key) | ||
return Promise.resolve() | ||
} | ||
onDidChange: vscode.Event<vscode.SecretStorageChangeEvent> = emptyEvent() | ||
} | ||
|
||
export class AgentClientManagedSecretStorage implements vscode.SecretStorage { | ||
constructor( | ||
private readonly agent: MessageHandler, | ||
public readonly onDidChange: vscode.Event<vscode.SecretStorageChangeEvent> | ||
) {} | ||
public async get(key: string): Promise<string | undefined> { | ||
const result = await this.agent.request('secrets/get', { key }) | ||
return result ?? undefined | ||
} | ||
public async store(key: string, value: string): Promise<void> { | ||
await this.agent.request('secrets/store', { key, value }) | ||
} | ||
public async delete(key: string): Promise<void> { | ||
await this.agent.request('secrets/delete', { key }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters