-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: External Secrets storage for credentials (#6477)
Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: Romain Minaud <[email protected]> Co-authored-by: Valya Bullions <[email protected]> Co-authored-by: Csaba Tuncsik <[email protected]> Co-authored-by: Giulio Andreini <[email protected]> Co-authored-by: Omar Ajoue <[email protected]>
- Loading branch information
1 parent
c833078
commit ed927d3
Showing
89 changed files
with
4,164 additions
and
57 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
102 changes: 102 additions & 0 deletions
102
packages/cli/src/ExternalSecrets/ExternalSecrets.controller.ee.ts
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,102 @@ | ||
import { Authorized, Get, Post, RestController } from '@/decorators'; | ||
import { ExternalSecretsRequest } from '@/requests'; | ||
import { NotFoundError } from '@/ResponseHelper'; | ||
import { Response } from 'express'; | ||
import { Service } from 'typedi'; | ||
import { ProviderNotFoundError, ExternalSecretsService } from './ExternalSecrets.service.ee'; | ||
|
||
@Service() | ||
@Authorized(['global', 'owner']) | ||
@RestController('/external-secrets') | ||
export class ExternalSecretsController { | ||
constructor(private readonly secretsService: ExternalSecretsService) {} | ||
|
||
@Get('/providers') | ||
async getProviders() { | ||
return this.secretsService.getProviders(); | ||
} | ||
|
||
@Get('/providers/:provider') | ||
async getProvider(req: ExternalSecretsRequest.GetProvider) { | ||
const providerName = req.params.provider; | ||
try { | ||
return this.secretsService.getProvider(providerName); | ||
} catch (e) { | ||
if (e instanceof ProviderNotFoundError) { | ||
throw new NotFoundError(`Could not find provider "${e.providerName}"`); | ||
} | ||
throw e; | ||
} | ||
} | ||
|
||
@Post('/providers/:provider/test') | ||
async testProviderSettings(req: ExternalSecretsRequest.TestProviderSettings, res: Response) { | ||
const providerName = req.params.provider; | ||
try { | ||
const result = await this.secretsService.testProviderSettings(providerName, req.body); | ||
if (result.success) { | ||
res.statusCode = 200; | ||
} else { | ||
res.statusCode = 400; | ||
} | ||
return result; | ||
} catch (e) { | ||
if (e instanceof ProviderNotFoundError) { | ||
throw new NotFoundError(`Could not find provider "${e.providerName}"`); | ||
} | ||
throw e; | ||
} | ||
} | ||
|
||
@Post('/providers/:provider') | ||
async setProviderSettings(req: ExternalSecretsRequest.SetProviderSettings) { | ||
const providerName = req.params.provider; | ||
try { | ||
await this.secretsService.saveProviderSettings(providerName, req.body, req.user.id); | ||
} catch (e) { | ||
if (e instanceof ProviderNotFoundError) { | ||
throw new NotFoundError(`Could not find provider "${e.providerName}"`); | ||
} | ||
throw e; | ||
} | ||
return {}; | ||
} | ||
|
||
@Post('/providers/:provider/connect') | ||
async setProviderConnected(req: ExternalSecretsRequest.SetProviderConnected) { | ||
const providerName = req.params.provider; | ||
try { | ||
await this.secretsService.saveProviderConnected(providerName, req.body.connected); | ||
} catch (e) { | ||
if (e instanceof ProviderNotFoundError) { | ||
throw new NotFoundError(`Could not find provider "${e.providerName}"`); | ||
} | ||
throw e; | ||
} | ||
return {}; | ||
} | ||
|
||
@Post('/providers/:provider/update') | ||
async updateProvider(req: ExternalSecretsRequest.UpdateProvider, res: Response) { | ||
const providerName = req.params.provider; | ||
try { | ||
const resp = await this.secretsService.updateProvider(providerName); | ||
if (resp) { | ||
res.statusCode = 200; | ||
} else { | ||
res.statusCode = 400; | ||
} | ||
return { updated: resp }; | ||
} catch (e) { | ||
if (e instanceof ProviderNotFoundError) { | ||
throw new NotFoundError(`Could not find provider "${e.providerName}"`); | ||
} | ||
throw e; | ||
} | ||
} | ||
|
||
@Get('/secrets') | ||
getSecretNames() { | ||
return this.secretsService.getAllSecrets(); | ||
} | ||
} |
Oops, something went wrong.