Skip to content

Commit

Permalink
Allowing to use a custom backend plugin url
Browse files Browse the repository at this point in the history
  • Loading branch information
skrolikiewicz committed Mar 28, 2024
1 parent fe0201a commit 6bd23f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ nobl9:

Depending on where your Nobl9 organization is hosted, use either `https://app.nobl9.com` or `http://us1.nobl9.com` as the base URL.

The backend plugin will be available under the `/api/nobl9/slos` path by default. You can use the `nobl9.backendPluginPath` config key to provide a custom path.
If, for example, you're backend plugins are served without the `/api` prefix, you can use the following config:

```yaml
nobl9:
baseUrl: https://app.nobl9.com
organization: ${NOBL9_ORGANIZATION_ID}
clientId: ${NOBL9_CLIENT_ID}
clientSecret: ${NOBL9_CLIENT_SECRET}
backendPluginPath: /nobl9/slos
```

#### Catalog entity annotations

Annotate components of your choice with `nobl9.com/project` annotation and either `nobl9.com/services` and/or `nobl9.com/slos`. Based on multiple annotations, the `AND` operator is used to decide which SLOs to display.
Expand Down
5 changes: 5 additions & 0 deletions plugins/nobl9-plugin/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ export interface Config {
* @visibility frontend
*/
organization: string;
/**
* custom backend plugin path
* @visibility frontend
*/
backendPluginPath: string | undefined;
};
}
14 changes: 9 additions & 5 deletions plugins/nobl9-plugin/src/components/SloPage/SloPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@ const toQueryStringParams = (entity: Entity) => {
return params.toString();
};

const getBackendUrl = (config: any, entity: Entity) => {
const baseUrl = config.getString('backend.baseUrl');
const path = config.has('nobl9.backendPluginPath')
? config.getString('nobl9.backendPluginPath')
: '/api/nobl9/slos';
return `${baseUrl}${path}?${toQueryStringParams(entity)}`;
};

export const SloPage = () => {
const { entity } = useEntity();
const config = useApi(configApiRef);
const classes = useStyles();

const { value, loading, error } =
useAsync(async (): Promise<N9BackendResponse> => {
return await fetch(
`${config.getString(
'backend.baseUrl',
)}/api/nobl9/slos?${toQueryStringParams(entity)}`,
).then(res => res.json());
return await fetch(getBackendUrl(config, entity)).then(res => res.json());
}, [entity]);

if (loading) {
Expand Down

0 comments on commit 6bd23f3

Please sign in to comment.