Skip to content

Commit 38b2683

Browse files
committed
Removes unnecessary and adds missing awaits
1 parent d78ea2f commit 38b2683

20 files changed

+236
-229
lines changed

src/apis/ci/jenkins.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,19 @@ export class JenkinsCI extends Utils {
306306
}
307307
}
308308

309+
//Parse SBOM version from build log
310+
public parseSbomVersionFromConsoleLog(log: string): string {
311+
const filter = log.split("Uploading SBOM file for").pop()?.split("vnd.cyclonedx+json").shift()?.trim();
312+
if (filter != undefined) {
313+
return filter.substring(
314+
filter.indexOf("sha256-") + 7,
315+
filter.lastIndexOf(".sbom")
316+
);
317+
} else {
318+
return "";
319+
}
320+
}
321+
309322
public async deleteJenkinsJobInFolder(jobName: string, folderName: string) {
310323
const url = `${this.jenkinsUrl}/job/${folderName}/job/${jobName}/doDelete`;
311324

@@ -350,7 +363,7 @@ export class JenkinsCI extends Utils {
350363
}
351364

352365

353-
public async getJenkinsURL() {
366+
public getJenkinsURL(): string {
354367
return this.jenkinsUrl;
355368
}
356369
}

src/apis/kubernetes/kube.ts

+33-31
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PromiseMiddlewareWrapper } from '@kubernetes/client-node/dist/gen/middl
99
/**
1010
* Constants for interacting with Kubernetes/OpenShift clusters.
1111
*/
12-
const RHTAPGitopsNamespace = process.env.RHTAP_GITOPS_NAMESPACE ??'rhtap-gitops';
12+
const RHTAPGitopsNamespace = process.env.RHTAP_GITOPS_NAMESPACE ?? 'rhtap-gitops';
1313

1414
/**
1515
* Kubernetes class for interacting with Kubernetes/OpenShift clusters.
@@ -36,7 +36,7 @@ export class Kubernetes extends Utils {
3636
public async namespaceExists(name: string): Promise<boolean> {
3737
const k8sCoreApi = this.kubeConfig.makeApiClient(CoreV1Api);
3838
try {
39-
const response = await k8sCoreApi.readNamespace({ name: name});
39+
const response = await k8sCoreApi.readNamespace({ name: name });
4040
if (response?.metadata?.name === name) {
4141
return true;
4242
}
@@ -57,7 +57,7 @@ export class Kubernetes extends Utils {
5757
public async getTaskRunsFromPipelineRun(pipelineRunName: string): Promise<TaskRunKind[]> {
5858
const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi);
5959
try {
60-
const taskRunList = await customObjectsApi.listClusterCustomObject({group: 'tekton.dev', version: 'v1', plural: 'taskruns'});
60+
const taskRunList = await customObjectsApi.listClusterCustomObject({ group: 'tekton.dev', version: 'v1', plural: 'taskruns' });
6161
const taskRunInterface = taskRunList as TaskRunList;
6262
return taskRunInterface.items.filter(taskRun => taskRun?.metadata?.ownerReferences?.[0].name === pipelineRunName);
6363

@@ -76,7 +76,7 @@ export class Kubernetes extends Utils {
7676
public async getOpenshiftRoute(name: string, namespace: string): Promise<string> {
7777
const customObjectsApi = this.kubeConfig.makeApiClient(CustomObjectsApi);
7878
try {
79-
const route = await customObjectsApi.getNamespacedCustomObject({group: 'route.openshift.io', version: 'v1', plural: 'routes', name: name, namespace: namespace});
79+
const route = await customObjectsApi.getNamespacedCustomObject({ group: 'route.openshift.io', version: 'v1', plural: 'routes', name: name, namespace: namespace });
8080
return route.spec.host;
8181
} catch (error) {
8282
console.error(error);
@@ -95,19 +95,19 @@ export class Kubernetes extends Utils {
9595
const k8sApi = this.kubeConfig.makeApiClient(CoreV1Api);
9696
try {
9797
// Get the pod object
98-
const pod = await k8sApi.readNamespacedPod({name: podName, namespace: namespace});
98+
const pod = await k8sApi.readNamespacedPod({ name: podName, namespace: namespace });
9999

100100
// Check if pod.spec is defined
101101
if (pod.spec?.containers) {
102102
// Iterate over each container in the pod
103103
for (const container of pod.spec.containers) {
104104
// Get logs from each container
105-
const response = await k8sApi.readNamespacedPodLog({name: podName, namespace: namespace, container: container.name});
105+
const response = await k8sApi.readNamespacedPodLog({ name: podName, namespace: namespace, container: container.name });
106106

107107
// Append container name before the logs
108108
const logsWithContainerInfo = `Container: ${container.name}\n${response}\n\n`;
109109
const logFilePath = path.join('taskruns-logs', podName);
110-
await this.writeLogsToArtifactDir(logFilePath, `${container.name}.log`, logsWithContainerInfo);
110+
this.writeLogsToArtifactDir(logFilePath, `${container.name}.log`, logsWithContainerInfo);
111111
}
112112

113113
} else {
@@ -130,7 +130,7 @@ export class Kubernetes extends Utils {
130130
const k8sApi = this.kubeConfig.makeApiClient(CoreV1Api);
131131
try {
132132
// Get logs from the given container
133-
const response = await k8sApi.readNamespacedPodLog({name: podName, namespace: namespace, container: containerName});
133+
const response = await k8sApi.readNamespacedPodLog({ name: podName, namespace: namespace, container: containerName });
134134
return (response);
135135
} catch (err) {
136136
console.error('Error:', err);
@@ -151,8 +151,10 @@ export class Kubernetes extends Utils {
151151

152152
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
153153
try {
154-
const body = await customObjectsApi.listClusterCustomObject({group: 'tekton.dev', version:'v1', plural: 'pipelineruns',
155-
labelSelector: `pipelinesascode.tekton.dev/url-repository=${gitRepository}`});
154+
const body = await customObjectsApi.listClusterCustomObject({
155+
group: 'tekton.dev', version: 'v1', plural: 'pipelineruns',
156+
labelSelector: `pipelinesascode.tekton.dev/url-repository=${gitRepository}`
157+
});
156158
const pr = body as PipelineRunList;
157159

158160
const filteredPipelineRuns = pr.items.filter((pipelineRun: PipelineRunKind) => {
@@ -203,7 +205,7 @@ export class Kubernetes extends Utils {
203205

204206
while (timeoutMs === 0 || totalTimeMs < timeoutMs) {
205207
try {
206-
const body = await customObjectsApi.getNamespacedCustomObject({group: 'tekton.dev', version: 'v1', namespace: namespace, plural: 'pipelineruns', name: name});
208+
const body = await customObjectsApi.getNamespacedCustomObject({ group: 'tekton.dev', version: 'v1', namespace: namespace, plural: 'pipelineruns', name: name });
207209
const pr = body as PipelineRunKind;
208210

209211
if (pr.status?.conditions) {
@@ -272,7 +274,7 @@ export class Kubernetes extends Utils {
272274

273275
while (timeoutMs === 0 || totalTimeMs < timeoutMs) {
274276
try {
275-
const body = await customObjectsApi.getNamespacedCustomObject({group: 'argoproj.io', version: 'v1alpha1', namespace: RHTAPGitopsNamespace, plural: 'applications', name: name});
277+
const body = await customObjectsApi.getNamespacedCustomObject({ group: 'argoproj.io', version: 'v1alpha1', namespace: RHTAPGitopsNamespace, plural: 'applications', name: name });
276278
const application = body as ApplicationSpec;
277279

278280
if (application.status?.sync?.status &&
@@ -320,9 +322,9 @@ export class Kubernetes extends Utils {
320322
const headerPatchMiddleware = new PromiseMiddlewareWrapper({
321323
pre: async (requestContext: RequestContext) => {
322324
requestContext.setHeaderParam('Content-Type', 'application/merge-patch+json');
323-
return requestContext;
325+
return await Promise.resolve(requestContext);
324326
},
325-
post: async (responseContext: ResponseContext) => responseContext,
327+
post: async (responseContext: ResponseContext) => await Promise.resolve(responseContext),
326328
});
327329
const currentContext = this.kubeConfig.getCurrentContext();
328330
const currentCluster = this.kubeConfig.getCluster(currentContext);
@@ -344,11 +346,11 @@ export class Kubernetes extends Utils {
344346
});
345347

346348
// Patch the app
347-
await k8sCoreApi.patchNamespacedCustomObject({group: 'argoproj.io', version: 'v1alpha1', namespace: namespace, plural: 'applications', name: applicationName, body: patchObject}, configuration);
349+
await k8sCoreApi.patchNamespacedCustomObject({ group: 'argoproj.io', version: 'v1alpha1', namespace: namespace, plural: 'applications', name: applicationName, body: patchObject }, configuration);
348350

349351

350352
// Delete the app
351-
await k8sCoreApi.deleteNamespacedCustomObject({group: 'argoproj.io', version: 'v1alpha1', namespace: namespace, plural: 'applications', name: applicationName});
353+
await k8sCoreApi.deleteNamespacedCustomObject({ group: 'argoproj.io', version: 'v1alpha1', namespace: namespace, plural: 'applications', name: applicationName });
352354

353355
console.log(`App ${applicationName} patched and deleted successfully.`);
354356
} catch (error) {
@@ -369,7 +371,7 @@ export class Kubernetes extends Utils {
369371
const k8sApi = this.kubeConfig.makeApiClient(CoreV1Api);
370372
try {
371373
// Fetch the secret from the specified namespace
372-
const secret = await k8sApi.readNamespacedSecret({name: secretName, namespace: namespace});
374+
const secret = await k8sApi.readNamespacedSecret({ name: secretName, namespace: namespace });
373375

374376
// Check if the key exists in the secret data
375377
if (secret.data && secret.data[keyName]) {
@@ -392,7 +394,7 @@ export class Kubernetes extends Utils {
392394
const k8sApi = this.kubeConfig.makeApiClient(CoreV1Api);
393395

394396
// List all secrets
395-
const secretList = await k8sApi.listNamespacedSecret({namespace: namespace});
397+
const secretList = await k8sApi.listNamespacedSecret({ namespace: namespace });
396398

397399
// Filter secrets
398400
const matchingSecrets = secretList.items.filter(secret => secret.metadata?.name?.startsWith(partialSecretName));
@@ -461,21 +463,21 @@ export class Kubernetes extends Utils {
461463
* Gets cosign public key.
462464
*/
463465
public async getCosignPublicKey(): Promise<string> {
464-
return this.getSecretPartialName("openshift-pipelines", "signing-secrets", "cosign.pub", false);
466+
return await this.getSecretPartialName("openshift-pipelines", "signing-secrets", "cosign.pub", false);
465467
}
466468

467469
/**
468470
* Gets cosign private key.
469471
*/
470472
public async getCosignPrivateKey(): Promise<string> {
471-
return this.getSecretPartialName("openshift-pipelines", "signing-secrets", "cosign.key", false);
473+
return await this.getSecretPartialName("openshift-pipelines", "signing-secrets", "cosign.key", false);
472474
}
473475

474476
/**
475477
* Gets cosign password.
476478
*/
477479
public async getCosignPassword(): Promise<string> {
478-
return this.getSecretPartialName("openshift-pipelines", "signing-secrets", "cosign.password", false);
480+
return await this.getSecretPartialName("openshift-pipelines", "signing-secrets", "cosign.password", false);
479481
}
480482

481483
/**
@@ -485,7 +487,7 @@ export class Kubernetes extends Utils {
485487
* @returns {Promise<string>} - returns route URL.
486488
*/
487489
public async getACSEndpoint(namespace: string): Promise<string> {
488-
return this.getDeveloperHubSecret(namespace, "rhtap-acs-integration", "endpoint");
490+
return await this.getDeveloperHubSecret(namespace, "rhtap-acs-integration", "endpoint");
489491
}
490492

491493
/**
@@ -495,7 +497,7 @@ export class Kubernetes extends Utils {
495497
* @returns {Promise<string>} - returns token.
496498
*/
497499
public async getACSToken(namespace: string): Promise<string> {
498-
return this.getDeveloperHubSecret(namespace, "rhtap-acs-integration", "token");
500+
return await this.getDeveloperHubSecret(namespace, "rhtap-acs-integration", "token");
499501
}
500502

