Skip to content

Commit

Permalink
change: add new settings for hub_api_root and hub_url_auth (melta…
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielPDWalker committed Aug 24, 2022
1 parent 84e58a2 commit 3f8a965
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
43 changes: 42 additions & 1 deletion docs/src/_reference/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,29 @@ meltano config meltano set project_readonly true
export MELTANO_PROJECT_READONLY=true
```

### <a name="hub-api-root"></a>`hub_api_root`

- [Environment variable](/guide/configuration#configuring-settings): `MELTANO_HUB_API_ROOT`
- Default: None

This sets the value of the root url for the hub api.

If provided, this setting overrides the [`hub_url`](#hub-url).

#### How to use

```bash
meltano config meltano set hub_api_root "https://mysite.com/my-plugins"
meltano config meltano set hub_api_root false

export MELTANO_HUB_API_ROOT="https://mysite.com/my-plugins"
export MELTANO_HUB_API_ROOT=false
```

### <a name="hub-url"></a>`hub_url`

- [Environment variable](/guide/configuration#configuring-settings): `MELTANO_HUB_URL`
- Default: [`https://hub.meltano.com`](https://hub.meltano.com)
- Default: `https://hub.meltano.com`

Where Meltano can find the Hub that lists all [discoverable plugins](/concepts/plugins#discoverable-plugins).

Expand All @@ -254,6 +273,28 @@ meltano config meltano set hub_url http://localhost:4000
export MELTANO_HUB_URL=http://localhost:4000
```

### <a name="hub-url-auth"></a>`hub_url_auth`

- [Environment variable](/guide/configuration#configuring-settings): `MELTANO_HUB_URL_AUTH`
- Default: None

The value of the `Authorization` header sent when making a request to [`hub_url`](#hub-url).

No `Authorization` header is applied under the following conditions:

- `hub_url_auth` is not set
- `hub_url_auth` is set to `false`, `null` or an empty string

#### How to use

```bash
meltano config meltano set hub_url_auth "Bearer $ACCESS_TOKEN"
meltano config meltano set hub_url_auth false

export MELTANO_HUB_URL_AUTH="Bearer $ACCESS_TOKEN"
export MELTANO_HUB_URL_AUTH=false
```

### <a name="discovery-url"></a>`discovery_url`

- [Environment variable](/guide/configuration#configuring-settings): `MELTANO_DISCOVERY_URL`
Expand Down
2 changes: 2 additions & 0 deletions src/meltano/core/bundle/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ settings:
env_specific: true
- name: discovery_url
value: https://discovery.meltano.com/discovery.yml
- name: hub_api_root
- name: hub_url
value: https://hub.meltano.com
- name: hub_url_auth
- name: discovery_url_auth
- name: elt.buffer_size
kind: integer
Expand Down
16 changes: 15 additions & 1 deletion src/meltano/core/hub/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,29 @@ def __init__(self, project: Project) -> None:

self.session.headers["X-Project-ID"] = project_id

if self.hub_url_auth:
self.session.headers.update({"Authorization": self.hub_url_auth})

@property
def hub_api_url(self):
"""Return the URL of the Hub API.
Returns:
The URL of the Hub API.
"""
hub_api_root = self.settings_service.get("hub_api_root")
hub_url = self.settings_service.get("hub_url")
return f"{hub_url}/meltano/api/v1"

return hub_api_root or f"{hub_url}/meltano/api/v1"

@property
def hub_url_auth(self):
"""Return the `hub_url_auth` setting.
Returns:
The `hub_url_auth` setting.
"""
return self.settings_service.get("hub_url_auth")

def plugin_type_endpoint(self, plugin_type: PluginType) -> str:
"""Return the list endpoint for the given plugin type.
Expand Down
6 changes: 6 additions & 0 deletions tests/meltano/core/hub/test_meltano_hub_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from meltano.core.hub.client import HubPluginVariantNotFoundError
from meltano.core.plugin.base import PluginType, Variant
from meltano.core.plugin.error import PluginNotFoundError
from meltano.core.project_settings_service import ProjectSettingsService


class TestMeltanoHubService:
Expand Down Expand Up @@ -94,3 +95,8 @@ def test_get_plugins_of_type(
"singer-io",
]
assert hub_request_counter["/extractors/index"] == 1

def test_hub_auth(self, project):
ProjectSettingsService(project).set("hub_url_auth", "Bearer s3cr3t")
hub = MeltanoHubService(project)
assert hub.session.headers["Authorization"] == "Bearer s3cr3t"

0 comments on commit 3f8a965

Please sign in to comment.