Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common code reorganisation #197

Merged
merged 4 commits into from
Nov 14, 2023
Merged

Common code reorganisation #197

merged 4 commits into from
Nov 14, 2023

Conversation

lbajolet-hashicorp
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp commented Nov 9, 2023

This PR reworks the code for all the components, now instead of having the common code as part of the builder, and have the post-processors depend on it, we moved all the common code to a lib package, which is then leveraged by components.

This removes some duplication in the authentication logic, and consolidates it in a single package, along with the driver, which gets more capabilities for the post-processors to use.

This however means (and this was already the case in the related PR) that the googlecompute-export component now needs to expose its own authentication methods, as it cannot rely on the artifact for that.

Leaving authentication information in the artifact may be a security issue later, so we opted to remove that.

Note: based on top of #186

@lbajolet-hashicorp lbajolet-hashicorp requested a review from a team as a code owner November 9, 2023 21:06
@lbajolet-hashicorp lbajolet-hashicorp force-pushed the auth_rework branch 2 times, most recently from f251bb5 to b223417 Compare November 9, 2023 21:08
@lbajolet-hashicorp lbajolet-hashicorp changed the base branch from main to relax-JWT-Error November 10, 2023 16:09
Copy link
Contributor

@JenGoldstrich JenGoldstrich left a comment

Choose a reason for hiding this comment

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

LGTM! Nice refactor

@lmayorga1980
Copy link
Contributor

This will be very nice to support machine images

@lbajolet-hashicorp lbajolet-hashicorp changed the base branch from relax-JWT-Error to main November 14, 2023 16:14
The googlecompute builder used to contain a lot of code that was not
only used by itself, but by the post-processors as well.

This way of organising code is a bit counter-intuitive, and may be
problematic when sharing code between components.

To make it clear what is supposed to be available for every component of
the plugin, we move everything to a common lib, so the builder, and
post-processors, can all depend on it.
The import post-processor used to invoke some functions from the GCE API
directly, with a series of options provided directly from its context.

Since we want to move away from that model for authentication, in favour
of something common to all components, this has to change, and so we
move the few calls that were directly made into functions in the driver.

Then we can use this driver from the post-processor in order to perform
those actions.

This also has the benefit of letting the driver perform the asynchronous
actions like getting the state of the image, making the code more
reliable as there's a timeout to the action instead of an endless loop
until the image is ready.
The authentication code was duplicated for all components, making
changes heavier than they need to be.
To consolidate this, we move the authentication configuration to common,
and the code that sets-up the credentials for GCE.
The CreateImage and CreateImageFromRaw functions fropm the GCE driver
were very similar and contained a lot of duplicated code, for very
little changes in between the two calls.

Instead of having both with a lot of parameters, we simplify the
function to accept an image specification, as exposed by the GCE client
library, so the driver only takes care of performing the call, and
manage its lifecycle through channels, then returning the image after
it's created.
@lbajolet-hashicorp
Copy link
Contributor Author

Not sure what the linter is complaining about, locally this doesn't fail so I'll override the test and merge this as-is, we'll fix the issue if it becomes persistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants