|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import { APIResource } from '../core/resource'; |
| 4 | +import { APIPromise } from '../core/api-promise'; |
| 5 | +import { buildHeaders } from '../internal/headers'; |
| 6 | +import { RequestOptions } from '../internal/request-options'; |
| 7 | +import { path } from '../internal/utils/path'; |
| 8 | + |
| 9 | +export class CredentialProviders extends APIResource { |
| 10 | + /** |
| 11 | + * Configure an external credential provider (e.g., 1Password) for automatic |
| 12 | + * credential lookup. |
| 13 | + * |
| 14 | + * @example |
| 15 | + * ```ts |
| 16 | + * const credentialProvider = |
| 17 | + * await client.credentialProviders.create({ |
| 18 | + * token: 'ops_eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...', |
| 19 | + * provider_type: 'onepassword', |
| 20 | + * }); |
| 21 | + * ``` |
| 22 | + */ |
| 23 | + create(body: CredentialProviderCreateParams, options?: RequestOptions): APIPromise<CredentialProvider> { |
| 24 | + return this._client.post('/org/credential-providers', { body, ...options }); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Retrieve a credential provider by its ID. |
| 29 | + * |
| 30 | + * @example |
| 31 | + * ```ts |
| 32 | + * const credentialProvider = |
| 33 | + * await client.credentialProviders.retrieve('id'); |
| 34 | + * ``` |
| 35 | + */ |
| 36 | + retrieve(id: string, options?: RequestOptions): APIPromise<CredentialProvider> { |
| 37 | + return this._client.get(path`/org/credential-providers/${id}`, options); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Update a credential provider's configuration. |
| 42 | + * |
| 43 | + * @example |
| 44 | + * ```ts |
| 45 | + * const credentialProvider = |
| 46 | + * await client.credentialProviders.update('id'); |
| 47 | + * ``` |
| 48 | + */ |
| 49 | + update( |
| 50 | + id: string, |
| 51 | + body: CredentialProviderUpdateParams, |
| 52 | + options?: RequestOptions, |
| 53 | + ): APIPromise<CredentialProvider> { |
| 54 | + return this._client.patch(path`/org/credential-providers/${id}`, { body, ...options }); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * List external credential providers configured for the organization. |
| 59 | + * |
| 60 | + * @example |
| 61 | + * ```ts |
| 62 | + * const credentialProviders = |
| 63 | + * await client.credentialProviders.list(); |
| 64 | + * ``` |
| 65 | + */ |
| 66 | + list(options?: RequestOptions): APIPromise<CredentialProviderListResponse> { |
| 67 | + return this._client.get('/org/credential-providers', options); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Delete a credential provider by its ID. |
| 72 | + * |
| 73 | + * @example |
| 74 | + * ```ts |
| 75 | + * await client.credentialProviders.delete('id'); |
| 76 | + * ``` |
| 77 | + */ |
| 78 | + delete(id: string, options?: RequestOptions): APIPromise<void> { |
| 79 | + return this._client.delete(path`/org/credential-providers/${id}`, { |
| 80 | + ...options, |
| 81 | + headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), |
| 82 | + }); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Validate the credential provider's token and list accessible vaults. |
| 87 | + * |
| 88 | + * @example |
| 89 | + * ```ts |
| 90 | + * const credentialProviderTestResult = |
| 91 | + * await client.credentialProviders.test('id'); |
| 92 | + * ``` |
| 93 | + */ |
| 94 | + test(id: string, options?: RequestOptions): APIPromise<CredentialProviderTestResult> { |
| 95 | + return this._client.post(path`/org/credential-providers/${id}/test`, options); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +/** |
| 100 | + * Request to create an external credential provider |
| 101 | + */ |
| 102 | +export interface CreateCredentialProviderRequest { |
| 103 | + /** |
| 104 | + * Service account token for the provider (e.g., 1Password service account token) |
| 105 | + */ |
| 106 | + token: string; |
| 107 | + |
| 108 | + /** |
| 109 | + * Type of credential provider |
| 110 | + */ |
| 111 | + provider_type: 'onepassword'; |
| 112 | + |
| 113 | + /** |
| 114 | + * How long to cache credential lists (default 300 seconds) |
| 115 | + */ |
| 116 | + cache_ttl_seconds?: number; |
| 117 | +} |
| 118 | + |
| 119 | +/** |
| 120 | + * An external credential provider (e.g., 1Password) for automatic credential |
| 121 | + * lookup |
| 122 | + */ |
| 123 | +export interface CredentialProvider { |
| 124 | + /** |
| 125 | + * Unique identifier for the credential provider |
| 126 | + */ |
| 127 | + id: string; |
| 128 | + |
| 129 | + /** |
| 130 | + * When the credential provider was created |
| 131 | + */ |
| 132 | + created_at: string; |
| 133 | + |
| 134 | + /** |
| 135 | + * Whether the provider is enabled for credential lookups |
| 136 | + */ |
| 137 | + enabled: boolean; |
| 138 | + |
| 139 | + /** |
| 140 | + * Priority order for credential lookups (lower numbers are checked first) |
| 141 | + */ |
| 142 | + priority: number; |
| 143 | + |
| 144 | + /** |
| 145 | + * Type of credential provider |
| 146 | + */ |
| 147 | + provider_type: 'onepassword'; |
| 148 | + |
| 149 | + /** |
| 150 | + * When the credential provider was last updated |
| 151 | + */ |
| 152 | + updated_at: string; |
| 153 | +} |
| 154 | + |
| 155 | +/** |
| 156 | + * Result of testing a credential provider connection |
| 157 | + */ |
| 158 | +export interface CredentialProviderTestResult { |
| 159 | + /** |
| 160 | + * Whether the connection test was successful |
| 161 | + */ |
| 162 | + success: boolean; |
| 163 | + |
| 164 | + /** |
| 165 | + * List of vaults accessible by the service account |
| 166 | + */ |
| 167 | + vaults: Array<CredentialProviderTestResult.Vault>; |
| 168 | + |
| 169 | + /** |
| 170 | + * Error message if the test failed |
| 171 | + */ |
| 172 | + error?: string; |
| 173 | +} |
| 174 | + |
| 175 | +export namespace CredentialProviderTestResult { |
| 176 | + export interface Vault { |
| 177 | + /** |
| 178 | + * Vault ID |
| 179 | + */ |
| 180 | + id: string; |
| 181 | + |
| 182 | + /** |
| 183 | + * Vault name |
| 184 | + */ |
| 185 | + name: string; |
| 186 | + } |
| 187 | +} |
| 188 | + |
| 189 | +/** |
| 190 | + * Request to update a credential provider |
| 191 | + */ |
| 192 | +export interface UpdateCredentialProviderRequest { |
| 193 | + /** |
| 194 | + * New service account token (to rotate credentials) |
| 195 | + */ |
| 196 | + token?: string; |
| 197 | + |
| 198 | + /** |
| 199 | + * How long to cache credential lists |
| 200 | + */ |
| 201 | + cache_ttl_seconds?: number; |
| 202 | + |
| 203 | + /** |
| 204 | + * Whether the provider is enabled for credential lookups |
| 205 | + */ |
| 206 | + enabled?: boolean; |
| 207 | + |
| 208 | + /** |
| 209 | + * Priority order for credential lookups (lower numbers are checked first) |
| 210 | + */ |
| 211 | + priority?: number; |
| 212 | +} |
| 213 | + |
| 214 | +export type CredentialProviderListResponse = Array<CredentialProvider>; |
| 215 | + |
| 216 | +export interface CredentialProviderCreateParams { |
| 217 | + /** |
| 218 | + * Service account token for the provider (e.g., 1Password service account token) |
| 219 | + */ |
| 220 | + token: string; |
| 221 | + |
| 222 | + /** |
| 223 | + * Type of credential provider |
| 224 | + */ |
| 225 | + provider_type: 'onepassword'; |
| 226 | + |
| 227 | + /** |
| 228 | + * How long to cache credential lists (default 300 seconds) |
| 229 | + */ |
| 230 | + cache_ttl_seconds?: number; |
| 231 | +} |
| 232 | + |
| 233 | +export interface CredentialProviderUpdateParams { |
| 234 | + /** |
| 235 | + * New service account token (to rotate credentials) |
| 236 | + */ |
| 237 | + token?: string; |
| 238 | + |
| 239 | + /** |
| 240 | + * How long to cache credential lists |
| 241 | + */ |
| 242 | + cache_ttl_seconds?: number; |
| 243 | + |
| 244 | + /** |
| 245 | + * Whether the provider is enabled for credential lookups |
| 246 | + */ |
| 247 | + enabled?: boolean; |
| 248 | + |
| 249 | + /** |
| 250 | + * Priority order for credential lookups (lower numbers are checked first) |
| 251 | + */ |
| 252 | + priority?: number; |
| 253 | +} |
| 254 | + |
| 255 | +export declare namespace CredentialProviders { |
| 256 | + export { |
| 257 | + type CreateCredentialProviderRequest as CreateCredentialProviderRequest, |
| 258 | + type CredentialProvider as CredentialProvider, |
| 259 | + type CredentialProviderTestResult as CredentialProviderTestResult, |
| 260 | + type UpdateCredentialProviderRequest as UpdateCredentialProviderRequest, |
| 261 | + type CredentialProviderListResponse as CredentialProviderListResponse, |
| 262 | + type CredentialProviderCreateParams as CredentialProviderCreateParams, |
| 263 | + type CredentialProviderUpdateParams as CredentialProviderUpdateParams, |
| 264 | + }; |
| 265 | +} |
0 commit comments