diff --git a/.changeset/four-pears-swim.md b/.changeset/four-pears-swim.md new file mode 100644 index 0000000000..b091dad598 --- /dev/null +++ b/.changeset/four-pears-swim.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-vault-node': minor +--- + +Initial version of the `plugin-vault-node`` package. It contains the extension point definitions +for the vault backend, as well as some types that will be deprecated in the backend plugin. diff --git a/plugins/vault-node/.eslintrc.js b/plugins/vault-node/.eslintrc.js new file mode 100644 index 0000000000..e2a53a6ad2 --- /dev/null +++ b/plugins/vault-node/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/vault-node/README.md b/plugins/vault-node/README.md new file mode 100644 index 0000000000..5f777e792b --- /dev/null +++ b/plugins/vault-node/README.md @@ -0,0 +1,3 @@ +# @backstage/plugin-vault-node + +Houses types and utilities for building the vault modules diff --git a/plugins/vault-node/api-report.md b/plugins/vault-node/api-report.md new file mode 100644 index 0000000000..d0e0a29f8f --- /dev/null +++ b/plugins/vault-node/api-report.md @@ -0,0 +1,38 @@ +## API Report File for "@backstage/plugin-vault-node" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { ExtensionPoint } from '@backstage/backend-plugin-api'; + +// @public +export interface VaultApi { + getFrontendSecretsUrl(): string; + listSecrets( + secretPath: string, + options?: { + secretEngine?: string; + }, + ): Promise; + renewToken?(): Promise; +} + +// @public +export interface VaultExtensionPoint { + // (undocumented) + setClient(vaultClient: VaultApi): void; +} + +// @public +export const vaultExtensionPoint: ExtensionPoint; + +// @public +export type VaultSecret = { + name: string; + path: string; + showUrl: string; + editUrl: string; +}; + +// (No @packageDocumentation comment for this package) +``` diff --git a/plugins/vault-node/catalog-info.yaml b/plugins/vault-node/catalog-info.yaml new file mode 100644 index 0000000000..6b6c8b84ad --- /dev/null +++ b/plugins/vault-node/catalog-info.yaml @@ -0,0 +1,10 @@ +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: backstage-plugin-vault-node + title: '@backstage/plugin-vault-node' + description: Node.js library for the vault plugin +spec: + lifecycle: experimental + type: backstage-node-library + owner: maintainers diff --git a/plugins/vault-node/package.json b/plugins/vault-node/package.json new file mode 100644 index 0000000000..a0a821680c --- /dev/null +++ b/plugins/vault-node/package.json @@ -0,0 +1,33 @@ +{ + "name": "@backstage/plugin-vault-node", + "description": "Node.js library for the vault plugin", + "version": "0.0.0", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "publishConfig": { + "access": "public", + "main": "dist/index.cjs.js", + "types": "dist/index.d.ts" + }, + "backstage": { + "role": "node-library" + }, + "scripts": { + "build": "backstage-cli package build", + "lint": "backstage-cli package lint", + "test": "backstage-cli package test", + "clean": "backstage-cli package clean", + "prepack": "backstage-cli package prepack", + "postpack": "backstage-cli package postpack" + }, + "dependencies": { + "@backstage/backend-plugin-api": "workspace:^" + }, + "devDependencies": { + "@backstage/cli": "workspace:^" + }, + "files": [ + "dist" + ] +} diff --git a/plugins/vault-node/src/api/index.ts b/plugins/vault-node/src/api/index.ts new file mode 100644 index 0000000000..92cb965d75 --- /dev/null +++ b/plugins/vault-node/src/api/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export * from './types'; diff --git a/plugins/vault-node/src/api/types.ts b/plugins/vault-node/src/api/types.ts new file mode 100644 index 0000000000..9969fb001b --- /dev/null +++ b/plugins/vault-node/src/api/types.ts @@ -0,0 +1,55 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Object containing the secret name and some links + * @public + */ +export type VaultSecret = { + name: string; + path: string; + showUrl: string; + editUrl: string; +}; + +/** + * Interface for the Vault API + * @public + */ +export interface VaultApi { + /** + * Returns the URL to access the Vault UI with the defined config. + */ + getFrontendSecretsUrl(): string; + + /** + * Returns a list of secrets used to show in a table. + * @param secretPath - The path where the secrets are stored in Vault + * @param options - Additional options to be passed to the Vault API, allows to override vault default settings in app config file + */ + listSecrets( + secretPath: string, + options?: { + secretEngine?: string; + }, + ): Promise; + + /** + * Optional, to renew the token used to list the secrets. Throws an + * error if the token renewal went wrong. + */ + renewToken?(): Promise; +} diff --git a/plugins/vault-node/src/extensions.ts b/plugins/vault-node/src/extensions.ts new file mode 100644 index 0000000000..efe4ba6223 --- /dev/null +++ b/plugins/vault-node/src/extensions.ts @@ -0,0 +1,36 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createExtensionPoint } from '@backstage/backend-plugin-api'; +import { VaultApi } from './api'; + +/** + * Extension point for vault. + * + * @public + */ +export interface VaultExtensionPoint { + setClient(vaultClient: VaultApi): void; +} + +/** + * Extension point for vault. + * + * @public + */ +export const vaultExtensionPoint = createExtensionPoint({ + id: 'vault.configuration', +}); diff --git a/plugins/vault-node/src/index.ts b/plugins/vault-node/src/index.ts new file mode 100644 index 0000000000..070f2cf64d --- /dev/null +++ b/plugins/vault-node/src/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { type VaultExtensionPoint, vaultExtensionPoint } from './extensions'; +export type { VaultApi, VaultSecret } from './api'; diff --git a/plugins/vault-node/src/setupTests.ts b/plugins/vault-node/src/setupTests.ts new file mode 100644 index 0000000000..4b9026cde5 --- /dev/null +++ b/plugins/vault-node/src/setupTests.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/yarn.lock b/yarn.lock index b029e6280f..0ac22cafa6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9909,6 +9909,7 @@ __metadata: "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" "@backstage/errors": "workspace:^" + "@backstage/plugin-vault-node": "workspace:^" "@types/compression": ^1.7.2 "@types/express": "*" "@types/supertest": ^2.0.8 @@ -9926,6 +9927,15 @@ __metadata: languageName: unknown linkType: soft +"@backstage/plugin-vault-node@workspace:^, @backstage/plugin-vault-node@workspace:plugins/vault-node": + version: 0.0.0-use.local + resolution: "@backstage/plugin-vault-node@workspace:plugins/vault-node" + dependencies: + "@backstage/backend-plugin-api": "workspace:^" + "@backstage/cli": "workspace:^" + languageName: unknown + linkType: soft + "@backstage/plugin-vault@workspace:plugins/vault": version: 0.0.0-use.local resolution: "@backstage/plugin-vault@workspace:plugins/vault"