Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add proxy config from env variables #242

Merged
merged 4 commits into from
Aug 11, 2023
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
12 changes: 6 additions & 6 deletions lib/charms/grafana_k8s/v0/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, *args):
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version

LIBPATCH = 32
LIBPATCH = 33

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -665,14 +665,14 @@ def _template_panels(
continue
if not existing_templates:
datasource = panel.get("datasource")
if type(datasource) == str:
if isinstance(datasource, str):
if "loki" in datasource:
panel["datasource"] = "${lokids}"
elif "grafana" in datasource:
continue
else:
panel["datasource"] = "${prometheusds}"
elif type(datasource) == dict:
elif isinstance(datasource, dict):
# In dashboards exported by Grafana 9, datasource type is dict
dstype = datasource.get("type", "")
if dstype == "loki":
Expand All @@ -686,7 +686,7 @@ def _template_panels(
logger.error("Unknown datasource format: skipping")
continue
else:
if type(panel["datasource"]) == str:
if isinstance(panel["datasource"], str):
if panel["datasource"].lower() in replacements.values():
# Already a known template variable
continue
Expand All @@ -701,7 +701,7 @@ def _template_panels(
if replacement:
used_replacements.append(ds)
panel["datasource"] = replacement or panel["datasource"]
elif type(panel["datasource"]) == dict:
elif isinstance(panel["datasource"], dict):
dstype = panel["datasource"].get("type", "")
if panel["datasource"].get("uid", "").lower() in replacements.values():
# Already a known template variable
Expand Down Expand Up @@ -831,7 +831,7 @@ def _modify_panel(panel: dict, topology: dict, transformer: "CosTool") -> dict:
if "datasource" not in panel.keys():
continue

if type(panel["datasource"]) == str:
if isinstance(panel["datasource"], str):
if panel["datasource"] not in known_datasources:
continue
querytype = known_datasources[panel["datasource"]]
Expand Down
8 changes: 4 additions & 4 deletions lib/charms/observability_libs/v0/cert_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

LIBID = "b5cd5cd580f3428fa5f59a8876dcbe6a"
LIBAPI = 0
LIBPATCH = 5
LIBPATCH = 6


class CertChanged(EventBase):
Expand Down Expand Up @@ -101,16 +101,16 @@ def __init__(
peer_relation_name: Must match metadata.yaml.
certificates_relation_name: Must match metadata.yaml.
cert_subject: Custom subject. Name collisions are under the caller's responsibility.
extra_sans_dns: Any additional DNS names apart from FQDN.
extra_sans_dns: DNS names. If none are given, use FQDN.
"""
super().__init__(charm, key)

self.charm = charm
self.cert_subject = cert_subject or charm.unit.name
self.cert_subject = charm.unit.name if not cert_subject else cert_subject

# Auto-include the fqdn and drop empty/duplicate sans
self.sans_dns = list(set(filter(None, (extra_sans_dns or []) + [socket.getfqdn()])))
# Use fqdn only if no SANs were given, and drop empty/duplicate SANs
self.sans_dns = list(set(filter(None, (extra_sans_dns or [socket.getfqdn()]))))

self.peer_relation_name = peer_relation_name
self.certificates_relation_name = certificates_relation_name
Expand Down
15 changes: 15 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,21 @@ def _build_layer(self) -> Layer:
"GF_DATABASE_TYPE": "sqlite3",
}

# Juju Proxy settings
extra_info.update(
{
"https_proxy": os.environ["JUJU_CHARM_HTTPS_PROXY"]
if "JUJU_CHARM_HTTPS_PROXY" in os.environ
else "",
"http_proxy": os.environ["JUJU_CHARM_HTTP_PROXY"]
if "JUJU_CHARM_HTTP_PROXY" in os.environ
else "",
"no_proxy": os.environ["JUJU_CHARM_NO_PROXY"]
if "JUJU_CHARM_NO_PROXY" in os.environ
else "",
}
)

grafana_path = self.external_url
if self._auth_env_vars:
extra_info.update(self._auth_env_vars)
Expand Down
Loading