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

Split image metadata facade. #7636

Merged
merged 4 commits into from
Jul 13, 2017
Merged

Conversation

anastasiamac
Copy link
Contributor

Description of change

This PR splits image metadata facade into 2 - one for client and one for the worker.
The worker-related facade remained the original name ImageMetadata and only contains functionality to retrieve and store metadata for published cloud images.
The new client facade, ImageMetadataManager, contains functionality for CRUD operations on image metadata. As these operations are currently only meant to be called as part of the experimental feature with commands sitting behind a feature flag, this facade is also put behind a feature flag.
There are some reservations around whether this facade should be behind a feature flag or not. The debate is around what is more important to us - usability or maintainability. From usability perspective, without the feature flag here, newer clients, that may have these commands exposed, will be able to use functionality without the need to upgrade controllers. However, to be more aligned with the approach on other experimental features, I have put the facade behind a feature flag for now.

The rest of the PR is moving tests and related code around into new locations as well as updating references and import statements.

Note that I have not actually changed the content of the code besides the basic move, rename and typo corrections.

QA steps

There should be no changes to behavior - all unit and CI tests still pass.

Documentation changes

n/a

Bug reference

https://bugs.launchpad.net/juju/+bug/1703582

Copy link
Contributor

@axw axw left a comment

Choose a reason for hiding this comment

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

looking good overall, but please make sure the auth is tightly scoped

@@ -4,7 +4,6 @@
package imagemetadata
Copy link
Contributor

Choose a reason for hiding this comment

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

the worker is only run by controllers, so it should go under facades/controller

Copy link
Contributor

Choose a reason for hiding this comment

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

please make sure the imagemetadata facade allows only controllers to auth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

resources facade.Resources,
authorizer facade.Authorizer,
) (*API, error) {
if !authorizer.AuthClient() && !authorizer.AuthController() {
Copy link
Contributor

Choose a reason for hiding this comment

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

this facade should allow only clients

if !authorizer.AuthClient() {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

type API struct {
metadata metadataAccess
newEnviron func() (environs.Environ, error)
authorizer facade.Authorizer
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to store authorizer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, true now that they are split there is no need. It also means that we no longer need to have ControllerTag call - a lot cleaner code. Done.

// given filter.
// Returned list contains metadata ordered by priority.
func (api *API) List(filter params.ImageMetadataFilter) (params.ListCloudImageMetadataResult, error) {
if api.authorizer.AuthClient() {
Copy link
Contributor

Choose a reason for hiding this comment

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

the whole facade should only allow clients now, so drop this check, and ones in other non-constructor methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@axw axw left a comment

Choose a reason for hiding this comment

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

LGTM once the superuser checks are back in place. Can you please add a test to each facade for the auth checks?

@anastasiamac
Copy link
Contributor Author

I'd rather add the tests as a follow-up as I wanted to address our current fake authoriser used for tests first - it's really something I wanted to do for a while and will make permission tests easier.

Also, it'd be great if these permission tests where done at a higher level now that we have split between client, controller, etc facades. In other words, something along the lines of "test that all facades in facades/client package are client scoped".

@anastasiamac
Copy link
Contributor Author

$$merge$$

@jujubot
Copy link
Collaborator

jujubot commented Jul 13, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@axw
Copy link
Contributor

axw commented Jul 13, 2017

Also, it'd be great if these permission tests where done at a higher level now that we have split between client, controller, etc facades. In other words, something along the lines of "test that all facades in facades/client package are client scoped".

That would be great, if it's possible.

@jujubot jujubot merged commit 6498a80 into juju:develop Jul 13, 2017
@anastasiamac anastasiamac deleted the metadata-facade-split branch July 13, 2017 11:58
barrettj12 added a commit to barrettj12/juju that referenced this pull request May 22, 2024
This package was pulled out in juju#7631 to create a new controller-side image
metadata facade (juju#7636) which was later removed in juju#8400. Since this code is
only used by the client facade, we can take it out of common and into the
client facade package.

Re: tests, only TestSaveModelCfgFailed had to be moved over. The other tests
were already covered by existing tests in the client package.
jujubot added a commit that referenced this pull request May 22, 2024
#17394

This PR removes the `ModelConfig` function from `ImageMetadataInterface`, hence removing the dependency on Mongo/state. We have replaced this function with an interface
```go
type ModelConfigService interface {
 ModelConfig(ctx context.Context) (*config.Config, error)
}
```
which provides the functionality of the removed function. This interface is implemented by `ServiceFactory.Config()` and mocked out in testing.

Now that `ImageMetadataInterface` only provides one method (`Save`), we also renamed it to `ImageMetadataSaver`. I also changed the interface of the `imagecommon.Save` function to take a context and a `ModelConfigService`:
```go
func Save(
 ctx context.Context,
 service ModelConfigService,
 saver ImageMetadataSaver,
 metadata params.MetadataSaveParams,
) ([]params.ErrorResult, error) {
```

Corresponding test changes are included.

@nvinuesa also pointed out that the `imagecommon` package was only used by the `client/imagemetadata` facade. It appears this `imagecommon` was originally pulled out (#7631) to create a new controller-side image metadata facade (#7636) which was later removed (#8400). Hence, I have removed this package and pulled all the relevant code into the client package.

### TODO:
- [x] fix panicking test
- [x] clean up commit history
- [x] move imagecommon pkg into imagemetadata

**Jira card:** JUJU-6038
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants