Skip to content

Commit

Permalink
Merge branch 'feature-rebac' into k8s-charm-install-dashboard-fix-01
Browse files Browse the repository at this point in the history
  • Loading branch information
alesstimec authored Jul 10, 2023
2 parents 53a504d + 5543c36 commit 9a6b919
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 38 deletions.
16 changes: 10 additions & 6 deletions charms/jimm-k8s/lib/charms/openfga_k8s/v0/openfga.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _on_openfga_store_created(self, event: OpenFGAStoreCreateEvent):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 3
LIBPATCH = 4

logger = logging.getLogger(__name__)

Expand All @@ -88,23 +88,27 @@ class OpenFGAEvent(RelationEvent):

@property
def store_id(self):
return self.relation.data[self.relation.app].get("store_id")
return self.relation.data[self.relation.app].get("store_id", "")

@property
def token_secret_id(self):
return self.relation.data[self.relation.app].get("token_secret_id")
return self.relation.data[self.relation.app].get("token_secret_id", "")

@property
def token(self):
return self.relation.data[self.relation.app].get("token", "")

@property
def address(self):
return self.relation.data[self.relation.app].get("address")
return self.relation.data[self.relation.app].get("address", "")

@property
def scheme(self):
return self.relation.data[self.relation.app].get("scheme")
return self.relation.data[self.relation.app].get("scheme", "")

@property
def port(self):
return self.relation.data[self.relation.app].get("port")
return self.relation.data[self.relation.app].get("port", "")


class OpenFGAStoreCreateEvent(OpenFGAEvent):
Expand Down
37 changes: 20 additions & 17 deletions charms/jimm-k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@

WORKLOAD_CONTAINER = "jimm"

REQUIRED_SETTINGS = [
"JIMM_UUID",
"JIMM_DSN",
"CANDID_URL",
"OPENFGA_STORE",
"OPENFGA_AUTH_MODEL",
"OPENFGA_HOST",
"OPENFGA_SCHEME",
"OPENFGA_TOKEN",
"OPENFGA_PORT",
]
REQUIRED_SETTINGS = {
"JIMM_UUID": "missing uuid configuration",
"JIMM_DSN": "missing postgresql relation",
"CANDID_URL": "missing candid-url configuration",
"OPENFGA_STORE": "missing openfga relation",
"OPENFGA_AUTH_MODEL": "run create-authorization-model action",
"OPENFGA_HOST": "missing openfga relation",
"OPENFGA_SCHEME": "missing openfga relation",
"OPENFGA_TOKEN": "missing openfga relation",
"OPENFGA_PORT": "missing openfga relation",
}

DATABASE_NAME = "jimm"
OPENFGA_STORE_NAME = "jimm"
Expand Down Expand Up @@ -335,7 +335,7 @@ def _on_stop(self, _):
"""Stop JIMM."""
container = self.unit.get_container(WORKLOAD_CONTAINER)
if container.can_connect():
container.stop()
container.stop("jimm")
self._ready()

def _on_update_status(self, _):
Expand Down Expand Up @@ -395,10 +395,10 @@ def _ready(self):

env_vars = plan.services.get("jimm").environment

for setting in REQUIRED_SETTINGS:
for setting, message in REQUIRED_SETTINGS.items():
if not env_vars.get(setting, ""):
self.unit.status = BlockedStatus(
"{} configuration value not set".format(setting),
"{} configuration value not set: {}".format(setting, message),
)
return False

Expand Down Expand Up @@ -586,11 +586,14 @@ def _on_openfga_store_created(self, event: OpenFGAStoreCreateEvent):
if not event.store_id:
return

# secret = self.model.get_secret(id=event.token_secret_id)
# secret_content = secret.get_content()
token = event.token
if event.token_secret_id:
secret = self.model.get_secret(id=event.token_secret_id)
secret_content = secret.get_content()
token = secret_content["token"]

self._state.openfga_store_id = event.store_id
self._state.openfga_token = event.token # secret_content["token"]
self._state.openfga_token = token
self._state.openfga_address = event.address
self._state.openfga_port = event.port
self._state.openfga_scheme = event.scheme
Expand Down
19 changes: 11 additions & 8 deletions charms/jimm/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ type: "charm"
parts:
charm:
prime:
- ./templates
- ./files
- README.md
charm-python-packages: [setuptools]
- ./templates
- ./files
- README.md
charm-python-packages:
- setuptools
- cosl
- pydantic==1.10
bases:
# Ensure run-on is the same or newer than build-on
# since jimm-server is a Go binary using CGO dependencies
- build-on:
- name: "ubuntu"
channel: "20.04"
- name: "ubuntu"
channel: "20.04"
run-on:
- name: "ubuntu"
channel: "20.04"
- name: "ubuntu"
channel: "20.04"
2 changes: 1 addition & 1 deletion charms/jimm/lib/charms/grafana_agent/v0/cos_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class _MetricsEndpointDict(TypedDict):
LIBAPI = 0
LIBPATCH = 3

PYDEPS = ["cosl", "pydantic"]
PYDEPS = ["cosl", "pydantic==1.10"]

DEFAULT_RELATION_NAME = "cos-agent"
DEFAULT_PEER_RELATION_NAME = "peers"
Expand Down
6 changes: 5 additions & 1 deletion charms/jimm/lib/charms/openfga_k8s/v0/openfga.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _on_openfga_store_created(self, event: OpenFGAStoreCreateEvent):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 3
LIBPATCH = 4

logger = logging.getLogger(__name__)

Expand All @@ -93,6 +93,10 @@ def store_id(self):
@property
def token_secret_id(self):
return self.relation.data[self.relation.app].get("token_secret_id")

@property
def token(self):
return self.relation.data[self.relation.app].get("token")

@property
def address(self):
Expand Down
2 changes: 1 addition & 1 deletion charms/jimm/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Jinja2 >= 2.11.3
ops >= 2.0.0
charmhelpers >= 0.20.22
hvac >= 0.11.0
pydantic
pydantic == 1.10
cosl
11 changes: 7 additions & 4 deletions charms/jimm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,19 @@ def _on_openfga_store_created(self, event: OpenFGAStoreCreateEvent):
if not event.store_id:
return

logger.error("token secret {}".format(event.token_secret_id))
secret = self.model.get_secret(id=event.token_secret_id)
secret_content = secret.get_content()
token = event.token
if event.token_secret_id:
logger.error("token secret {}".format(event.token_secret_id))
secret = self.model.get_secret(id=event.token_secret_id)
secret_content = secret.get_content()
token = secret_content["token"]

args = {
"openfga_host": event.address,
"openfga_port": event.port,
"openfga_scheme": event.scheme,
"openfga_store": event.store_id,
"openfga_token": secret_content["token"],
"openfga_token": token,
}

with open(self._env_filename("openfga"), "wt") as f:
Expand Down

0 comments on commit 9a6b919

Please sign in to comment.