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

CIF-1447 - The Core CIF Components must use a service user to access configurations #300

Merged
merged 26 commits into from
Jun 18, 2020

Conversation

dplaton
Copy link
Contributor

@dplaton dplaton commented Jun 12, 2020

Description

Add the service user mapping to the content package.

Implement an adapter factory that adapts a resource to a specific configuration object using a service resolver. I chose this approach because we cannot adapt directly to a ValueMap.
The configuration object is a wrapper around the ValueMap and it's in the public space, so HTL scripts can use them if needed.

The MagentoGraphqlClient has been updated to use this new method.

Related Issue

CIF-1447

Motivation and Context

Align our implementation with the security requirements that state that all access to /conf should be done via service users, not directly manipulating the ACLs

How Has This Been Tested?

Functional testing, unit tests

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes and the overall coverage did not decrease.
  • All unit tests pass on CircleCi.
  • I ran all tests locally and they pass.

…configurations

Add the service users mapping to the content package.
Implement a `ComponentsConfigurationProvider` which reads the context configuration data using the service users.

Update `MagentoGraphqlClient` to use the new service when reading configuration data.
Update some models to use the new service to read configuration data.
Daniel Platon added 7 commits June 15, 2020 14:24
…configurations

Remove the `ComponentsConfigurationProvider` service and implement a `ComponentsConfigurationAdapterFactory` which adapts from a `Resource` to a `ComponentsConfiguration` object. The `ComponentsConfiguration` is just a wrapper around a `ValueMap` and it's public so it can also be used in an HTL script it future use-cases require.
…configurations

Update `MagentoGraphqlClient` to use the new `ComponentsConfigurationAdapter`
…configurations

Update models and unit tests to use the new method of reading the configurations.
…configurations

Add unit tests for `ComponentsConfigurationAdapterFactory`.
…configurations

Fix unit test after merging with the `master` branch
@codecov
Copy link

codecov bot commented Jun 16, 2020

Codecov Report

Merging #300 into master will decrease coverage by 0.14%.
The diff coverage is 83.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #300      +/-   ##
============================================
- Coverage     64.77%   64.62%   -0.15%     
- Complexity      802      809       +7     
============================================
  Files           179      181       +2     
  Lines          5601     5631      +30     
  Branches        875      875              
============================================
+ Hits           3628     3639      +11     
- Misses         1848     1864      +16     
- Partials        125      128       +3     
Flag Coverage Δ Complexity Δ
#jest 42.44% <ø> (ø) 0.00 <ø> (ø)
#karma 94.51% <ø> (ø) 0.00 <ø> (ø)
#unittests 85.77% <83.33%> (-0.65%) 809.00 <12.00> (+7.00) ⬇️
Impacted Files Coverage Δ Complexity Δ
...ervices/ComponentsConfigurationAdapterFactory.java 64.70% <64.70%> (ø) 5.00 <5.00> (?)
...e/core/components/client/MagentoGraphqlClient.java 67.30% <92.30%> (-26.03%) 9.00 <0.00> (-4.00)
.../models/v1/navigation/GraphQLCategoryProvider.java 100.00% <100.00%> (ø) 13.00 <0.00> (ø)
.../internal/models/v1/navigation/NavigationImpl.java 87.40% <100.00%> (+0.57%) 25.00 <0.00> (ø)
...1/storeconfigexporter/StoreConfigExporterImpl.java 100.00% <100.00%> (ø) 4.00 <1.00> (ø)
...e/components/services/ComponentsConfiguration.java 100.00% <100.00%> (ø) 6.00 <6.00> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6356b21...cf8f978. Read the comment docs.

Copy link
Contributor

@cjelger cjelger left a comment

Choose a reason for hiding this comment

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

Looks good. I think we could probably refactor the unit tests a bit to avoid all the duplicate setup (I know we're all guilty here, we all added a lot of duplicate code), but we can also do that in a separate PR.

/*
* Copyright 2020 Adobe. All rights reserved.
*
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to be picky, this header is not formatted like all the other headers we use.

…configurations

Follow-up on the PR review:
- fix copyright headers
- code cleanup
- fix the graphql-requests.log file
- clean up the ProductImplTest which was passing, but for the wrong reasons.
* @return a {@link ValueMap} object.
*/
public ValueMap getValueMap() {
Map<String, Object> temp = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can just write new HashMap<>(internalProperties) because ValueMap implements Map.

dplaton and others added 2 commits June 18, 2020 10:37
…configurations

Optimize the `getValueMap` method of `ComponentsConfiguration`
ValueMap properties = configBuilder.name("cloudconfigs/commerce").asValueMap();
rootCategoryId = properties.get(PN_MAGENTO_ROOT_CATEGORY_ID, Integer.class);
}
ComponentsConfiguration properties = catalogPage.adaptTo(ComponentsConfiguration.class);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will that work? (catalogPage is not a Resource)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It probably won't. I didn't notice it in the tests because it always falls back to the context configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually that component reads the configuration in the "opposite" order of what we want to do: it should first get the config from that new ComponentsConfiguration and then fallback to the old way ... that's probably why the test didn't fail.

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, this is the way it's intended for this component - it first reads the category from the page properties and then it falls back to the configuration.

@cjelger
Copy link
Contributor

cjelger commented Jun 18, 2020

Following the last comment from @LSantha , I realised you probably also need to update StoreConfigExporterImpl to make everything consistent, no?

Daniel Platon and others added 3 commits June 18, 2020 11:49
…configurations

Update the `StoreConfigurationExporter` to also use `ComponentsConfiguration`
* The `try-with-resource` pattern that I tried to use in the `ComponentsConfigurationAdapterFactory` is cool, but it fails in this case because the `ValueMap` used to build the `ComponentsConfiguration` object is unusable if the resolver is closed. I switched to using a service resolver created in the `activate()` method.

* Update the `StoreConfigExporter` to use the `ComponentsConfiguration` object
* Fix a bug in the `NavigationImpl` model which was causing the model not to fallback to the page hierarchy in case of a missing `magentoRootCategoryId` property in the context configuration.
@dplaton dplaton merged commit b8dd61e into master Jun 18, 2020
@dplaton dplaton deleted the issues/CIF-1447 branch June 18, 2020 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants