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

feat(db): Add db #6

Merged
merged 55 commits into from
Oct 1, 2024
Merged

feat(db): Add db #6

merged 55 commits into from
Oct 1, 2024

Conversation

merkata
Copy link
Collaborator

@merkata merkata commented Jul 23, 2024

Applicable spec:

Overview

Adds a db relation and handling.

Rationale

Juju Events Changes

Module Changes

Library Changes

Checklist

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

license-eye has checked 40 files.

Valid Invalid Ignored Fixed
17 1 22 0
Click to see the invalid file list
  • tests/unit/test_irc.py
Use this command to fix any missing license headers
```bash

docker run -it --rm -v $(pwd):/github/workspace apache/skywalking-eyes header fix

</details>

tests/unit/test_irc.py Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/database.py Outdated Show resolved Hide resolved
src/database.py Outdated
data["POSTGRES_PASSWORD"],
data["POSTGRES_DB"],
):
return default
Copy link

@amandahla amandahla Jul 23, 2024

Choose a reason for hiding this comment

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

Will IRC bridge fail if the default is returned?

Choose a reason for hiding this comment

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

Same comment on my side as before

src/database.py Outdated

return data

def is_relation_ready(self) -> bool:

Choose a reason for hiding this comment

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

This is interesting.
Most of our charms are relying on some kind of "database is not None" (at least is my impression).
The only concern here is that by any chance this check is not done before using the relation data, will be hard to tell why there is no database configuration as expected.

Choose a reason for hiding this comment

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

This should be managed through a ValidationError when the pydantic object is created more than an explicit is ready

src/irc.py Outdated Show resolved Hide resolved
src/irc.py Outdated Show resolved Hide resolved
src/irc.py Outdated Show resolved Hide resolved
src/database.py Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/irc.py Outdated Show resolved Hide resolved
src/database.py Outdated Show resolved Hide resolved
src/database.py Outdated Show resolved Hide resolved
src/irc.py Outdated
Comment on lines 192 to 194
exec_process = subprocess.run(
pem_create_command, shell=True, check=True, capture_output=True)
)

Choose a reason for hiding this comment

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

Any exception that we should catch here ?

src/irc.py Outdated Show resolved Hide resolved
src/irc.py Outdated Show resolved Hide resolved
src/irc.py Outdated Show resolved Hide resolved
src/charm.py Show resolved Hide resolved
merkata and others added 3 commits July 23, 2024 22:24
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

license-eye has checked 45 files.

Valid Invalid Ignored Fixed
19 3 23 0
Click to see the invalid file list
  • templates/config.yaml
  • templates/matrix-appservice-irc.service
  • templates/matrix-appservice-irc.target
Use this command to fix any missing license headers
```bash

docker run -it --rm -v $(pwd):/github/workspace apache/skywalking-eyes header fix

</details>

config.yaml Outdated
@@ -0,0 +1,21 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

templates/config.yaml Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

license-eye has checked 49 files.

Valid Invalid Ignored Fixed
22 3 24 0
Click to see the invalid file list
  • templates/matrix-appservice-irc.service
  • templates/matrix-appservice-irc.target
  • tests/unit/test_charm_types.py
Use this command to fix any missing license headers
```bash

docker run -it --rm -v $(pwd):/github/workspace apache/skywalking-eyes header fix

</details>

@@ -0,0 +1,26 @@
import pytest
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import pytest
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
import pytest

metadata.yaml Outdated

Choose a reason for hiding this comment

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

You should merge charmcraft.yaml and metadata.yaml in charmcraft.yaml

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm facing an issue here when merging:

Bad charmcraft.yaml content:
- input should be None (in field 'issues')
- extra inputs are not permitted (in field 'display-name')
- extra inputs are not permitted (in field 'docs')
- extra inputs are not permitted (in field 'maintainers')
- extra inputs are not permitted (in field 'source')

Might leave it as is for now (stumbled upon this).

requirements.txt Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/database_observer.py Show resolved Hide resolved
src/irc.py Outdated Show resolved Hide resolved
src/irc.py Outdated Show resolved Hide resolved
tests/integration/test_charm.py Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
src/charm.py Outdated Show resolved Hide resolved
+ "-outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048",
]
logger.info("Creating PEM file for IRC bridge.")
subprocess.run(pem_create_command, shell=True, check=True, capture_output=True) # nosec

Choose a reason for hiding this comment

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

What did we say about that one ? I see the comment is closed but without being addressed

src/irc.py Outdated Show resolved Hide resolved
src/irc.py Outdated Show resolved Hide resolved
"""Exception raised when unable to stop the service."""


class InstallError(exceptions.SnapError):
"""Exception raised when unable to install dependencies for the service."""


class IRCBRidgeService:
class IRCBridgeService:

Choose a reason for hiding this comment

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

There are not instance or class attributes nor constructor. I'm wondering if this shouldn't simply be a module ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It could, that's in spirit of the bind-operator, it has a similar class (BindService) without a constructor or attributes. Propose to leave it as is for now.

Choose a reason for hiding this comment

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

Ok, but let's track the change in a ticket

"-c",
f"[[ -f {IRC_BRIDGE_REGISTRATION_FILE_PATH} ]] || "
f"matrix-appservice-irc -r -f {IRC_BRIDGE_REGISTRATION_FILE_PATH}"
f" -u https://{matrix.host}:{IRC_BRIDGE_HEALTH_PORT} "

Choose a reason for hiding this comment

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

How do we intend to route traffic to the bridge machine ?
If they share the same host as matrix, then we need a reverse proxy in front of both that will route based on path or port since the hostname will resolve to the same IP for both synapse and the bridge

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well spotted, this is not correct, it should be the address where the Matrix homeserver can contact the bridge. It can be a config option if we use an FQDN or an IP that is reachable from Matrix, wdyt?

Choose a reason for hiding this comment

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

Yeap that's tricky... the machine needs either to be accessible publicly or internally, and it should support HTTPS meaning you need either a TLS termination or support the TLS relation in the bridge :\

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Depends on the communication flow, I think Matrix and the bridge talk to each other, soo it could be private? And the public part between the IRC network and the bridge happens over the Mattix homeserver. Need to check, you raised a very good point here.

Copy link
Contributor

Test coverage for 157d588

Name                       Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------------------------
src/charm.py                  57     57      2      0     0%   7-110
src/charm_types.py            37      2      8      2    91%   102, 106
src/constants.py              20      0      0      0   100%
src/database_observer.py      23      2      2      1    88%   52, 63
src/exceptions.py             12      2      0      0    83%   52, 68
src/irc.py                    90      6     14      1    93%   140-142, 195->197, 202-204
src/matrix_observer.py        13     13      0      0     0%   6-42
----------------------------------------------------------------------
TOTAL                        252     82     26      4    68%

Static code analysis report

Run started:2024-09-25 13:27:01.084269

Test results:
  No issues identified.

Code scanned:
  Total lines of code: 1157
  Total lines skipped (#nosec): 7
  Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 0

Run metrics:
  Total issues (by severity):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
  Total issues (by confidence):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
Files skipped (0):

@merkata merkata merged commit 3ea9512 into main Oct 1, 2024
14 of 16 checks passed
@merkata merkata deleted the feat/add-db branch October 1, 2024 07:38
@merkata
Copy link
Collaborator Author

merkata commented Oct 1, 2024

Merged as discussed - follow up work in the feat/add-plugins-lib where the rest of the comments are addressed. The failing test is due to a snap issue that is waiting to be resolved via a manual approval in the snap store (usage of a privileged interface).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants