Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

INT-7797: refactor private ca #587

Merged
merged 8 commits into from
Apr 20, 2023
Merged

Conversation

gastonyelmini
Copy link
Contributor

@gastonyelmini gastonyelmini commented Apr 20, 2023

The issue is that we’re using privateca API version v1beta1, which is deprecated. We need to instead use v1, which is supported.

as a result, we need to also add the caPool resource, which should be a parent of google_certificate_authority.

This also includes:

  • Migrating test to new version
  • Refactoring service constants
  • Splitting handlers to multiple files
  • Splitting steps that fetch and generate relationships in the same step.

@gastonyelmini gastonyelmini requested a review from a team as a code owner April 20, 2023 03:49
Comment on lines 27 to 28
const instance =
getRawData<privateca_v1.Schema$CertificateAuthority>(caAuthorityEntity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
const instance =
getRawData<privateca_v1.Schema$CertificateAuthority>(caAuthorityEntity);
const caAuthority =
getRawData<privateca_v1.Schema$CertificateAuthority>(caAuthorityEntity);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It typically makes sense to put this step inside fetchAuthorityCertificates.ts, since the relationship is built off of that entity.

import { PrivatecaSteps } from '../constants';

describe(`privateca#${PrivatecaSteps.STEP_PRIVATE_CA_CERTIFICATES.id}`, () => {
let recording: Recording;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tip: this suggestion will prevent you from ever forgetting the condition in front of if (recording) await recording.stop()

Suggested change
let recording: Recording;
let recording: Recording | undefined;

Copy link

@JuanManuelIbarlucea JuanManuelIbarlucea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
Just left some minor comments on possible logging.

);

if (!caPoolEntity || !caAuthorityEntity) {
return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe log something here?

const bucketName = instance.gcsBucket;

if (!bucketName) {
return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem

getCloudStorageBucketKey(bucketName),
);
if (!storageBucketEntity) {
return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem

test/mocks.ts Show resolved Hide resolved
Comment on lines 22 to 24
logger.warn(
`${PrivatecaSteps.STEP_PRIVATE_CA_POOLS.id} - Found undefined caPool entity in iterateCaPools.`,
);
Copy link
Contributor

@ndowmon ndowmon Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something you've encountered? How is the API returning an array that contains undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was just for safe purposes but you are right it does not make much sense

Comment on lines 90 to 95
if (!bucketName) {
logger.warn(
`${PrivatecaSteps.STEP_CREATE_PRIVATE_CA_CERTIFICATE_AUTHORITY_BUCKET_RELATIONSHIPS.id} - Missing bucketName.`,
);
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious - is gcsBucket a required property here? Is it true that if we do not find it, something has gone wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!bucketName) {
logger.warn(
`${PrivatecaSteps.STEP_CREATE_PRIVATE_CA_CERTIFICATE_AUTHORITY_BUCKET_RELATIONSHIPS.id} - Missing bucketName.`,
);
return;
}
if (!bucketName) {
return;
}


const result = await executeStepWithDependencies(stepTestConfig);
expect(result).toMatchStepMetadata(stepTestConfig);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: instead of separately setting jest.setTimeout(45_000), you can add the timeout as the third positional argument to test():

Suggested change
});
}, 45_000);

ndowmon
ndowmon previously approved these changes Apr 20, 2023
@gastonyelmini gastonyelmini added minor Increment the minor version when merged release Create a release when this pr is merged labels Apr 20, 2023
Copy link

@JuanManuelIbarlucea JuanManuelIbarlucea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gastonyelmini gastonyelmini merged commit 9d782ed into main Apr 20, 2023
@gastonyelmini gastonyelmini deleted the INT-7797-refactor-private-ca branch April 20, 2023 17:41
@j1-internal-automation
Copy link
Collaborator

🚀 PR was released in v2.23.0 🚀

@j1-internal-automation j1-internal-automation added the released This issue/pull request has been released. label Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
minor Increment the minor version when merged release Create a release when this pr is merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants