Skip to content

Commit

Permalink
feat: add GenericSecretProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Jan 17, 2023
1 parent 16d30ea commit e490c37
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,36 @@ OIDC token must be issued for an allowed project **and** an allowed context. No

We have a few built-in secret providers documented below, you can build your own provider by importing and implementing the base `SecretProvider` class.

### Generic Secret Provider

This provider allows you to load secrets from _anywhere_ and hand them back in key<>value form.

```typescript
import { GenericSecretProvider } from '@electron/circleci-oidc-secret-exchange';

export const config = [
{
organizationId: 'foo',
secrets: [
provider: () => new GenericSecretProvider(
async () => ({
MY_COOL_SECRET: process.env.MY_COOL_SECRET,
OTHER_SECRET: await getFromSomewhere(),
})
),
filters: { ... },
]
}
]
```

### File Secret Provider

This provider loads a JSON file from disk and let's you read and provide secrets from it. The file is read fresh on every request
so if you change the file on disk even without restarting the service the updated secrets will be read

```typescript
import { GitHubAppTokenProvider } from '@electron/circleci-oidc-secret-exchange';
import { FileSecretProvider } from '@electron/circleci-oidc-secret-exchange';

export const config = [
{
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Fastify from 'fastify';
import { OIDCSecretExchangeConfig, OIDCSecretExchangeConfiguration } from './config';
import { getValidatedToken } from './oidc/validate-token';
import { FileSecretProvider } from './providers/FileProvider';
import { GenericSecretProvider } from './providers/GenericProvider';
import { GitHubAppTokenProvider } from './providers/GitHubAppProvider';
import { SecretProvider } from './SecretProvider';
import { CircleCIOIDCClaims } from './type';
Expand Down Expand Up @@ -138,4 +139,4 @@ export const configureAndListen = async (
});
};

export { FileSecretProvider, GitHubAppTokenProvider, SecretProvider };
export { FileSecretProvider, GenericSecretProvider, GitHubAppTokenProvider, SecretProvider };
19 changes: 19 additions & 0 deletions src/providers/GenericProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SecretProvider } from '../SecretProvider';

export class GenericSecretProvider extends SecretProvider<null> {
constructor(private getSecrets: () => Promise<Record<string, string>>) {
super();
}

loadableContentKey(): string {
return `generic-secret-no-content`;
}

async loadContent(): Promise<null> {
return null;
}

async provideSecrets(): Promise<Record<string, string>> {
return await Promise.resolve(this.getSecrets());
}
}

0 comments on commit e490c37

Please sign in to comment.