@firestartr/cli 1.39.0-SNAPSHOT → 1.39.0

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/build/index.js CHANGED
@@ -276807,8 +276807,12 @@ const validate = uuid_dist/* validate */.Gu;
276807
276807
  const stringify = uuid_dist/* stringify */.Pz;
276808
276808
  const parse = uuid_dist/* parse */.Qc;
276809
276809
 
276810
+ // EXTERNAL MODULE: external "crypto"
276811
+ var external_crypto_ = __nccwpck_require__(6113);
276812
+ var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto_);
276810
276813
  ;// CONCATENATED MODULE: ../catalog_common/src/generic/nomicon.ts
276811
276814
 
276815
+
276812
276816
  const UUID_ANNOTATION = 'fire-starter.dev/uuid';
276813
276817
  /*
276814
276818
  *
@@ -276836,6 +276840,12 @@ function calculateStoregeKey(artifact, storageType) {
276836
276840
  return `${artifact['kind'].toLowerCase()}-${helperlGetArtifactUUID(artifact)}`;
276837
276841
  }
276838
276842
  }
276843
+ /*
276844
+ * String to md5
276845
+ */
276846
+ function toMd5(text) {
276847
+ return external_crypto_default().createHash('md5').update(text).digest('hex');
276848
+ }
276839
276849
 
276840
276850
  // EXTERNAL MODULE: external "stream"
276841
276851
  var external_stream_ = __nccwpck_require__(12781);
@@ -277829,6 +277839,7 @@ function removeRepeatedObjectsFromArrayByProp(array, propiedad) {
277829
277839
  getFirestartrLabel: getFirestartrLabel,
277830
277840
  normalizeLabel: normalizeLabel,
277831
277841
  removeRepeatedObjectsFromArrayByProp: removeRepeatedObjectsFromArrayByProp,
277842
+ toMd5: toMd5,
277832
277843
  });
277833
277844
 
277834
277845
  ;// CONCATENATED MODULE: ../catalog_common/src/types/envvars.ts
