Skip to content

PB-50163 - Go-Cli : schema-driven resource type support#67

Open
cedricherzog-passbolt wants to merge 11 commits intopassbolt:v5from
cedricherzog-passbolt:v5-wrapper
Open

PB-50163 - Go-Cli : schema-driven resource type support#67
cedricherzog-passbolt wants to merge 11 commits intopassbolt:v5from
cedricherzog-passbolt:v5-wrapper

Conversation

@cedricherzog-passbolt
Copy link

@cedricherzog-passbolt cedricherzog-passbolt commented Dec 6, 2025

Summary

Replace hardcoded per-type structs and switch statements with a generic,
schema-driven approach using map[string]any for metadata and secret data.
This enables support for any resource type automatically (including
v5-custom-fields from Passbolt 5.3) without touching SDK code.

  • Add IsSecretString(), IsV5(), HasSecretField(), HasMetadataField()
    schema introspection methods on ResourceType
  • Rewrite Resource wrapper to use metadataFields/secretFields maps
    instead of discrete fields, with generic accessors (MetadataFields(),
    SecretFields(), MetadataField(), SecretField())
  • Add CreateResourceGeneric(ctx, c, slug, folderParentID, metadataFields, secretFields)
    and UpdateResourceGeneric(ctx, c, resourceID, metadataUpdates, secretUpdates)
  • Refactor GetResourceFromDataWithOptions to eliminate the 8-branch
    switch, now uses Metadata != "" for v4/v5 detection and
    IsSecretString() for secret format detection
  • Replace slug-based check in validateSecretData with IsSecretString()
  • Add v5-custom-fields fallback schema
  • Remove type-specific structs (SecretDataTypeV5Default,
    ResourceMetadataTypeV5Default, etc.), keep only Secret,
    SecretDataTOTP, and encryption/decryption functions

Existing public functions (CreateResource, UpdateResource, GetResource,
GetResourceFromData) are preserved as wrappers that delegate to the
new generic implementations.

@cedricherzog-passbolt cedricherzog-passbolt marked this pull request as draft December 6, 2025 17:29
@speatzle
Copy link
Collaborator

I had a look, I don't think the Resource wrapper should be separate fields for username, description, password and so on.
I think a better approach would be: Have 2 maps, one for metadata and one for the Secret just like it is Server Side.

We already have a Problem with the description which sometimes becomes the Note with v5.
And with new Resource types which may not have any of these, a map would work much better.

We can have generic access functions which could work with any resource type and we can check if the requested Field exists in the Jsonschema from the Server allowing for custom resource types. Adding functions which get the often used fields and return an error if they don't exist can still be done this way.

This also eliminates all of ensureBasicFieldsParsed Since we don't need to have specific logic for resource Types.

Any thought?

@CLAassistant
Copy link

CLAassistant commented Mar 17, 2026

CLA assistant check
All committers have signed the CLA.

@cedricherzog-passbolt cedricherzog-passbolt force-pushed the v5-wrapper branch 2 times, most recently from eba171e to 0abefb9 Compare March 17, 2026 17:17
@cedricherzog-passbolt cedricherzog-passbolt changed the title Create resource wrapper feat: schema-driven resource type support with dynamic field maps Mar 17, 2026
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
…ardless of v4/v5 schema differences

Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
@cedricherzog-passbolt cedricherzog-passbolt marked this pull request as ready for review March 18, 2026 13:57
@cedricherzog-passbolt cedricherzog-passbolt changed the title feat: schema-driven resource type support with dynamic field maps PB-50163 - Go-Cli : schema-driven resource type support Mar 18, 2026
Signed-off-by: Cédric HERZOG <cedric.herzog@passbolt.com>
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