From 0c5cd9152df4fa164e79ef53be369a90001b62b2 Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Wed, 5 Mar 2025 18:12:01 +0100 Subject: [PATCH] Add MetadataTypeSettings to Client, add set function --- api/client.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/api/client.go b/api/client.go index e08609f..767482f 100644 --- a/api/client.go +++ b/api/client.go @@ -31,6 +31,9 @@ type Client struct { userPublicKey string userID string + // Server Settings Determining which Resource Types we can use + metadataTypeSettings MetadataTypeSettings + // used for solving MFA challenges. You can block this to for example wait for user input. // You shouden't run any unrelated API Calls while you are in this callback. // You need to Return the Cookie that Passbolt expects to verify you MFA, usually it is called passbolt_mfa @@ -208,3 +211,26 @@ func (c *Client) GetPublicKey(ctx context.Context) (string, string, error) { } return body.Keydata, privateKeyObj.GetFingerprint(), nil } + +// setMetadataTypeSettings Gets and configures the Client to use the Types the Server wants us to use +func (c *Client) setMetadataTypeSettings(ctx context.Context) error { + settings, err := c.GetServerSettings(ctx) + if err != nil { + return fmt.Errorf("Getting Server Settings: %w", err) + } + + if settings.Passbolt.IsPluginEnabled("metadata") { + c.log("Server has metadata plugin enabled, is v5 or Higher") + metadataTypeSettings, err := c.GetMetadataTypeSettings(ctx) + if err != nil { + return fmt.Errorf("Getting Metadata Type Settings: %w", err) + } + + c.log("metadataTypeSettings: %+v", metadataTypeSettings) + c.metadataTypeSettings = *metadataTypeSettings + } else { + c.log("Server has metadata plugin disabled or not installed, Server is v4") + c.metadataTypeSettings = getV4DefaultMetadataTypeSettings() + } + return nil +}