Skip to content

[DPE-8863] Custom username and prefixes for v1#258

Open
dragomirp wants to merge 26 commits intomainfrom
dpe-8863-username-prefixes
Open

[DPE-8863] Custom username and prefixes for v1#258
dragomirp wants to merge 26 commits intomainfrom
dpe-8863-username-prefixes

Conversation

@dragomirp
Copy link
Copy Markdown
Contributor

@dragomirp dragomirp commented Feb 11, 2026

Port of #239 and #245 for DPLv1

  • Add custom username support
  • Add prefix resources support

@dragomirp dragomirp changed the title [DPE-8863] username prefixes [DPE-8863] username prefixes v1 Feb 11, 2026
@dragomirp dragomirp changed the title [DPE-8863] username prefixes v1 [DPE-8863] Custom username and prefixes for v1 Feb 12, 2026
@dragomirp dragomirp force-pushed the dpe-8863-username-prefixes branch from 0bd5433 to 3f798ce Compare February 12, 2026 14:46
@dragomirp dragomirp force-pushed the dpe-8863-username-prefixes branch from 3f798ce to f61dd66 Compare February 12, 2026 16:02
@dragomirp dragomirp force-pushed the dpe-8863-username-prefixes branch from 72c3e5a to 371fba2 Compare February 12, 2026 23:09
@dragomirp dragomirp force-pushed the dpe-8863-username-prefixes branch 2 times, most recently from 83c0c4c to 0b29a12 Compare February 14, 2026 17:52
@dragomirp dragomirp changed the base branch from main to ci-fixes February 14, 2026 18:04
@dragomirp dragomirp force-pushed the dpe-8863-username-prefixes branch 11 times, most recently from a94372a to 66af6bc Compare February 15, 2026 02:44
@dragomirp dragomirp force-pushed the dpe-8863-username-prefixes branch 3 times, most recently from bddfdd4 to 4a7774a Compare March 10, 2026 20:47
@dragomirp dragomirp force-pushed the dpe-8863-username-prefixes branch 8 times, most recently from 2ee2a5e to 97a4f1a Compare March 13, 2026 23:11
@dragomirp dragomirp force-pushed the dpe-8863-username-prefixes branch from 97a4f1a to 557065c Compare March 14, 2026 11:51
Comment on lines +839 to +848
try:
secret = repository.get_secret(
secret_group, secret_uri=secret_uri, short_uuid=short_uuid
)
except SecretNotFoundError:
# v0 deletes the requested entity secret
if secret_group == "requested-entity":
logger.debug("Missing requested entity secret")
continue
raise
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

v0 will delete the helper secret once the relation was established.

mtls_cert: MtlsSecretStr = Field(default=None)
secret_requested_entity: SecretString | None = Field(
default=None,
validation_alias=AliasChoices("requested-entity-secret", "secret-requested-entity"),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should match both the old and new secret field.

entity_name: EntitySecretStr = Field(default=None)
entity_password: EntitySecretStr = Field(default=None)
version: str | None = Field(default=None)
prefix_resources: str | None = Field(default=None)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanted to use PlainSerializer to sort the CSV list, but it seems that the field_info.annotation in OptionalSecrets traps other annotations as well. Leaving it be for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting.
Maybe we can add just a field serializer for this one in this class ? Or that prevents it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What I tried to do was:

prefix_resources: Annotated[str | None, PlainSerializer(csv_list_sorter)] = Field(default=None)

With the serialiser being:

def csv_list_sorter(el: str | None) -> str | None:
"""Serialization sorter for comma separated lists."""
if el:
return ",".join(sorted(el.split(",")))
return None

But then the field got turned into a secret. I guess that the OptionalSecretStr alias traps this, since they are both str | None, but didn't dig further, since autosorting is nice to have, but not strictly necessary.

"startup": "enabled",
"environment": {
"PGDATA": "/var/lib/postgresql/data/pgdata",
"PGDATA": "/var/lib/postgresql/data/pgdata/data",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For Canonical k8s compatibility (non-empty volume is provided).

@dragomirp dragomirp marked this pull request as ready for review March 14, 2026 15:50
Comment on lines +2664 to +2667
if response.prefix_resources:
self.interface.repository(relation_id).write_field(
"prefix-databases", response.prefix_resources
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way to inject this field?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, this is because the field is renamed ?
Then probably we can do like we do for the other resources: here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the original_field is still written in the provider response with write_field here:

old_name = request_model.original_field
request_model.request_id = None # For safety, let's ensure that we don't have a model.
self._handle_event(event, repository, request_model)
logger.info(
f"Patching databag for v0 compatibility: replacing 'resource' by '{old_name}'"
)
self.interface.repository(
event.relation.id,
).write_field(old_name, request_model.resource)

Copy link
Copy Markdown
Contributor

@Gu1nness Gu1nness left a comment

Choose a reason for hiding this comment

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

All seems good.
Let's investigate on the CSV ordering.
For the prefix-database vs prefix-resource let's try like we do for the resource field.
Same pattern, a dedicated field that we don't serialize just to store the original field name.

entity_name: EntitySecretStr = Field(default=None)
entity_password: EntitySecretStr = Field(default=None)
version: str | None = Field(default=None)
prefix_resources: str | None = Field(default=None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting.
Maybe we can add just a field serializer for this one in this class ? Or that prevents it?

Comment on lines +2664 to +2667
if response.prefix_resources:
self.interface.repository(relation_id).write_field(
"prefix-databases", response.prefix_resources
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, this is because the field is renamed ?
Then probably we can do like we do for the other resources: here

Comment thread lib/charms/data_platform_libs/v1/data_interfaces.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants