Skip to content

Commit

Permalink
fix: added a function to normalize the namespace in case of UDP (#57)
Browse files Browse the repository at this point in the history
Co-authored-by: janssenb <[email protected]>
Co-authored-by: Matthias Mohr <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2021
1 parent deeb696 commit 345f7e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- The `namespace` parameter in `listProcesses` and `describeProcess` parses URLs to extract the namespace (experimental).

## [2.3.1] - 2021-12-10

### Fixed
Expand Down
14 changes: 14 additions & 0 deletions openeo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,20 @@ declare module OpenEO {
* @throws {Error}
*/
listCollectionItems(collectionId: string, spatialExtent?: Array<number> | null, temporalExtent?: Array<any> | null, limit?: number | null): AsyncGenerator<any, void, unknown>;
/**
* Normalisation of the namespace to a value that is compatible with the OpenEO specs - EXPERIMENTAL.
*
* This is required to support UDP that are shared as public. These can only be executed with providing the full URL
* (e.g. https://<backend>/processes/<namespace>/<process_id>) as the namespace value in the processing graph. For other
* parts of the API (such as the listing of the processes, only the name of the namespace is required.
*
* This function will extract the short name of the namespace from a shareable URL.
*
* @protected
* @param {?string} namespace - Namespace of the process
* @returns {?string}
*/
protected normalizeNamespace(namespace: string | null): string | null;
/**
* List processes available on the back-end.
*
Expand Down
23 changes: 21 additions & 2 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,25 @@ class Connection {
}
}

/**
* Normalisation of the namespace to a value that is compatible with the OpenEO specs - EXPERIMENTAL.
*
* This is required to support UDP that are shared as public. These can only be executed with providing the full URL
* (e.g. https://<backend>/processes/<namespace>/<process_id>) as the namespace value in the processing graph. For other
* parts of the API (such as the listing of the processes, only the name of the namespace is required.
*
* This function will extract the short name of the namespace from a shareable URL.
*
* @protected
* @param {?string} namespace - Namespace of the process
* @returns {?string}
*/
normalizeNamespace(namespace) {
// The pattern in https://github.com/Open-EO/openeo-api/pull/348 doesn't include the double colon yet - the regexp may change in the future
const matches = namespace.match( /^https?:\/\/.*\/processes\/(@?[\w\-.~:]+)\/?/i);
return matches && matches.length > 1 ? matches[1] : namespace;
}

/**
* List processes available on the back-end.
*
Expand All @@ -308,7 +327,7 @@ class Connection {
if (!namespace) {
namespace = 'backend';
}
let path = (namespace === 'backend') ? '/processes' : `/processes/${namespace}`;
let path = (namespace === 'backend') ? '/processes' : `/processes/${this.normalizeNamespace(namespace)}`;
let response = await this._get(path);

if (!Utils.isObject(response.data) || !Array.isArray(response.data.processes)) {
Expand Down Expand Up @@ -340,7 +359,7 @@ class Connection {
await this.listProcesses();
}
else {
let response = await this._get(`/processes/${namespace}/${processId}`);
let response = await this._get(`/processes/${this.normalizeNamespace(namespace)}/${processId}`);
if (!Utils.isObject(response.data) || typeof response.data.id !== 'string') {
throw new Error('Invalid response received for process');
}
Expand Down

0 comments on commit 345f7e6

Please sign in to comment.