@backstage/plugin-catalog-backend-module-aws 0.1.3 → 0.1.4-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,105 @@
1
1
  # @backstage/plugin-catalog-backend-module-aws
2
2
 
3
+ ## 0.1.4-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 5969c4b65c: Add a new provider `AwsS3EntityProvider` as replacement for `AwsS3DiscoveryProcessor`.
8
+
9
+ In order to migrate from the `AwsS3DiscoveryProcessor` you need to apply
10
+ the following changes:
11
+
12
+ **Before:**
13
+
14
+ ```yaml
15
+ # app-config.yaml
16
+
17
+ catalog:
18
+ locations:
19
+ - type: s3-discovery
20
+ target: https://sample-bucket.s3.us-east-2.amazonaws.com/prefix/
21
+ ```
22
+
23
+ ```ts
24
+ /* packages/backend/src/plugins/catalog.ts */
25
+
26
+ import { AwsS3DiscoveryProcessor } from '@backstage/plugin-catalog-backend-module-aws';
27
+
28
+ const builder = await CatalogBuilder.create(env);
29
+ /** ... other processors ... */
30
+ builder.addProcessor(new AwsS3DiscoveryProcessor(env.reader));
31
+ ```
32
+
33
+ **After:**
34
+
35
+ ```yaml
36
+ # app-config.yaml
37
+
38
+ catalog:
39
+ providers:
40
+ awsS3:
41
+ yourProviderId: # identifies your dataset / provider independent of config changes
42
+ bucketName: sample-bucket
43
+ prefix: prefix/ # optional
44
+ region: us-east-2 # optional, uses the default region otherwise
45
+ ```
46
+
47
+ ```ts
48
+ /* packages/backend/src/plugins/catalog.ts */
49
+
50
+ import { AwsS3EntityProvider } from '@backstage/plugin-catalog-backend-module-aws';
51
+
52
+ const builder = await CatalogBuilder.create(env);
53
+ /** ... other processors and/or providers ... */
54
+ builder.addEntityProvider(
55
+ ...AwsS3EntityProvider.fromConfig(env.config, {
56
+ logger: env.logger,
57
+ schedule: env.scheduler.createScheduledTaskRunner({
58
+ frequency: Duration.fromObject({ minutes: 30 }),
59
+ timeout: Duration.fromObject({ minutes: 3 }),
60
+ }),
61
+ }),
62
+ );
63
+ ```
64
+
65
+ For simple setups, you can omit the provider ID at the config
66
+ which has the same effect as using `default` for it.
67
+
68
+ ```yaml
69
+ # app-config.yaml
70
+
71
+ catalog:
72
+ providers:
73
+ awsS3:
74
+ # uses "default" as provider ID
75
+ bucketName: sample-bucket
76
+ prefix: prefix/ # optional
77
+ region: us-east-2 # optional, uses the default region otherwise
78
+ ```
79
+
80
+ - 776a91ea3a: Corrected title and URL to setup documentation in README
81
+ - Updated dependencies
82
+ - @backstage/plugin-catalog-backend@1.1.0-next.3
83
+ - @backstage/backend-common@0.13.2-next.2
84
+ - @backstage/integration@1.1.0-next.2
85
+
86
+ ## 0.1.4-next.1
87
+
88
+ ### Patch Changes
89
+
90
+ - Updated dependencies
91
+ - @backstage/plugin-catalog-backend@1.1.0-next.1
92
+ - @backstage/backend-common@0.13.2-next.1
93
+
94
+ ## 0.1.4-next.0
95
+
96
+ ### Patch Changes
97
+
98
+ - Updated dependencies
99
+ - @backstage/catalog-model@1.0.1-next.0
100
+ - @backstage/plugin-catalog-backend@1.0.1-next.0
101
+ - @backstage/backend-common@0.13.2-next.0
102
+
3
103
  ## 0.1.3
4
104
 
5
105
  ### Patch Changes
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Catalog Backend Module for LDAP
1
+ # Catalog Backend Module for AWS
2
2
 
3
3
  This is an extension module to the plugin-catalog-backend plugin, providing an
4
4
  `AwsOrganizationCloudAccountProcessor` that can be used to ingest cloud accounts
@@ -6,5 +6,5 @@ as `Resource` kind entities.
6
6
 
7
7
  ## Getting started
8
8
 
