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

Revisited add-admin action #241

Merged
merged 93 commits into from
Jun 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
38900b0
drafted approach to re-do add-admin user action
codethulu May 2, 2024
7a56ca3
fixed linting, small bugs, typos
codethulu May 3, 2024
25f27f5
fixes
codethulu May 4, 2024
86745c4
added patches
codethulu May 14, 2024
4edeef8
blank
codethulu May 15, 2024
9608a39
feat: singular rake file to have both create user and promtoe admin a…
codethulu May 15, 2024
af7cc0a
fixed tests and linting
codethulu May 15, 2024
72bf7db
re-added check to rock
codethulu May 15, 2024
b450e82
Merge branch 'main' into feat/ISD-1064
codethulu May 15, 2024
a2e900f
bug fixed: changed rockcraft to patch rake.patch
codethulu May 15, 2024
9f6c673
fixes
codethulu May 16, 2024
76f168d
fixed bug in lp patch
codethulu May 16, 2024
6846e2e
fixed rock
codethulu May 17, 2024
1747d3c
force enable https
codethulu May 22, 2024
3b9e437
fixes
codethulu May 22, 2024
b2d0abb
minor changes to rake file
codethulu May 22, 2024
f6baa42
blank
codethulu May 22, 2024
361fdfd
fix
codethulu May 22, 2024
ac18402
using admin:create instead
codethulu May 23, 2024
e922412
relevant changes
codethulu May 23, 2024
00720d4
removed unnecessary line
codethulu May 23, 2024
bfbff5e
minor fixes
codethulu May 24, 2024
8cd79e3
fixed event set results typo
codethulu May 24, 2024
68c90e4
using secrets instead of random
codethulu May 24, 2024
0010a60
replace email with user
codethulu May 24, 2024
13b2d2b
blank
codethulu May 26, 2024
bc94146
changed config
codethulu May 26, 2024
df3ef14
Update config.yaml
codethulu May 27, 2024
be80aae
Update conftest.py
codethulu May 27, 2024
d95c61c
Update conftest.py
codethulu May 27, 2024
fb1a9db
updat3ed ops
codethulu May 28, 2024
4c43eaf
refactor test
codethulu May 28, 2024
6be5dab
Merge branch 'main' into feat/ISD-1064
codethulu May 29, 2024
bfd05e5
resolved
codethulu May 29, 2024
14a94b1
refactored test
codethulu May 29, 2024
9419b10
added saml testing module
codethulu May 29, 2024
3e4fa46
parameters
codethulu May 29, 2024
db9d829
updated workflow
codethulu May 30, 2024
8933ba4
updated descriptions
codethulu May 30, 2024
992a6c8
Merge branch 'main' into feat/ISD-1064
codethulu May 30, 2024
7b44ed2
blank
codethulu May 30, 2024
42f99f3
Update requirements.txt
codethulu May 30, 2024
88bccca
Update actions.yaml
codethulu May 31, 2024
97bfa31
addressed changes
codethulu Jun 3, 2024
879cdee
make sure action fails
codethulu Jun 3, 2024
1e0bed2
linting
codethulu Jun 3, 2024
ba37983
linting fix
codethulu Jun 3, 2024
d70cd85
linting
codethulu Jun 3, 2024
cb2b7f3
blank
codethulu Jun 4, 2024
5bccdf9
updated rockcraft/patches
codethulu Jun 5, 2024
4e29b90
fixes, new integration test and fix for unit test
codethulu Jun 5, 2024
10328ed
linting fixes
codethulu Jun 5, 2024
ea6f495
addressed comments
codethulu Jun 6, 2024
8930351
using response.ok
codethulu Jun 6, 2024
9664cbf
Merge branch 'main' into feat/ISD-1064
codethulu Jun 6, 2024
373a6fe
readded touch
codethulu Jun 6, 2024
2fc84da
rock and unit test
codethulu Jun 6, 2024
fcc9fa3
uhm
codethulu Jun 6, 2024
d801445
blank
codethulu Jun 6, 2024
5c5c212
Dblank
codethulu Jun 6, 2024
af951d1
addressed changes, fixed linting
codethulu Jun 6, 2024
b9012a8
fixed unit test
codethulu Jun 7, 2024
c56b177
updated rock
codethulu Jun 7, 2024
107c780
added user activation
codethulu Jun 10, 2024
952b9a6
fixed linting
codethulu Jun 10, 2024
4abe096
improved and fixed unit test
codethulu Jun 10, 2024
b1a736f
improved and fixed unit test
codethulu Jun 10, 2024
589dad6
fixes
codethulu Jun 10, 2024
b0853d9
added timeout
codethulu Jun 10, 2024
eb30e65
Merge branch 'main' into feat/ISD-1064
codethulu Jun 10, 2024
4ad16cd
flagged test upgrade
codethulu Jun 11, 2024
1bc23b4
activate
codethulu Jun 11, 2024
e26c0c9
fixed integration test
codethulu Jun 11, 2024
4ba9a42
changed cindition, added some logging statements
codethulu Jun 12, 2024
814cb2c
Update rockcraft.yaml
codethulu Jun 12, 2024
45d0bb7
added try except, figure out whats failing in ci
codethulu Jun 12, 2024
80e3755
wait for idle
codethulu Jun 12, 2024
a4bf637
pinned redis channel to 28/edge
codethulu Jun 12, 2024
5e60183
latest/stable
codethulu Jun 12, 2024
f4c5ab7
rev 28
codethulu Jun 12, 2024
300d64f
moved user testing to separate module
codethulu Jun 12, 2024
a2c0d7d
addressed changes
codethulu Jun 13, 2024
3121bc5
fixed unit test exit code
codethulu Jun 13, 2024
125a24b
Update rockcraft.yaml
codethulu Jun 14, 2024
1c0bc3f
fixed unit tests
codethulu Jun 14, 2024
db34e09
fixed unit tests
codethulu Jun 14, 2024
de4b0ac
fixed all unit tests
codethulu Jun 14, 2024
2a7c8b9
changes
codethulu Jun 14, 2024
8b74d84
unit test coverage
codethulu Jun 14, 2024
3285716
refactor
codethulu Jun 14, 2024
ef2e9aa
lint
codethulu Jun 14, 2024
79d3e57
raise w/o arguments
codethulu Jun 14, 2024
6df0442
removed arguments of raise
codethulu Jun 14, 2024
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
Prev Previous commit
Next Next commit
fixed tests and linting
codethulu committed May 15, 2024

Unverified

This user has not yet uploaded their public signing key.
commit af7cc0a76cc9a9ccb4aa2045c68271fb0901a15e
98 changes: 98 additions & 0 deletions src-docs/charm.py.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!-- markdownlint-disable -->

<a href="../src/charm.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `charm.py`
Charm for Discourse on kubernetes.

**Global Variables**
---------------
- **DEFAULT_RELATION_NAME**
- **DATABASE_NAME**
- **DISCOURSE_PATH**
- **THROTTLE_LEVELS**
- **LOG_PATHS**
- **PROMETHEUS_PORT**
- **REQUIRED_S3_SETTINGS**
- **SCRIPT_PATH**
- **SERVICE_NAME**
- **CONTAINER_NAME**
- **CONTAINER_APP_USERNAME**
- **SERVICE_PORT**
- **SETUP_COMPLETED_FLAG_FILE**
- **DATABASE_RELATION_NAME**


---

## <kbd>class</kbd> `DiscourseCharm`
Charm for Discourse on kubernetes.

<a href="../src/charm.py#L92"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `__init__`

```python
__init__(*args)
```

Initialize defaults and event handlers.


---

#### <kbd>property</kbd> app

Application that this unit is part of.

---

#### <kbd>property</kbd> charm_dir

Root directory of the charm as it is running.

---

#### <kbd>property</kbd> config

A mapping containing the charm's config and current values.

---

#### <kbd>property</kbd> meta

Metadata of this charm.

---

#### <kbd>property</kbd> model

Shortcut for more simple access the model.

---

#### <kbd>property</kbd> unit

Unit that this execution is responsible for.




---

