OpenConext / OpenConext-attribute-aggregation

OpenConext attribute aggregation
Apache License 2.0
1 stars 2 forks source link

Add reusable REST Attribute Aggregator #46

Closed Jong-Vincent closed 1 year ago

Jong-Vincent commented 1 year ago

Hi all,

We've implemented a reusable REST aggregator which can be used to retrieve data from REST endpoints. A new aggregator is added purely via configuration.

Below is the documentation to go with this implementation:

REST Attribute Aggregator

This reusable aggregator can be used for retrieving data from a REST endpoint and supports various options for configuring a HTTP request to that endpoint e.g. an API key.

New entries are added in attributeAuthorities.yml.

Below is an example of the full configuration with explanations for the options:

- {
  id: "<id>",
  description: "<description>",
  endpoint: "<endpoint>",
  type: "rest",
  // Username for basic authentication
  user: "", 
  // Password for basic authentication
  password: "", 
  // Headers to add in the HTTP request 
  headers: [ 
      {
        "key": "<key>",
        "value": "<value>",
      }
  ],
  // Path parameters to use in the value for 'endpoint' 
  // Wildcards can be added with %s e.g. https://endpoint/%s/subpath/%s...
  // The index below will correspond to the order in which the wildcards are replaced
  // sourceAttribute refers to the attribute received from EngineBlock to use as the substitute
  pathParams: [
      {
        "index": 0,
        "sourceAttribute": "urn:mace:terena.org:attribute-def:schacHomeOrganization"
      },
      {
        "index": 1,
        "sourceAttribute": "urn:mace:dir:attribute-def:uid"
      }
  ],
  // Options are 'GET', 'POST', 'PUT', 'DELETE', default is 'GET'
  requestMethod: 'GET',
  // Request parameters to use in the HTTP request, will be appended as ?name=value&...
  // sourceAttribute refers to the attribute received from EngineBlock to use as the substitute
  requestParams: [
      {
        "name": "<name>",
        "sourceAttribute": "urn:mace:terena.org:attribute-def:schacHomeOrganization"
      }
  ],
  // Mapping to apply to the response received from the HTTP request
  // responseKey corresponds to the field in the response object of which to retrieve the value
  // targetAttribute corresponds to the attribute to send the value as in the result of aggregation
  mappings: [
      {
        "responseKey": "myResponseKey",
        "targetAttribute": "myTargetAttribute"
      }
  ],
  timeOut: 15000,
  attributes: [],
  requiredInputAttributes: [
      {
        name: "urn:mace:terena.org:attribute-def:schacHomeOrganization",
      }
  ],
  validationRegExp: "[a-zA-Z0-9]*"
}
thijskh commented 1 year ago

Thanks! It would be excellent if the given documentation and config example was in the PR somewhere, e.g. in the application.yml template as a ready to use example and/or documented in the README.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 84.70% and project coverage change: -0.72 :warning:

Comparison is base (27158bd) 92.81% compared to head (eb2d2ee) 92.09%.

:exclamation: Current head eb2d2ee differs from pull request most recent head 1f81bb5. Consider uploading reports for the commit 1f81bb5 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #46 +/- ## ============================================ - Coverage 92.81% 92.09% -0.72% - Complexity 323 360 +37 ============================================ Files 59 65 +6 Lines 877 962 +85 Branches 48 56 +8 ============================================ + Hits 814 886 +72 - Misses 43 53 +10 - Partials 20 23 +3 ``` | [Impacted Files](https://app.codecov.io/gh/OpenConext/OpenConext-attribute-aggregation/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=OpenConext) | Coverage Δ | | |---|---|---| | [.../aggregators/AttributeAggregatorConfiguration.java](https://app.codecov.io/gh/OpenConext/OpenConext-attribute-aggregation/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=OpenConext#diff-YWEtc2VydmVyL3NyYy9tYWluL2phdmEvYWEvYWdncmVnYXRvcnMvQXR0cmlidXRlQWdncmVnYXRvckNvbmZpZ3VyYXRpb24uamF2YQ==) | `76.47% <0.00%> (-7.41%)` | :arrow_down: | | [aa-server/src/main/java/aa/model/Header.java](https://app.codecov.io/gh/OpenConext/OpenConext-attribute-aggregation/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=OpenConext#diff-YWEtc2VydmVyL3NyYy9tYWluL2phdmEvYWEvbW9kZWwvSGVhZGVyLmphdmE=) | `60.00% <60.00%> (ø)` | | | [aa-server/src/main/java/aa/model/Mapping.java](https://app.codecov.io/gh/OpenConext/OpenConext-attribute-aggregation/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=OpenConext#diff-YWEtc2VydmVyL3NyYy9tYWluL2phdmEvYWEvbW9kZWwvTWFwcGluZy5qYXZh) | `60.00% <60.00%> (ø)` | | | [aa-server/src/main/java/aa/model/PathParam.java](https://app.codecov.io/gh/OpenConext/OpenConext-attribute-aggregation/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=OpenConext#diff-YWEtc2VydmVyL3NyYy9tYWluL2phdmEvYWEvbW9kZWwvUGF0aFBhcmFtLmphdmE=) | `60.00% <60.00%> (ø)` | | | [aa-server/src/main/java/aa/model/RequestParam.java](https://app.codecov.io/gh/OpenConext/OpenConext-attribute-aggregation/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=OpenConext#diff-YWEtc2VydmVyL3NyYy9tYWluL2phdmEvYWEvbW9kZWwvUmVxdWVzdFBhcmFtLmphdmE=) | `60.00% <60.00%> (ø)` | | | [...a/aa/aggregators/rest/RestAttributeAggregator.java](https://app.codecov.io/gh/OpenConext/OpenConext-attribute-aggregation/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=OpenConext#diff-YWEtc2VydmVyL3NyYy9tYWluL2phdmEvYWEvYWdncmVnYXRvcnMvcmVzdC9SZXN0QXR0cmlidXRlQWdncmVnYXRvci5qYXZh) | `96.29% <96.29%> (ø)` | | | [...-server/src/main/java/aa/model/AggregatorType.java](https://app.codecov.io/gh/OpenConext/OpenConext-attribute-aggregation/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=OpenConext#diff-YWEtc2VydmVyL3NyYy9tYWluL2phdmEvYWEvbW9kZWwvQWdncmVnYXRvclR5cGUuamF2YQ==) | `100.00% <100.00%> (ø)` | | | [...java/aa/model/AttributeAuthorityConfiguration.java](https://app.codecov.io/gh/OpenConext/OpenConext-attribute-aggregation/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=OpenConext#diff-YWEtc2VydmVyL3NyYy9tYWluL2phdmEvYWEvbW9kZWwvQXR0cmlidXRlQXV0aG9yaXR5Q29uZmlndXJhdGlvbi5qYXZh) | `96.15% <100.00%> (+1.15%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

Jong-Vincent commented 1 year ago

Thanks! It would be excellent if the given documentation and config example was in the PR somewhere, e.g. in the application.yml template as a ready to use example and/or documented in the README.

Added the documentation to the README