9
- See [Backstage documentation](https://backstage.io/docs/integrations/ldap/org) for details on how to install
9
+ See [Backstage documentation](https://backstage.io/docs/integrations/aws-s3/discovery) for details on how to install
10
10
  and configure the plugin.
package/config.d.ts CHANGED
@@ -14,6 +14,27 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ interface AwsS3Config {
18
+ /**
19
+ * (Required) AWS S3 Bucket Name
20
+ * @visibility backend
21
+ */
22
+ bucketName: string;
23
+ /**
24
+ * (Optional) AWS S3 Object key prefix
25
+ * If not set, all keys will be accepted, no filtering will be applied.
26
+ * @visibility backend
27
+ */
28
+ prefix?: string;
29
+ /**
30
+ * (Optional) AWS Region.
31
+ * If not set, AWS_REGION environment variable or aws config file will be used.
32
+ * @see https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-region.html
33
+ * @visibility backend
34
+ */
35
+ region?: string;
36
+ }
37
+
17
38
  export interface Config {
18
39
  catalog?: {
19
40
  /**
@@ -32,5 +53,16 @@ export interface Config {
32
53
  };
33
54
  };
34
55
  };
56
+ /**
57
+ * List of provider-specific options and attributes
58
+ */
59
+ providers?: {
60
+ /**
61
+ * AwsS3EntityProvider configuration
62
+ *
63
+ * Uses "default" as default id for the single config variant.
64
+ */
65
+ awsS3?: AwsS3Config | Record<string, AwsS3Config>;
66
+ };
35
67
  };
36
68
  }
package/dist/index.cjs.js CHANGED
@@ -6,11 +6,32 @@ var pluginCatalogBackend = require('@backstage/plugin-catalog-backend');
6
6
  var AWS = require('aws-sdk');
7
7
  var errors = require('@backstage/errors');
8
8
  var limiterFactory = require('p-limit');
9
+ var integration = require('@backstage/integration');
10
+ var uuid = require('uuid');
9
11
 
10
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
13
 
14
+ function _interopNamespace(e) {
15
+ if (e && e.__esModule) return e;
16
+ var n = Object.create(null);
17
+ if (e) {
18
+ Object.keys(e).forEach(function (k) {
19
+ if (k !== 'default') {
20
+ var d = Object.getOwnPropertyDescriptor(e, k);
21
+ Object.defineProperty(n, k, d.get ? d : {
22
+ enumerable: true,
23
+ get: function () { return e[k]; }
24
+ });
25
+ }
26
+ });
27
+ }
28
+ n["default"] = e;
29
+ return Object.freeze(n);
30
+ }
31
+
12
32
  var AWS__default = /*#__PURE__*/_interopDefaultLegacy(AWS);
13
33
  var limiterFactory__default = /*#__PURE__*/_interopDefaultLegacy(limiterFactory);
34
+ var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
14
35
 
15
36
  function readAwsOrganizationConfig(config) {
16
37
  const providerConfig = config.getOptionalConfig("provider");
@@ -164,6 +185,175 @@ class AwsS3DiscoveryProcessor {
164
185
  }
165
186
  }
166
187
 
188
+ class AwsCredentials {
189
+ static create(config, roleSessionName) {
190
+ if (!config) {
191
+ return void 0;
192
+ }
193
+ const accessKeyId = config.accessKeyId;
194
+ const secretAccessKey = config.secretAccessKey;
195
+ let explicitCredentials;
196
+ if (accessKeyId && secretAccessKey) {
197
+ explicitCredentials = new AWS.Credentials({
198
+ accessKeyId,
199
+ secretAccessKey
200
+ });
201
+ }
202
+ const roleArn = config.roleArn;
203
+ if (roleArn) {
204
+ return new AWS__default["default"].ChainableTemporaryCredentials({
205
+ masterCredentials: explicitCredentials,
206
+ params: {
207
+ RoleArn: roleArn,
208
+ RoleSessionName: roleSessionName
209
+ }
210
+ });
211
+ }
212
+ return explicitCredentials;
213
+ }
214
+ }
215
+
216
+ const DEFAULT_PROVIDER_ID = "default";
217
+ function readAwsS3Configs(config) {
218
+ const configs = [];
219
+ const providerConfigs = config.getOptionalConfig("catalog.providers.awsS3");
220
+ if (!providerConfigs) {
221
+ return configs;
222
+ }
223
+ if (providerConfigs.has("bucketName")) {
224
+ configs.push(readAwsS3Config(DEFAULT_PROVIDER_ID, providerConfigs));
225
+ return configs;
226
+ }
227
+ for (const id of providerConfigs.keys()) {
228
+ configs.push(readAwsS3Config(id, providerConfigs.getConfig(id)));
229
+ }
230
+ return configs;
231
+ }
232
+ function readAwsS3Config(id, config) {
233
+ const bucketName = config.getString("bucketName");
234
+ const region = config.getOptionalString("region");
235
+ const prefix = config.getOptionalString("prefix");
236
+ return {
237
+ id,
238
+ bucketName,
239
+ region,
240
+ prefix
241
+ };
242
+ }
243
+
244
+ class AwsS3EntityProvider {
245
+ constructor(config, integration, logger, schedule) {
246
+ this.config = config;
247
+ this.integration = integration;
248
+ this.logger = logger.child({
249
+ target: this.getProviderName()
250
+ });
251
+ this.s3 = new AWS.S3({
252
+ apiVersion: "2006-03-01",
253
+ credentials: AwsCredentials.create(integration.config, "backstage-aws-s3-provider"),
254
+ endpoint: integration.config.endpoint,
255
+ region: this.config.region,
256
+ s3ForcePathStyle: integration.config.s3ForcePathStyle
257
+ });
258
+ this.scheduleFn = this.createScheduleFn(schedule);
259
+ }
260
+ static fromConfig(configRoot, options) {
261
+ const providerConfigs = readAwsS3Configs(configRoot);
262
+ const integration$1 = integration.ScmIntegrations.fromConfig(configRoot).awsS3.list()[0];
263
+ if (!integration$1) {
264
+ throw new Error("No integration found for awsS3");
265
+ }
266
+ return providerConfigs.map((providerConfig) => new AwsS3EntityProvider(providerConfig, integration$1, options.logger, options.schedule));
267
+ }
268
+ createScheduleFn(schedule) {
269
+ return async () => {
270
+ const taskId = `${this.getProviderName()}:refresh`;
271
+ return schedule.run({
272
+ id: taskId,
273
+ fn: async () => {
274
+ const logger = this.logger.child({
275
+ class: AwsS3EntityProvider.prototype.constructor.name,
276
+ taskId,
277
+ taskInstanceId: uuid__namespace.v4()
278
+ });
279
+ try {
280
+ await this.refresh(logger);
281
+ } catch (error) {
282
+ logger.error(error);
283
+ }
284
+ }
285
+ });
286
+ };
287
+ }
288
+ getProviderName() {
289
+ return `awsS3-provider:${this.config.id}`;
290
+ }
291
+ async connect(connection) {
292
+ this.connection = connection;
293
+ await this.scheduleFn();
294
+ }
295
+ async refresh(logger) {
296
+ if (!this.connection) {
297
+ throw new Error("Not initialized");
298
+ }
299
+ logger.info("Discovering AWS S3 objects");
300
+ const keys = await this.listAllObjectKeys();
301
+ logger.info(`Discovered ${keys.length} AWS S3 objects`);
302
+ const locations = keys.map((key) => this.createLocationSpec(key));
303
+ await this.connection.applyMutation({
304
+ type: "full",
305
+ entities: locations.map((location) => {
306
+ return {
307
+ locationKey: this.getProviderName(),
308
+ entity: pluginCatalogBackend.locationSpecToLocationEntity({ location })
309
+ };
310
+ })
311
+ });
312
+ logger.info(`Committed ${locations.length} Locations for AWS S3 objects`);
313
+ }
314
+ async listAllObjectKeys() {
315
+ const keys = [];
316
+ let continuationToken = void 0;
317
+ let output;
318
+ do {
319
+ const request = this.s3.listObjectsV2({
320
+ Bucket: this.config.bucketName,
321
+ ContinuationToken: continuationToken,
322
+ Prefix: this.config.prefix
323
+ });
324
+ output = await request.promise();
325
+ if (output.Contents) {
326
+ output.Contents.forEach((item) => {
327
+ if (item.Key && !item.Key.endsWith("/")) {
328
+ keys.push(item.Key);
329
+ }
330
+ });
331
+ }
332
+ continuationToken = output.NextContinuationToken;
333
+ } while (continuationToken);
334
+ return keys;
335
+ }
336
+ createLocationSpec(key) {
337
+ return {
338
+ type: "url",
339
+ target: this.createObjectUrl(key),
340
+ presence: "required"
341
+ };
342
+ }
343
+ createObjectUrl(key) {
344
+ const bucketName = this.config.bucketName;
345
+ const endpoint = this.integration.config.endpoint;
346
+ if (endpoint) {
347
+ if (endpoint.startsWith(`https://${bucketName}.`)) {
348
+ return `${endpoint}/${key}`;
349
+ }
350
+ return `${endpoint}/${bucketName}/${key}`;
351
+ }
352
+ return `https://${bucketName}.s3.${this.config.region}.amazonaws.com/${key}`;
353
+ }
354
+ }
355
+
167
356
  exports.AwsOrganizationCloudAccountProcessor = AwsOrganizationCloudAccountProcessor;
168
357
  exports.AwsS3DiscoveryProcessor = AwsS3DiscoveryProcessor;
358
+ exports.AwsS3EntityProvider = AwsS3EntityProvider;
169
359
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/awsOrganization/config.ts","../src/processors/AwsOrganizationCloudAccountProcessor.ts","../src/processors/AwsS3DiscoveryProcessor.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\n\n/**\n * The configuration parameters for a single AWS Organization Processor\n */\nexport type AwsOrganizationProviderConfig = {\n /**\n * The role to assume for the processor.\n */\n roleArn?: string;\n};\n\nexport function readAwsOrganizationConfig(\n config: Config,\n): AwsOrganizationProviderConfig {\n const providerConfig = config.getOptionalConfig('provider');\n\n const roleArn = providerConfig?.getOptionalString('roleArn');\n return {\n roleArn,\n };\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ResourceEntityV1alpha1 } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport {\n CatalogProcessor,\n CatalogProcessorEmit,\n LocationSpec,\n processingResult,\n} from '@backstage/plugin-catalog-backend';\nimport AWS, { Credentials, Organizations } from 'aws-sdk';\nimport { Account, ListAccountsResponse } from 'aws-sdk/clients/organizations';\nimport { Logger } from 'winston';\nimport {\n AwsOrganizationProviderConfig,\n readAwsOrganizationConfig,\n} from '../awsOrganization/config';\n\nconst AWS_ORGANIZATION_REGION = 'us-east-1';\nconst LOCATION_TYPE = 'aws-cloud-accounts';\n\nconst ACCOUNTID_ANNOTATION = 'amazonaws.com/account-id';\nconst ARN_ANNOTATION = 'amazonaws.com/arn';\nconst ORGANIZATION_ANNOTATION = 'amazonaws.com/organization-id';\n\n/**\n * A processor for ingesting AWS Accounts from AWS Organizations.\n *\n * If custom authentication is needed, it can be achieved by configuring the\n * global AWS.credentials object.\n *\n * @public\n */\nexport class AwsOrganizationCloudAccountProcessor implements CatalogProcessor {\n private readonly organizations: Organizations;\n private readonly provider: AwsOrganizationProviderConfig;\n\n static fromConfig(config: Config, options: { logger: Logger }) {\n const c = config.getOptionalConfig('catalog.processors.awsOrganization');\n return new AwsOrganizationCloudAccountProcessor({\n ...options,\n provider: c ? readAwsOrganizationConfig(c) : {},\n });\n }\n\n private static buildCredentials(\n config: AwsOrganizationProviderConfig,\n ): Credentials | undefined {\n const roleArn = config.roleArn;\n if (!roleArn) {\n return undefined;\n }\n\n return new AWS.ChainableTemporaryCredentials({\n params: {\n RoleSessionName: 'backstage-aws-organization-processor',\n RoleArn: roleArn,\n },\n });\n }\n\n private constructor(options: { provider: AwsOrganizationProviderConfig }) {\n this.provider = options.provider;\n const credentials = AwsOrganizationCloudAccountProcessor.buildCredentials(\n this.provider,\n );\n this.organizations = new AWS.Organizations({\n credentials,\n region: AWS_ORGANIZATION_REGION,\n }); // Only available in us-east-1\n }\n\n getProcessorName(): string {\n return 'AwsOrganizationCloudAccountProcessor';\n }\n\n async readLocation(\n location: LocationSpec,\n _optional: boolean,\n emit: CatalogProcessorEmit,\n ): Promise<boolean> {\n if (location.type !== LOCATION_TYPE) {\n return false;\n }\n\n (await this.getAwsAccounts())\n .map(account => this.mapAccountToComponent(account))\n .filter(entity => {\n if (location.target !== '') {\n if (entity.metadata.annotations) {\n return (\n entity.metadata.annotations[ORGANIZATION_ANNOTATION] ===\n location.target\n );\n }\n return false;\n }\n return true;\n })\n .forEach(entity => {\n emit(processingResult.entity(location, entity));\n });\n\n return true;\n }\n\n private normalizeName(name: string): string {\n return name\n .trim()\n .toLocaleLowerCase('en-US')\n .replace(/[^a-zA-Z0-9\\-]/g, '-');\n }\n\n private extractInformationFromArn(arn: string): {\n accountId: string;\n organizationId: string;\n } {\n const parts = arn.split('/');\n\n return {\n accountId: parts[parts.length - 1],\n organizationId: parts[parts.length - 2],\n };\n }\n\n private async getAwsAccounts(): Promise<Account[]> {\n let awsAccounts: Account[] = [];\n let isInitialAttempt = true;\n let nextToken = undefined;\n while (isInitialAttempt || nextToken) {\n isInitialAttempt = false;\n const orgAccounts: ListAccountsResponse = await this.organizations\n .listAccounts({ NextToken: nextToken })\n .promise();\n if (orgAccounts.Accounts) {\n awsAccounts = awsAccounts.concat(orgAccounts.Accounts);\n }\n nextToken = orgAccounts.NextToken;\n }\n\n return awsAccounts;\n }\n\n private mapAccountToComponent(account: Account): ResourceEntityV1alpha1 {\n const { accountId, organizationId } = this.extractInformationFromArn(\n account.Arn as string,\n );\n return {\n apiVersion: 'backstage.io/v1alpha1',\n kind: 'Resource',\n metadata: {\n annotations: {\n [ACCOUNTID_ANNOTATION]: accountId,\n [ARN_ANNOTATION]: account.Arn || '',\n [ORGANIZATION_ANNOTATION]: organizationId,\n },\n name: this.normalizeName(account.Name || ''),\n namespace: 'default',\n },\n spec: {\n type: 'cloud-account',\n owner: 'unknown',\n },\n };\n }\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { UrlReader } from '@backstage/backend-common';\nimport { isError } from '@backstage/errors';\nimport {\n CatalogProcessor,\n CatalogProcessorEmit,\n CatalogProcessorParser,\n LocationSpec,\n processingResult,\n} from '@backstage/plugin-catalog-backend';\nimport limiterFactory from 'p-limit';\n\n/**\n * A processor for automatic discovery of entities from S3 buckets. Handles the\n * `s3-discovery` location type, and target bucket URLs e.g. on the form\n * `https://testbucket.s3.us-east-2.amazonaws.com`.\n *\n * @public\n */\nexport class AwsS3DiscoveryProcessor implements CatalogProcessor {\n constructor(private readonly reader: UrlReader) {}\n\n getProcessorName(): string {\n return 'AwsS3DiscoveryProcessor';\n }\n\n async readLocation(\n location: LocationSpec,\n optional: boolean,\n emit: CatalogProcessorEmit,\n parser: CatalogProcessorParser,\n ): Promise<boolean> {\n if (location.type !== 's3-discovery') {\n return false;\n }\n\n try {\n const output = await this.doRead(location.target);\n for (const item of output) {\n for await (const parseResult of parser({\n data: item.data,\n location: { type: location.type, target: item.url },\n })) {\n emit(parseResult);\n }\n }\n } catch (error) {\n const message = `Unable to read ${location.type}, ${error}`;\n\n if (isError(error) && error.name === 'NotFoundError') {\n if (!optional) {\n emit(processingResult.notFoundError(location, message));\n }\n } else {\n emit(processingResult.generalError(location, message));\n }\n }\n return true;\n }\n\n private async doRead(\n location: string,\n ): Promise<{ data: Buffer; url: string }[]> {\n const limiter = limiterFactory(5);\n const response = await this.reader.readTree(location);\n const responseFiles = await response.files();\n const output = responseFiles.map(async file => ({\n url: file.path,\n data: await limiter(file.content),\n }));\n return Promise.all(output);\n }\n}\n"],"names":["AWS","processingResult","isError","limiterFactory"],"mappings":";;;;;;;;;;;;;;AA4BO,SAAA,yBAAA,CACL,MAC+B,EAAA;AAC/B,EAAM,MAAA,cAAA,GAAiB,OAAO,iBAAkB,CAAA,UAAA,CAAA,CAAA;AAEhD,EAAM,MAAA,OAAA,GAAU,iDAAgB,iBAAkB,CAAA,SAAA,CAAA,CAAA;AAClD,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,GAAA,CAAA;AAAA;;ACHJ,MAAM,uBAA0B,GAAA,WAAA,CAAA;AAChC,MAAM,aAAgB,GAAA,oBAAA,CAAA;AAEtB,MAAM,oBAAuB,GAAA,0BAAA,CAAA;AAC7B,MAAM,cAAiB,GAAA,mBAAA,CAAA;AACvB,MAAM,uBAA0B,GAAA,+BAAA,CAAA;AAU8C,MAAA,oCAAA,CAAA;AAAA,EAIrE,OAAA,UAAA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AAM,QAAW,GAAA,MAAM,IAAK,CAAA,MAAA,CAAO,QAAS,CAAA,QAAA,CAAA,CAAA;AAC5C,IAAM,MAAA,aAAA,GAAgB,MAAM,QAAS,CAAA,KAAA,EAAA,CAAA;AACrC,IAAA,MAAM,MAAS,GAAA,aAAA,CAAc,GAAI,CAAA,OAAM,IAAS,MAAA;AAAA,MAC9C,KAAK,IAAK,CAAA,IAAA;AAAA,MACV,IAAA,EAAM,MAAM,OAAA,CAAQ,IAAK,CAAA,OAAA,CAAA;AAAA,KAAA,CAAA,CAAA,CAAA;AAE3B,IAAA,OAAO,QAAQ,GAAI,CAAA,MAAA,CAAA,CAAA;AAAA,GAAA;AAAA;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/awsOrganization/config.ts","../src/processors/AwsOrganizationCloudAccountProcessor.ts","../src/processors/AwsS3DiscoveryProcessor.ts","../src/credentials/AwsCredentials.ts","../src/providers/config.ts","../src/providers/AwsS3EntityProvider.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\n\n/**\n * The configuration parameters for a single AWS Organization Processor\n */\nexport type AwsOrganizationProviderConfig = {\n /**\n * The role to assume for the processor.\n */\n roleArn?: string;\n};\n\nexport function readAwsOrganizationConfig(\n config: Config,\n): AwsOrganizationProviderConfig {\n const providerConfig = config.getOptionalConfig('provider');\n\n const roleArn = providerConfig?.getOptionalString('roleArn');\n return {\n roleArn,\n };\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ResourceEntityV1alpha1 } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport {\n CatalogProcessor,\n CatalogProcessorEmit,\n LocationSpec,\n processingResult,\n} from '@backstage/plugin-catalog-backend';\nimport AWS, { Credentials, Organizations } from 'aws-sdk';\nimport { Account, ListAccountsResponse } from 'aws-sdk/clients/organizations';\nimport { Logger } from 'winston';\nimport {\n AwsOrganizationProviderConfig,\n readAwsOrganizationConfig,\n} from '../awsOrganization/config';\n\nconst AWS_ORGANIZATION_REGION = 'us-east-1';\nconst LOCATION_TYPE = 'aws-cloud-accounts';\n\nconst ACCOUNTID_ANNOTATION = 'amazonaws.com/account-id';\nconst ARN_ANNOTATION = 'amazonaws.com/arn';\nconst ORGANIZATION_ANNOTATION = 'amazonaws.com/organization-id';\n\n/**\n * A processor for ingesting AWS Accounts from AWS Organizations.\n *\n * If custom authentication is needed, it can be achieved by configuring the\n * global AWS.credentials object.\n *\n * @public\n */\nexport class AwsOrganizationCloudAccountProcessor implements CatalogProcessor {\n private readonly organizations: Organizations;\n private readonly provider: AwsOrganizationProviderConfig;\n\n static fromConfig(config: Config, options: { logger: Logger }) {\n const c = config.getOptionalConfig('catalog.processors.awsOrganization');\n return new AwsOrganizationCloudAccountProcessor({\n ...options,\n provider: c ? readAwsOrganizationConfig(c) : {},\n });\n }\n\n private static buildCredentials(\n config: AwsOrganizationProviderConfig,\n ): Credentials | undefined {\n const roleArn = config.roleArn;\n if (!roleArn) {\n return undefined;\n }\n\n return new AWS.ChainableTemporaryCredentials({\n params: {\n RoleSessionName: 'backstage-aws-organization-processor',\n RoleArn: roleArn,\n },\n });\n }\n\n private constructor(options: { provider: AwsOrganizationProviderConfig }) {\n this.provider = options.provider;\n const credentials = AwsOrganizationCloudAccountProcessor.buildCredentials(\n this.provider,\n );\n this.organizations = new AWS.Organizations({\n credentials,\n region: AWS_ORGANIZATION_REGION,\n }); // Only available in us-east-1\n }\n\n getProcessorName(): string {\n return 'AwsOrganizationCloudAccountProcessor';\n }\n\n async readLocation(\n location: LocationSpec,\n _optional: boolean,\n emit: CatalogProcessorEmit,\n ): Promise<boolean> {\n if (location.type !== LOCATION_TYPE) {\n return false;\n }\n\n (await this.getAwsAccounts())\n .map(account => this.mapAccountToComponent(account))\n .filter(entity => {\n if (location.target !== '') {\n if (entity.metadata.annotations) {\n return (\n entity.metadata.annotations[ORGANIZATION_ANNOTATION] ===\n location.target\n );\n }\n return false;\n }\n return true;\n })\n .forEach(entity => {\n emit(processingResult.entity(location, entity));\n });\n\n return true;\n }\n\n private normalizeName(name: string): string {\n return name\n .trim()\n .toLocaleLowerCase('en-US')\n .replace(/[^a-zA-Z0-9\\-]/g, '-');\n }\n\n private extractInformationFromArn(arn: string): {\n accountId: string;\n organizationId: string;\n } {\n const parts = arn.split('/');\n\n return {\n accountId: parts[parts.length - 1],\n organizationId: parts[parts.length - 2],\n };\n }\n\n private async getAwsAccounts(): Promise<Account[]> {\n let awsAccounts: Account[] = [];\n let isInitialAttempt = true;\n let nextToken = undefined;\n while (isInitialAttempt || nextToken) {\n isInitialAttempt = false;\n const orgAccounts: ListAccountsResponse = await this.organizations\n .listAccounts({ NextToken: nextToken })\n .promise();\n if (orgAccounts.Accounts) {\n awsAccounts = awsAccounts.concat(orgAccounts.Accounts);\n }\n nextToken = orgAccounts.NextToken;\n }\n\n return awsAccounts;\n }\n\n private mapAccountToComponent(account: Account): ResourceEntityV1alpha1 {\n const { accountId, organizationId } = this.extractInformationFromArn(\n account.Arn as string,\n );\n return {\n apiVersion: 'backstage.io/v1alpha1',\n kind: 'Resource',\n metadata: {\n annotations: {\n [ACCOUNTID_ANNOTATION]: accountId,\n [ARN_ANNOTATION]: account.Arn || '',\n [ORGANIZATION_ANNOTATION]: organizationId,\n },\n name: this.normalizeName(account.Name || ''),\n namespace: 'default',\n },\n spec: {\n type: 'cloud-account',\n owner: 'unknown',\n },\n };\n }\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { UrlReader } from '@backstage/backend-common';\nimport { isError } from '@backstage/errors';\nimport {\n CatalogProcessor,\n CatalogProcessorEmit,\n CatalogProcessorParser,\n LocationSpec,\n processingResult,\n} from '@backstage/plugin-catalog-backend';\nimport limiterFactory from 'p-limit';\n\n/**\n * A processor for automatic discovery of entities from S3 buckets. Handles the\n * `s3-discovery` location type, and target bucket URLs e.g. on the form\n * `https://testbucket.s3.us-east-2.amazonaws.com`.\n *\n * @public\n */\nexport class AwsS3DiscoveryProcessor implements CatalogProcessor {\n constructor(private readonly reader: UrlReader) {}\n\n getProcessorName(): string {\n return 'AwsS3DiscoveryProcessor';\n }\n\n async readLocation(\n location: LocationSpec,\n optional: boolean,\n emit: CatalogProcessorEmit,\n parser: CatalogProcessorParser,\n ): Promise<boolean> {\n if (location.type !== 's3-discovery') {\n return false;\n }\n\n try {\n const output = await this.doRead(location.target);\n for (const item of output) {\n for await (const parseResult of parser({\n data: item.data,\n location: { type: location.type, target: item.url },\n })) {\n emit(parseResult);\n }\n }\n } catch (error) {\n const message = `Unable to read ${location.type}, ${error}`;\n\n if (isError(error) && error.name === 'NotFoundError') {\n if (!optional) {\n emit(processingResult.notFoundError(location, message));\n }\n } else {\n emit(processingResult.generalError(location, message));\n }\n }\n return true;\n }\n\n private async doRead(\n location: string,\n ): Promise<{ data: Buffer; url: string }[]> {\n const limiter = limiterFactory(5);\n const response = await this.reader.readTree(location);\n const responseFiles = await response.files();\n const output = responseFiles.map(async file => ({\n url: file.path,\n data: await limiter(file.content),\n }));\n return Promise.all(output);\n }\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport aws, { Credentials } from 'aws-sdk';\nimport { CredentialsOptions } from 'aws-sdk/lib/credentials';\n\nexport class AwsCredentials {\n /**\n * If accessKeyId and secretAccessKey are missing, the DefaultAWSCredentialsProviderChain will be used:\n * https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html\n */\n static create(\n config: {\n accessKeyId?: string;\n secretAccessKey?: string;\n roleArn?: string;\n },\n roleSessionName: string,\n ): Credentials | CredentialsOptions | undefined {\n if (!config) {\n return undefined;\n }\n\n const accessKeyId = config.accessKeyId;\n const secretAccessKey = config.secretAccessKey;\n let explicitCredentials: Credentials | undefined;\n\n if (accessKeyId && secretAccessKey) {\n explicitCredentials = new Credentials({\n accessKeyId,\n secretAccessKey,\n });\n }\n\n const roleArn = config.roleArn;\n if (roleArn) {\n return new aws.ChainableTemporaryCredentials({\n masterCredentials: explicitCredentials,\n params: {\n RoleArn: roleArn,\n RoleSessionName: roleSessionName,\n },\n });\n }\n\n return explicitCredentials;\n }\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\nimport { AwsS3Config } from './types';\n\nconst DEFAULT_PROVIDER_ID = 'default';\n\nexport function readAwsS3Configs(config: Config): AwsS3Config[] {\n const configs: AwsS3Config[] = [];\n\n const providerConfigs = config.getOptionalConfig('catalog.providers.awsS3');\n if (!providerConfigs) {\n return configs;\n }\n\n if (providerConfigs.has('bucketName')) {\n // simple/single config variant\n configs.push(readAwsS3Config(DEFAULT_PROVIDER_ID, providerConfigs));\n\n return configs;\n }\n\n for (const id of providerConfigs.keys()) {\n configs.push(readAwsS3Config(id, providerConfigs.getConfig(id)));\n }\n\n return configs;\n}\n\nfunction readAwsS3Config(id: string, config: Config): AwsS3Config {\n const bucketName = config.getString('bucketName');\n const region = config.getOptionalString('region');\n const prefix = config.getOptionalString('prefix');\n\n return {\n id,\n bucketName,\n region,\n prefix,\n };\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TaskRunner } from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\nimport { AwsS3Integration, ScmIntegrations } from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n LocationSpec,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-backend';\nimport { AwsCredentials } from '../credentials/AwsCredentials';\nimport { readAwsS3Configs } from './config';\nimport { AwsS3Config } from './types';\nimport { S3 } from 'aws-sdk';\nimport { ListObjectsV2Output } from 'aws-sdk/clients/s3';\nimport * as uuid from 'uuid';\nimport { Logger } from 'winston';\n\n// TODO: event-based updates using S3 events (+ queue like SQS)?\n/**\n * Provider which discovers catalog files (any name) within an S3 bucket.\n *\n * Use `AwsS3EntityProvider.fromConfig(...)` to create instances.\n *\n * @public\n */\nexport class AwsS3EntityProvider implements EntityProvider {\n private readonly logger: Logger;\n private readonly s3: S3;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n\n static fromConfig(\n configRoot: Config,\n options: {\n logger: Logger;\n schedule: TaskRunner;\n },\n ): AwsS3EntityProvider[] {\n const providerConfigs = readAwsS3Configs(configRoot);\n\n // Even though the awsS3 integration allows a config array\n // there is no *real* support for multiple configs.\n // Usually, there will be just the integration for the default host.\n // In case, a config custom endpoint is used, the host from this endpoint\n // will be extracted and used as host (e.g., localhost when used with LocalStack)\n // and the default integration will be added as second integration.\n // In this case, we still want the first one though, but have no means to select it\n // just from the bucket name (and region).\n const integration = ScmIntegrations.fromConfig(configRoot).awsS3.list()[0];\n if (!integration) {\n throw new Error('No integration found for awsS3');\n }\n\n return providerConfigs.map(\n providerConfig =>\n new AwsS3EntityProvider(\n providerConfig,\n integration,\n options.logger,\n options.schedule,\n ),\n );\n }\n\n private constructor(\n private readonly config: AwsS3Config,\n private readonly integration: AwsS3Integration,\n logger: Logger,\n schedule: TaskRunner,\n ) {\n this.logger = logger.child({\n target: this.getProviderName(),\n });\n\n this.s3 = new S3({\n apiVersion: '2006-03-01',\n credentials: AwsCredentials.create(\n integration.config,\n 'backstage-aws-s3-provider',\n ),\n endpoint: integration.config.endpoint,\n region: this.config.region,\n s3ForcePathStyle: integration.config.s3ForcePathStyle,\n });\n\n this.scheduleFn = this.createScheduleFn(schedule);\n }\n\n private createScheduleFn(schedule: TaskRunner): () => Promise<void> {\n return async () => {\n const taskId = `${this.getProviderName()}:refresh`;\n return schedule.run({\n id: taskId,\n fn: async () => {\n const logger = this.logger.child({\n class: AwsS3EntityProvider.prototype.constructor.name,\n taskId,\n taskInstanceId: uuid.v4(),\n });\n\n try {\n await this.refresh(logger);\n } catch (error) {\n logger.error(error);\n }\n },\n });\n };\n }\n\n /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */\n getProviderName(): string {\n return `awsS3-provider:${this.config.id}`;\n }\n\n /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n async refresh(logger: Logger) {\n if (!this.connection) {\n throw new Error('Not initialized');\n }\n\n logger.info('Discovering AWS S3 objects');\n\n const keys = await this.listAllObjectKeys();\n logger.info(`Discovered ${keys.length} AWS S3 objects`);\n\n const locations = keys.map(key => this.createLocationSpec(key));\n\n await this.connection.applyMutation({\n type: 'full',\n entities: locations.map(location => {\n return {\n locationKey: this.getProviderName(),\n entity: locationSpecToLocationEntity({ location }),\n };\n }),\n });\n\n logger.info(`Committed ${locations.length} Locations for AWS S3 objects`);\n }\n\n private async listAllObjectKeys(): Promise<string[]> {\n const keys: string[] = [];\n\n let continuationToken: string | undefined = undefined;\n let output: ListObjectsV2Output;\n do {\n const request = this.s3.listObjectsV2({\n Bucket: this.config.bucketName,\n ContinuationToken: continuationToken,\n Prefix: this.config.prefix,\n });\n\n output = await request.promise();\n if (output.Contents) {\n output.Contents.forEach(item => {\n if (item.Key && !item.Key.endsWith('/')) {\n keys.push(item.Key);\n }\n });\n }\n continuationToken = output.NextContinuationToken;\n } while (continuationToken);\n\n return keys;\n }\n\n private createLocationSpec(key: string): LocationSpec {\n return {\n type: 'url',\n target: this.createObjectUrl(key),\n presence: 'required',\n };\n }\n\n private createObjectUrl(key: string): string {\n const bucketName = this.config.bucketName;\n const endpoint = this.integration.config.endpoint;\n\n if (endpoint) {\n if (endpoint.startsWith(`https://${bucketName}.`)) {\n return `${endpoint}/${key}`;\n }\n\n return `${endpoint}/${bucketName}/${key}`;\n }\n\n return `https://${bucketName}.s3.${this.config.region}.amazonaws.com/${key}`;\n }\n}\n"],"names":["AWS","processingResult","isError","limiterFactory","Credentials","aws","S3","integration","ScmIntegrations","uuid","locationSpecToLocationEntity"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAAS,yBAAyB,CAAC,MAAM,EAAE;AAClD,EAAE,MAAM,cAAc,GAAG,MAAM,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;AAC9D,EAAE,MAAM,OAAO,GAAG,cAAc,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,cAAc,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;AAChG,EAAE,OAAO;AACT,IAAI,OAAO;AACX,GAAG,CAAC;AACJ;;ACCA,MAAM,uBAAuB,GAAG,WAAW,CAAC;AAC5C,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAC3C,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AACxD,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAC3C,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AACzD,MAAM,oCAAoC,CAAC;AAClD,EAAE,OAAO,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE;AACrC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,oCAAoC,CAAC,CAAC;AAC7E,IAAI,OAAO,IAAI,oCAAoC,CAAC;AACpD,MAAM,GAAG,OAAO;AAChB,MAAM,QAAQ,EAAE,CAAC,GAAG,yBAAyB,CAAC,CAAC,CAAC,GAAG,EAAE;AACrD,KAAK,CAAC,CAAC;AACP,GAAG;AACH,EAAE,OAAO,gBAAgB,CAAC,MAAM,EAAE;AAClC,IAAI,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AACnC,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,MAAM,OAAO,KAAK,CAAC,CAAC;AACpB,KA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AW;AACX,SAAS,CAAC,CAAC;AACX,OAAO;AACP,MAAM,iBAAiB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,KAAK,QAAQ,iBAAiB,EAAE;AAChC,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,kBAAkB,CAAC,GAAG,EAAE;AAC1B,IAAI,OAAO;AACX,MAAM,IAAI,EAAE,KAAK;AACjB,MAAM,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;AACvC,MAAM,QAAQ,EAAE,UAAU;AAC1B,KAAK,CAAC;AACN,GAAG;AACH,EAAE,eAAe,CAAC,GAAG,EAAE;AACvB,IAAI,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;AAC9C,IAAI,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;AACtD,IAAI,IAAI,QAAQ,EAAE;AAClB,MAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE;AACzD,QAAQ,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AACpC,OAAO;AACP,MAAM,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAChD,KAAK;AACL,IAAI,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,CAAC;AACjF,GAAG;AACH;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Config } from '@backstage/config';
2
- import { CatalogProcessor, LocationSpec, CatalogProcessorEmit, CatalogProcessorParser } from '@backstage/plugin-catalog-backend';
2
+ import { CatalogProcessor, LocationSpec, CatalogProcessorEmit, CatalogProcessorParser, EntityProvider, EntityProviderConnection } from '@backstage/plugin-catalog-backend';
3
3
  import { Logger } from 'winston';
4
4
  import { UrlReader } from '@backstage/backend-common';
5
+ import { TaskRunner } from '@backstage/backend-tasks';
5
6
 
6
7
  /**
7
8
  * A processor for ingesting AWS Accounts from AWS Organizations.
@@ -42,4 +43,34 @@ declare class AwsS3DiscoveryProcessor implements CatalogProcessor {
42
43
  private doRead;
43
44
  }
44
45
 
45
- export { AwsOrganizationCloudAccountProcessor, AwsS3DiscoveryProcessor };
46
+ /**
47
+ * Provider which discovers catalog files (any name) within an S3 bucket.
48
+ *
49
+ * Use `AwsS3EntityProvider.fromConfig(...)` to create instances.
50
+ *
51
+ * @public
52
+ */
53
+ declare class AwsS3EntityProvider implements EntityProvider {
54
+ private readonly config;
55
+ private readonly integration;
56
+ private readonly logger;
57
+ private readonly s3;
58
+ private readonly scheduleFn;
59
+ private connection?;
60
+ static fromConfig(configRoot: Config, options: {
61
+ logger: Logger;
62
+ schedule: TaskRunner;
63
+ }): AwsS3EntityProvider[];
64
+ private constructor();
65
+ private createScheduleFn;
66
+ /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
67
+ getProviderName(): string;
68
+ /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
69
+ connect(connection: EntityProviderConnection): Promise<void>;
70
+ refresh(logger: Logger): Promise<void>;
71
+ private listAllObjectKeys;
72
+ private createLocationSpec;
73
+ private createObjectUrl;
74
+ }
75
+
76
+ export { AwsOrganizationCloudAccountProcessor, AwsS3DiscoveryProcessor, AwsS3EntityProvider };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend-module-aws",
3
3
  "description": "A Backstage catalog backend module that helps integrate towards AWS",
4
- "version": "0.1.3",
4
+ "version": "0.1.4-next.2",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -33,19 +33,22 @@
33
33
  "start": "backstage-cli package start"
34
34
  },
35
35
  "dependencies": {
36
- "@backstage/backend-common": "^0.13.1",
37
- "@backstage/catalog-model": "^1.0.0",
36
+ "@backstage/backend-common": "^0.13.2-next.2",
37
+ "@backstage/backend-tasks": "^0.3.0-next.1",
38
+ "@backstage/catalog-model": "^1.0.1-next.0",
38
39
  "@backstage/config": "^1.0.0",
39
40
  "@backstage/errors": "^1.0.0",
40
- "@backstage/plugin-catalog-backend": "^1.0.0",
41
+ "@backstage/integration": "^1.1.0-next.2",
42
+ "@backstage/plugin-catalog-backend": "^1.1.0-next.3",
41
43
  "@backstage/types": "^1.0.0",
42
44
  "aws-sdk": "^2.840.0",
43
45
  "lodash": "^4.17.21",
44
46
  "p-limit": "^3.0.2",
47
+ "uuid": "^8.0.0",
45
48
  "winston": "^3.2.1"
46
49
  },
47
50
  "devDependencies": {
48
- "@backstage/cli": "^0.16.0",
51
+ "@backstage/cli": "^0.17.0-next.3",
49
52
  "@types/lodash": "^4.14.151",
50
53
  "aws-sdk-mock": "^5.2.1",
51
54
  "yaml": "^1.9.2"
@@ -55,5 +58,5 @@
55
58
  "config.d.ts"
56
59
  ],
57
60
  "configSchema": "config.d.ts",
58
- "gitHead": "e9496f746b31600dbfac7fa76987479e66426257"
61
+ "gitHead": "2eca57d93ef1081f4a76a19fc994a8e9e1a19e00"
59
62
  }