## <kbd>class</kbd> `MissingRedisRelationDataError`
Custom exception to be raised in case of malformed/missing redis relation data.





---

## <kbd>class</kbd> `S3Info`
S3Info(enabled, region, bucket, endpoint)





79 changes: 79 additions & 0 deletions src-docs/database.py.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!-- markdownlint-disable -->

<a href="../src/database.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `database.py`
Provide the DatabaseObserver class to handle database relation and state.

**Global Variables**
---------------
- **DATABASE_NAME**


---

## <kbd>class</kbd> `DatabaseHandler`
The Database relation observer.

<a href="../src/database.py#L18"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `__init__`

```python
__init__(charm: CharmBase, relation_name)
```

Initialize the observer and register event handlers.



**Args:**

- <b>`charm`</b>: The parent charm to attach the observer to.


---

#### <kbd>property</kbd> model

Shortcut for more simple access the model.



---

<a href="../src/database.py#L33"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `get_relation_data`

```python
get_relation_data() → Dict[str, str]
```

Get database data from relation.



**Returns:**

- <b>`Dict`</b>: Information needed for setting environment variables. Returns default if the relation data is not correctly initialized.

---

<a href="../src/database.py#L79"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `is_relation_ready`

```python
is_relation_ready() → bool
```

Check if the relation is ready.



**Returns:**

- <b>`bool`</b>: returns True if the relation is ready.


22 changes: 12 additions & 10 deletions src/charm.py
Original file line number Diff line number Diff line change
@@ -703,30 +703,31 @@ def _on_add_admin_user_action(self, event: ActionEvent) -> None:
"""
container = self.unit.get_container(CONTAINER_NAME)

email = event.params["email"]

if not container.can_connect():
event.fail("Unable to connect to container, container is not ready")
return

self._create_user(event)
self._create_user(event)

process = container.exec(
[
os.path.join(DISCOURSE_PATH, "bin/bundle"),
"exec",
"rake",
"admin:promote",
event.params["email"],
email,
],
working_dir=DISCOURSE_PATH,
user=CONTAINER_APP_USERNAME,
environment=self._create_discourse_environment_settings(),
)
try:
process.wait_output()
event.set_results({"user": f"{event.params["email"]}"})
event.set_results(email)
except ExecError as ex:
event.fail(
f"Failed to make user with email {event.params["email"]} an admin: {ex.stdout}" # type: ignore
f"Failed to make user with email {email} an admin: {ex.stdout}" # type: ignore
)

def _create_user(self, event: ActionEvent):
@@ -735,16 +736,19 @@ def _create_user(self, event: ActionEvent):
Args:
event: Event triggering the create user action.
"""

container = self.unit.get_container(CONTAINER_NAME)

email = event.params["email"]
password = event.params["password"]

process = container.exec(
[
os.path.join(DISCOURSE_PATH, "bin/bundle"),
"exec",
"rake",
"users:create",
],
stdin=f"{event.params["email"]}\n{event.params["password"]}\n",
stdin=f"{email}\n{password}\n",
working_dir=DISCOURSE_PATH,
user=CONTAINER_APP_USERNAME,
environment=self._create_discourse_environment_settings(),
@@ -753,9 +757,7 @@ def _create_user(self, event: ActionEvent):
try:
process.wait_output()
except ExecError as ex:
event.fail(
f"Failed to create user with email {email}: {ex.stdout}" # type: ignore
)
event.fail(f"Failed to create user with email {email}: {ex.stdout}") # type: ignore

def _config_force_https(self) -> None:
"""Config Discourse to force_https option based on charm configuration."""
2 changes: 1 addition & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
@@ -373,7 +373,7 @@ def bundle_handler(args: ops.testing.ExecArgs) -> None:
args.environment != harness.charm._create_discourse_environment_settings()
or args.working_dir != DISCOURSE_PATH
or args.user != "_daemon_"
or args.stdin != f"{email}\n{password}\n{password}\n"
or args.stdin != f"{email}\n{password}\n"
or args.timeout != 60
):
raise ValueError(f"{args.command} wasn't made with the correct args.")