Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/provides.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,19 @@ IntegrationRequest.set_block_storage_config(bs_version, trust_device_path,

Set the block storage config for this request.

<h2 id="provides.IntegrationRequest.proxy_config">proxy_config</h2>

```python
@property
IntegrationRequest.proxy_config() -> Dict[str, str]
```

Retrieve the `proxy_config` currently set by the provider side of the charm.

<h2 id="provides.IntegrationRequest.set_proxy_config">set_proxy_config</h2>

```python
IntegrationRequest.set_proxy_config() -> Dict[str, str]
```

Share the proxy_config for openstack endpoints from the provider side of the relation.
10 changes: 10 additions & 0 deletions docs/requires.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,13 @@ The username.

Optional version number for the APIs or None.


<h2 id="requires.OpenStackIntegrationRequires.proxy_config">proxy_config</h2>

```python
@property
OpenStackIntegrationRequires.proxy_config() -> Dict[str, str]
```

Optional `proxy_config` used to indicate to the application proxy details
necessary to reach the openstack endpoints.
3 changes: 2 additions & 1 deletion ops/ops/interface_openstack_integration/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import configparser
import contextlib
import io
from typing import Optional
from typing import Dict, Optional

from pydantic import BaseModel, Json, SecretStr, validator

Expand Down Expand Up @@ -40,6 +40,7 @@ class Data(BaseModel):
lb_method: Json[Optional[str]]
project_id: Json[Optional[str]] = None
project_domain_id: Json[Optional[str]] = None
proxy_config: Json[Optional[Dict[str, str]]] = None
manage_security_groups: Json[Optional[bool]]
subnet_id: Json[Optional[str]]
trust_device_path: Json[Optional[bool]]
Expand Down
10 changes: 9 additions & 1 deletion ops/ops/interface_openstack_integration/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
import base64
import logging
from typing import Optional
from typing import Dict, Optional

from backports.cached_property import cached_property
from ops.charm import CharmBase, RelationBrokenEvent
Expand Down Expand Up @@ -108,3 +108,11 @@ def endpoint_tls_ca(self) -> Optional[bytes]:
if data.endpoint_tls_ca:
return data.endpoint_tls_ca.encode()
return None

@property
def proxy_config(self) -> Dict[str, str]:
"""Return proxy_config from integrator relation."""
config = None
if self.is_ready and (data := self._data):
config = data.proxy_config
return config or {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because of pydantic validators, we can trust that after calling self.is_ready that whatever is in proxy_config is either None or Dict[str,str]

29 changes: 25 additions & 4 deletions provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""

from operator import attrgetter
from typing import Dict

from charms.reactive import Endpoint
from charms.reactive import when
Expand Down Expand Up @@ -109,7 +110,7 @@ def set_credentials(self,
"""
Set the credentials for this request.
"""
self._unit.relation.to_publish.update({
self._to_publish.update({
'auth_url': auth_url,
'region': region,
'username': username,
Expand Down Expand Up @@ -137,7 +138,7 @@ def set_lbaas_config(self,
"""
Set the load-balancer-as-a-service config for this request.
"""
self._unit.relation.to_publish.update({
self._to_publish.update({
'subnet_id': subnet_id,
'floating_network_id': floating_network_id,
'lb_method': lb_method,
Expand All @@ -154,15 +155,35 @@ def set_block_storage_config(self,
"""
Set the block storage config for this request.
"""
self._unit.relation.to_publish.update({
self._to_publish.update({
'bs_version': bs_version,
'trust_device_path': trust_device_path,
'ignore_volume_az': ignore_volume_az,
})

@property
def proxy_config(self) -> Dict[str, str]:
Comment on lines +164 to +165
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HomayoonAlimohammadi i switched this to a property to match the requires side of the relation

"""
Get the proxy config answered on this request.

if `proxy_config` is not set, return an empty dict.
"""
data = self._to_publish.get('proxy_config')
if not data or not isinstance(data, dict):
return {}
return {k: (v or "") for k, v in data.items()}

def set_proxy_config(self, proxy_config: Dict[str, str]):
"""
Set the proxy config for this request.
"""
self._to_publish.update({
'proxy_config': proxy_config,
})

@property
def has_credentials(self):
"""
Whether or not credentials have been set via `set_credentials`.
"""
return 'credentials' in self._unit.relation.to_publish
return 'credentials' in self._to_publish
9 changes: 9 additions & 0 deletions requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
charm once handled.
"""

from typing import Dict

from charms.reactive import Endpoint
from charms.reactive import when, when_not
Expand Down Expand Up @@ -311,3 +312,11 @@ def lb_enabled(self):
"""
# be careful to ensure a None value is returned as True, for backward compatibility
return self._received['lb_enabled'] is not False

@property
def proxy_config(self) -> Dict[str, str]:
"""Return proxy_config from integrator relation."""
data = self._received.get('proxy_config')
if not data or not isinstance(data, dict):
return {}
return {k: (v or "") for k, v in data.items()}