501503
/**
@@ -505,7 +507,7 @@ export class Kubernetes extends Utils {
505507
* @returns {Promise<string>} - returns route URL.
506508
*/
507509
public async getRekorServerUrl(namespace: string): Promise<string> {
508-
return this.getDeveloperHubSecret(namespace, "rhtap-tas-integration", "rekor_url");
510+
return await this.getDeveloperHubSecret(namespace, "rhtap-tas-integration", "rekor_url");
509511
}
510512

511513
/**
@@ -515,7 +517,7 @@ export class Kubernetes extends Utils {
515517
* @returns {Promise<string>} - returns route URL.
516518
*/
517519
public async getTUFUrl(namespace: string): Promise<string> {
518-
return this.getDeveloperHubSecret(namespace, "rhtap-tas-integration", "tuf_url");
520+
return await this.getDeveloperHubSecret(namespace, "rhtap-tas-integration", "tuf_url");
519521
}
520522

521523
/**
@@ -527,7 +529,7 @@ export class Kubernetes extends Utils {
527529
public async getPodYaml(PodName: string, nameSpace: string): Promise<string | null> {
528530
const k8sCoreApi = this.kubeConfig.makeApiClient(CoreV1Api);
529531
try {
530-
const response = await k8sCoreApi.readNamespacedPod({name: PodName, namespace: nameSpace});
532+
const response = await k8sCoreApi.readNamespacedPod({ name: PodName, namespace: nameSpace });
531533
const podYaml = dumpYaml(response);
532534
return podYaml;
533535
}
@@ -544,7 +546,7 @@ export class Kubernetes extends Utils {
544546
* @returns {Promise<string>} - returns route URL.
545547
*/
546548
public async getTTrustificationBombasticApiUrl(namespace: string): Promise<string> {
547-
return this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "bombastic_api_url");
549+
return await this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "bombastic_api_url");
548550
}
549551

550552
/**
@@ -554,7 +556,7 @@ export class Kubernetes extends Utils {
554556
* @returns {Promise<string>} - returns route URL.
555557
*/
556558
public async getTTrustificationOidcIssuerUrl(namespace: string): Promise<string> {
557-
return this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "oidc_issuer_url");
559+
return await this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "oidc_issuer_url");
558560
}
559561

560562
/**
@@ -564,7 +566,7 @@ export class Kubernetes extends Utils {
564566
* @returns {Promise<string>} - returns route URL.
565567
*/
566568
public async getTTrustificationClientId(namespace: string): Promise<string> {
567-
return this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "oidc_client_id");
569+
return await this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "oidc_client_id");
568570
}
569571

570572
/**
@@ -574,7 +576,7 @@ export class Kubernetes extends Utils {
574576
* @returns {Promise<string>} - returns route URL.
575577
*/
576578
public async getTTrustificationClientSecret(namespace: string): Promise<string> {
577-
return this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "oidc_client_secret");
579+
return await this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "oidc_client_secret");
578580
}
579581

580582
/**
@@ -584,6 +586,6 @@ export class Kubernetes extends Utils {
584586
* @returns {Promise<string>} - returns route URL.
585587
*/
586588
public async getTTrustificationSupportedCycloneDXVersion(namespace: string): Promise<string> {
587-
return this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "supported_cyclonedx_version");
589+
return await this.getDeveloperHubSecret(namespace, "rhtap-trustification-integration", "supported_cyclonedx_version");
588590
}
589591
}

0 commit comments

Comments
 (0)