@@ -286971,7 +286982,7 @@ async function replaceReferencesValues(contents, references, resolveRef) {
286971
286982
  class RevisionNormalizer extends Normalizer {
286972
286983
  constructor() {
286973
286984
  super(...arguments);
286974
- this.applicableProviders = ['all'];
286985
+ this.applicableProviders = ['terraform', 'github'];
286975
286986
  }
286976
286987
  async __validate(_schema) {
286977
286988
  return true;
@@ -287004,11 +287015,6 @@ class RevisionNormalizer extends Normalizer {
287004
287015
  identify() {
287005
287016
  return 'normalizer/revision';
287006
287017
  },
287007
- applicable() {
287008
- return {
287009
- applicableProviders: ['terraform'],
287010
- };
287011
- },
287012
287018
  },
287013
287019
  ];
287014
287020
  }
@@ -291497,11 +291503,10 @@ class FeatureRepoChart extends BaseGithubChart {
291497
291503
  template() {
291498
291504
  const claim = this.get('claim');
291499
291505
  const repositoryTarget = this.resolveRepositoryTarget();
291500
- return {
291506
+ const cr = {
291501
291507
  metadata: {
291502
291508
  name: claim.name,
291503
291509
  annotations: {
291504
- 'firestartr.dev/claim-ref': `${this.get('repoCr').metadata.annotations['firestartr.dev/claim-ref']}`,
291505
291510
  'firestartr.dev/external-name': claim.name,
291506
291511
  'firestartr.dev/feature-name': claim.feature.name,
291507
291512
  },
@@ -291518,10 +291523,31 @@ class FeatureRepoChart extends BaseGithubChart {
291518
291523
  },
291519
291524
  },
291520
291525
  };
291526
+ const annotations = this.getAnnotationsFromRepo(this.get('repoCr'), [
291527
+ 'claim-ref',
291528
+ 'revision',
291529
+ 'sync-enabled',
291530
+ 'sync-period',
291531
+ ]);
291532
+ cr.metadata.annotations = {
291533
+ ...cr.metadata.annotations,
291534
+ ...annotations,
291535
+ };
291536
+ return cr;
291521
291537
  }
291522
291538
  gvk() {
291523
291539
  return FirestartrGithubRepositoryFeature.GVK;
291524
291540
  }
291541
+ getAnnotationsFromRepo(repoCr, inheritedAnnotations) {
291542
+ const annotations = {};
291543
+ for (const annotation of inheritedAnnotations) {
291544
+ const fsAnnotation = `firestartr.dev/${annotation}`;
291545
+ if (fsAnnotation in repoCr.metadata.annotations) {
291546
+ annotations[fsAnnotation] = repoCr.metadata.annotations[fsAnnotation];
291547
+ }
291548
+ }
291549
+ return annotations;
291550
+ }
291525
291551
  resolveRepositoryTarget() {
291526
291552
  const repositoryTarget = {
291527
291553
  ref: {
@@ -292749,7 +292775,8 @@ function compareCRs(crV1, crV2) {
292749
292775
  */
292750
292776
  (op) => op.path !== '/spec/firestartr/tfStateKey' &&
292751
292777
  op.path !== '/metadata/name' &&
292752
- op.path !== '/spec/writeConnectionSecretToRef/name');
292778
+ op.path !== '/spec/writeConnectionSecretToRef/name' &&
292779
+ op.path !== '/metadata/annotations/firestartr.dev~1revision');
292753
292780
  return {
292754
292781
  changed: compareResult.length !== 0,
292755
292782
  changes: compareResult,
@@ -296746,6 +296773,9 @@ class GithubStack extends BaseStack {
296746
296773
  async provisionEntity(isImport, entity, deps, tfStatePath, orgConfig) {
296747
296774
  try {
296748
296775
  const { backendConfig, providerConfig } = this.getRefContextConfigs(entity, deps);
296776
+ if (backendConfig.spec.type === 'kubernetes') {
296777
+ tfStatePath = catalog_common.generic.toMd5(tfStatePath);
296778
+ }
296749
296779
  this.initProviders(this, tfStatePath, backendConfig, providerConfig, deps);
296750
296780
  const instance = getEntityInstance(entity, deps);
296751
296781
  await instance.provision({ scope: this });
@@ -301102,8 +301132,8 @@ class Analyzer {
301102
301132
  }
301103
301133
  }
301104
301134
 
301105
- ;// CONCATENATED MODULE: ../crs_analyzer/src/models/workspace.ts
301106
- class Workspace {
301135
+ ;// CONCATENATED MODULE: ../crs_analyzer/src/models/cr.ts
301136
+ class Cr {
301107
301137
  constructor(kind, metadata, conditions) {
301108
301138
  this.kind = kind;
301109
301139
  this.metadata = metadata;
@@ -301133,23 +301163,23 @@ class Workspace {
301133
301163
  }
301134
301164
  }
301135
301165
 
301136
- ;// CONCATENATED MODULE: ../crs_analyzer/src/analyzers/workspaces.ts
301166
+ ;// CONCATENATED MODULE: ../crs_analyzer/src/analyzers/crs-analyzer.ts
301137
301167
 
301138
301168
 
301139
- class WorkspacesAnalyzer extends Analyzer {
301169
+ class CrsAnalyzer extends Analyzer {
301140
301170
  constructor(context, cli) {
301141
301171
  super(context, cli);
301142
301172
  this.drifted = [];
301143
301173
  this.failed = [];
301144
301174
  }
301145
301175
  async analyze() {
301146
- const workspaces = await this.listWorkspaces();
301147
- this.drifted = this.filterByDrifted(workspaces);
301148
- this.failed = this.filterByFailed(workspaces);
301176
+ const crs = await this.listCrs();
301177
+ this.drifted = this.filterByDrifted(crs);
301178
+ this.failed = this.filterByFailed(crs);
301149
301179
  }
301150
- async listWorkspaces() {
301180
+ async listCrs() {
301151
301181
  const list = await this.cli.listKind(this.ctx.apiGroup, this.ctx.apiVersion, this.ctx.namespace, this.ctx.plural);
301152
- return list.map((item) => new Workspace(item.kind, item.metadata, item.status.conditions));
301182
+ return list.map((item) => new Cr(item.kind, item.metadata, item.status.conditions));
301153
301183
  }
301154
301184
  filterByFailed(workspaces) {
301155
301185
  return workspaces.filter((ws) => ws.hasError());
@@ -301224,10 +301254,10 @@ function sanitize(str) {
301224
301254
  return str;
301225
301255
  }
301226
301256
 
301227
- ;// CONCATENATED MODULE: ../crs_analyzer/src/publishers/workspaces.ts
301257
+ ;// CONCATENATED MODULE: ../crs_analyzer/src/publishers/crs.ts
301228
301258
 
301229
301259
 
301230
- class WorkspacesPublisher extends Publisher {
301260
+ class CrsPublisher extends Publisher {
301231
301261
  constructor(analyzer, githubCli, context) {
301232
301262
  super();
301233
301263
  this.output = '';
@@ -301251,35 +301281,35 @@ class WorkspacesPublisher extends Publisher {
301251
301281
  for (const issue of errorIssues || []) {
301252
301282
  if (!this.analyzer.failed.find((wp) => issue.title.includes(wp.claimName) && issue.title.includes('error'))) {
301253
301283
  await this.githubCli.closeIssue(this.context.githubOwner, this.context.githubRepo, issue.number);
301254
- this.writeLnOutput(`✅ No errors detected for TFWorkspace on issue ${issue.title}. Issue has been closed.`);
301284
+ this.writeLnOutput(`✅ No errors detected on issue ${issue.title}. Issue has been closed.`);
301255
301285
  }
301256
301286
  }
301257
301287
  }
301258
301288
  async closeOldDriftIssues(driftIssues) {
301259
301289
  for (const issue of driftIssues || []) {
301260
- if (!this.analyzer.drifted.find((wp) => issue.title.includes(wp.claimName) && issue.title.includes('drift'))) {
301290
+ if (!this.analyzer.drifted.find((cr) => issue.title.includes(cr.claimName) && issue.title.includes('drift'))) {
301261
301291
  await this.githubCli.closeIssue(this.context.githubOwner, this.context.githubRepo, issue.number);
301262
- this.writeLnOutput(`✅ No drift detected for TFWorkspace on issue ${issue.title}. Issue has been closed.`);
301292
+ this.writeLnOutput(`✅ No drift detected on issue ${issue.title}. Issue has been closed.`);
301263
301293
  }
301264
301294
  }
301265
301295
  }
301266
- async publishError(wp) {
301267
- const body = this.buildErrorsBody(wp);
301268
- const resp = await this.githubCli.upsertIssue(this.context.githubOwner, this.context.githubRepo, `Claim '${wp.claimName}' has an error`, body, [wp.claimKind, 'error']);
301269
- this.writeLnOutput(`❌ Error detected for TFWorkspace: ${wp.claimName}. Issue has been created or updated: ${resp.data.html_url}`);
301296
+ async publishError(cr) {
301297
+ const body = this.buildErrorsBody(cr);
301298
+ const resp = await this.githubCli.upsertIssue(this.context.githubOwner, this.context.githubRepo, `Claim '${cr.claimName}' has an error`, body, [cr.claimKind, 'error']);
301299
+ this.writeLnOutput(`❌ Error detected for ${cr.claimKind}: ${cr.claimName}. Issue has been created or updated: ${resp.data.html_url}`);
301270
301300
  return resp;
301271
301301
  }
301272
- async publishDrift(wp) {
301273
- const body = this.buildDriftBody(wp);
301274
- const resp = await this.githubCli.upsertIssue(this.context.githubOwner, this.context.githubRepo, `Claim '${wp.claimName}' has a drift`, body, [wp.claimKind, 'drift']);
301275
- this.writeLnOutput(`⚠️ Drift detected for TFWorkspace: ${wp.claimName}. Issue has been created or updated: ${resp.data.html_url}`);
301302
+ async publishDrift(cr) {
301303
+ const body = this.buildDriftBody(cr);
301304
+ const resp = await this.githubCli.upsertIssue(this.context.githubOwner, this.context.githubRepo, `Claim '${cr.claimName}' has a drift`, body, [cr.claimKind, 'drift']);
301305
+ this.writeLnOutput(`⚠️ Drift detected for ${cr.claimKind}: ${cr.claimName}. Issue has been created or updated: ${resp.data.html_url}`);
301276
301306
  return resp;
301277
301307
  }
301278
- buildErrorsBody(wp) {
301308
+ buildErrorsBody(cr) {
301279
301309
  return `
301280
- The claim '${wp.claimName}' with kind: ${wp.claimKind} has an error.
301310
+ The claim '${cr.claimName}' with kind: ${cr.claimKind} has an error.
301281
301311
 
301282
- ${this.buildErrorForWs(wp)}
301312
+ ${this.buildErrorForWs(cr)}
301283
301313
  `;
301284
301314
  }
301285
301315
  buildErrorForWs(ws) {
@@ -301331,19 +301361,11 @@ class GithubClient {
301331
301361
 
301332
301362
 
301333
301363
 
301334
- async function runCrsAnalyzer(analyzerType, namespace, org, repo) {
301335
- switch (analyzerType) {
301336
- case 'tfworkspaces':
301337
- await tfWorkspacesAnalyze(namespace, org, repo);
301338
- break;
301339
- default:
301340
- }
301341
- }
301342
- async function tfWorkspacesAnalyze(namespace, org, repo) {
301343
- const context = new context_Context('firestartr.dev', 'v1', 'terraformworkspaces', namespace, org, repo);
301344
- const analyzer = new WorkspacesAnalyzer(context, new KubernetesClient());
301364
+ async function runCrsAnalyzer(plural, namespace, org, repo) {
301365
+ const context = new context_Context('firestartr.dev', 'v1', plural, namespace, org, repo);
301366
+ const analyzer = new CrsAnalyzer(context, new KubernetesClient());
301345
301367
  await analyzer.analyze();
301346
- const publisher = new WorkspacesPublisher(analyzer, new GithubClient(), context);
301368
+ const publisher = new CrsPublisher(analyzer, new GithubClient(), context);
301347
301369
  await publisher.publish();
301348
301370
  if (publisher.output !== '') {
301349
301371
  console.log(publisher.output);
@@ -38,6 +38,7 @@ declare const _default: {
38
38
  getFirestartrLabel: typeof import("./src/generic/labels").getFirestartrLabel;
39
39
  normalizeLabel: typeof import("./src/generic/labels").normalizeLabel;
40
40
  removeRepeatedObjectsFromArrayByProp: typeof import("./src/generic/arrays").removeRepeatedObjectsFromArrayByProp;
41
+ toMd5: typeof import("./src/generic/nomicon").toMd5;
41
42
  };
42
43
  types: {
43
44
  ArtifactStatuses: typeof import("./src/types/catalog").ArtifactStatuses;
@@ -1,5 +1,5 @@
1
1
  import { randomString, shuffleArray, shuffleObject } from './random';
2
- import { annotateWithUUID, calculateStoregeKey } from './nomicon';
2
+ import { annotateWithUUID, calculateStoregeKey, toMd5 } from './nomicon';
3
3
  import CsvWriter from './csv_generator';
4
4
  import { getLogger } from './logger';
5
5
  import { sleep } from './time';
@@ -24,5 +24,6 @@ declare const _default: {
24
24
  getFirestartrLabel: typeof getFirestartrLabel;
25
25
  normalizeLabel: typeof normalizeLabel;
26
26
  removeRepeatedObjectsFromArrayByProp: typeof removeRepeatedObjectsFromArrayByProp;
27
+ toMd5: typeof toMd5;
27
28
  };
28
29
  export default _default;
@@ -4,3 +4,4 @@ export interface Artifact {
4
4
  export declare function annotateWithUUID(artifact: Artifact): Artifact;
5
5
  export declare function helperlGetArtifactUUID(artifact: Artifact): string;
6
6
  export declare function calculateStoregeKey(artifact: Artifact, storageType: string): string;
7
+ export declare function toMd5(text: string): string;
@@ -5,6 +5,7 @@ export declare class FeatureRepoChart extends BaseGithubChart {
5
5
  constructor(scope: any, chartId: string, firestartrId: string | null, claim: any, patches?: any[], cr?: any);
6
6
  template(): FirestartrGithubRepositoryFeatureProps;
7
7
  gvk(): GroupVersionKind;
8
+ private getAnnotationsFromRepo;
8
9
  private resolveRepositoryTarget;
9
10
  instanceApiObject(template: any): FirestartrGithubRepositoryFeature;
10
11
  }
@@ -1,4 +1,4 @@
1
- declare function runCrsAnalyzer(analyzerType: string, namespace: string, org: string, repo: string): Promise<void>;
1
+ declare function runCrsAnalyzer(plural: string, namespace: string, org: string, repo: string): Promise<void>;
2
2
  declare const _default: {
3
3
  runCrsAnalyzer: typeof runCrsAnalyzer;
4
4
  };
@@ -0,0 +1,13 @@
1
+ import { Context } from '../context';
2
+ import { Analyzer } from './base';
3
+ import { Cr } from '../models/cr';
4
+ import { KubernetesClient } from '../kubernetes-client';
5
+ export declare class CrsAnalyzer extends Analyzer {
6
+ drifted: Cr[];
7
+ failed: Cr[];
8
+ constructor(context: Context, cli: KubernetesClient);
9
+ analyze(): Promise<void>;
10
+ listCrs(): Promise<Cr[]>;
11
+ filterByFailed(workspaces: Cr[]): Cr[];
12
+ filterByDrifted(workspaces: Cr[]): Cr[];
13
+ }
@@ -1,4 +1,4 @@
1
- export declare class Workspace {
1
+ export declare class Cr {
2
2
  kind: string;
3
3
  metadata: {
4
4
  name: string;
@@ -0,0 +1,23 @@
1
+ import { CrsAnalyzer } from '../analyzers/crs-analyzer';
2
+ import { Context } from '../context';
3
+ import { GithubClient } from '../github-client';
4
+ import { Cr } from '../models/cr';
5
+ import { Publisher } from './base';
6
+ export declare class CrsPublisher extends Publisher {
7
+ githubCli: GithubClient;
8
+ analyzer: CrsAnalyzer;
9
+ context: Context;
10
+ output: string;
11
+ constructor(analyzer: CrsAnalyzer, githubCli: GithubClient, context: Context);
12
+ publish(): Promise<void>;
13
+ closeOldErrorIssues(errorIssues: any): Promise<void>;
14
+ closeOldDriftIssues(driftIssues: any): Promise<void>;
15
+ publishError(cr: Cr): Promise<any>;
16
+ publishDrift(cr: Cr): Promise<any>;
17
+ buildErrorsBody(cr: Cr): string;
18
+ buildErrorForWs(ws: Cr): string;
19
+ buildDriftBody(wp: Cr): string;
20
+ buildDriftForWs(ws: Cr): string;
21
+ writeLnOutput(line: string): void;
22
+ filterIssuesBy(type: 'error' | 'drift'): Promise<any>;
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firestartr/cli",
3
- "version": "1.39.0-SNAPSHOT",
3
+ "version": "1.39.0",
4
4
  "private": false,
5
5
  "description": "Commandline tool",
6
6
  "main": "build/main.js",
@@ -1,13 +0,0 @@
1
- import { Context } from '../context';
2
- import { Analyzer } from './base';
3
- import { Workspace } from '../models/workspace';
4
- import { KubernetesClient } from '../kubernetes-client';
5
- export declare class WorkspacesAnalyzer extends Analyzer {
6
- drifted: Workspace[];
7
- failed: Workspace[];
8
- constructor(context: Context, cli: KubernetesClient);
9
- analyze(): Promise<void>;
10
- listWorkspaces(): Promise<Workspace[]>;
11
- filterByFailed(workspaces: Workspace[]): Workspace[];
12
- filterByDrifted(workspaces: Workspace[]): Workspace[];
13
- }
@@ -1,23 +0,0 @@
1
- import { WorkspacesAnalyzer } from '../analyzers/workspaces';
2
- import { Context } from '../context';
3
- import { GithubClient } from '../github-client';
4
- import { Workspace } from '../models/workspace';
5
- import { Publisher } from './base';
6
- export declare class WorkspacesPublisher extends Publisher {
7
- githubCli: GithubClient;
8
- analyzer: WorkspacesAnalyzer;
9
- context: Context;
10
- output: string;
11
- constructor(analyzer: WorkspacesAnalyzer, githubCli: GithubClient, context: Context);
12
- publish(): Promise<void>;
13
- closeOldErrorIssues(errorIssues: any): Promise<void>;
14
- closeOldDriftIssues(driftIssues: any): Promise<void>;
15
- publishError(wp: Workspace): Promise<any>;
16
- publishDrift(wp: Workspace): Promise<any>;
17
- buildErrorsBody(wp: Workspace): string;
18
- buildErrorForWs(ws: Workspace): string;
19
- buildDriftBody(wp: Workspace): string;
20
- buildDriftForWs(ws: Workspace): string;
21
- writeLnOutput(line: string): void;
22
- filterIssuesBy(type: 'error' | 'drift'): Promise<any>;
23
- }