diff --git a/api/client.go b/api/client.go index ce85767..e4da693 100644 --- a/api/client.go +++ b/api/client.go @@ -37,7 +37,7 @@ type Client struct { metadataKeySettings MetadataKeySettings // Server Settings for password expiry - passwordExpirySettings PasswordExpirySettings + PasswordExpirySettings PasswordExpirySettings // 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. @@ -239,20 +239,20 @@ func (c *Client) setMetadataTypeSettings(ctx context.Context, settings *ServerSe return nil } -// setPasswordExpirySettings fetches and configures the Client to use the password expiry plugin +// setPasswordExpirySettings Gets and configures the Client to use the password expiry plugin func (c *Client) setPasswordExpirySettings(ctx context.Context, settings *ServerSettingsResponse) error { if settings.Passbolt.IsPluginEnabled("passwordExpiry") && settings.Passbolt.IsPluginEnabled("passwordExpiryPolicies") { c.log("Server has password expiry plugin enabled.") - passwordExpirySettings, err := c.getServerPasswordExpirySettings(ctx) + passwordExpirySettings, err := c.GetServerPasswordExpirySettings(ctx) if err != nil { return fmt.Errorf("Getting Password Expiry Settings: %w", err) } c.log("passwordExpirySettings: %+v", passwordExpirySettings) - c.passwordExpirySettings = *passwordExpirySettings + c.PasswordExpirySettings = *passwordExpirySettings } else { c.log("Server has password expiry plugin disabled or not installed.") - c.passwordExpirySettings = getDefaultPasswordExpirySettings() + c.PasswordExpirySettings = getDefaultPasswordExpirySettings() } return nil @@ -262,8 +262,3 @@ func (c *Client) setPasswordExpirySettings(ctx context.Context, settings *Server func (c *Client) GetPGPHandle() *crypto.PGPHandle { return c.pgp } - -// GetPasswordExpirySettings returns the password expiry settings for the client -func (c *Client) GetPasswordExpirySettings() PasswordExpirySettings { - return c.passwordExpirySettings -} diff --git a/api/password_expiry.go b/api/password_expiry.go index a375b6e..b5c756d 100644 --- a/api/password_expiry.go +++ b/api/password_expiry.go @@ -20,8 +20,8 @@ type PasswordExpirySettings struct { ModifiedBy string `json:"modified_by"` } -// getServerPasswordExpirySettings gets the servers password expiry settings -func (c *Client) getServerPasswordExpirySettings(ctx context.Context) (*PasswordExpirySettings, error) { +// GetServerPasswordExpirySettings gets the servers password expiry settings +func (c *Client) GetServerPasswordExpirySettings(ctx context.Context) (*PasswordExpirySettings, error) { msg, err := c.DoCustomRequestV5(ctx, "GET", "/password-expiry/settings.json", nil, nil) if err != nil { return nil, err diff --git a/helper/resource_create.go b/helper/resource_create.go index e8c98db..88fffbb 100644 --- a/helper/resource_create.go +++ b/helper/resource_create.go @@ -100,9 +100,8 @@ func CreateResourceV5(ctx context.Context, c *api.Client, folderParentID, name, } resource.Secrets = []api.Secret{{Data: encSecretData}} - passwordExpirySettings := c.GetPasswordExpirySettings() - if passwordExpirySettings.DefaultExpiryPeriod != 0 { - expiry := time.Now().Add(time.Hour * 24 * time.Duration(passwordExpirySettings.DefaultExpiryPeriod)) + if c.PasswordExpirySettings.DefaultExpiryPeriod != 0 { + expiry := time.Now().Add(time.Hour * 24 * time.Duration(c.PasswordExpirySettings.DefaultExpiryPeriod)) resource.Expired = &api.Time{Time: expiry} } @@ -161,9 +160,8 @@ func CreateResourceV4(ctx context.Context, c *api.Client, folderParentID, name, } resource.Secrets = []api.Secret{{Data: encSecretData}} - passwordExpirySettings := c.GetPasswordExpirySettings() - if passwordExpirySettings.DefaultExpiryPeriod != 0 { - expiry := time.Now().Add(time.Hour * 24 * time.Duration(passwordExpirySettings.DefaultExpiryPeriod)) + if c.PasswordExpirySettings.DefaultExpiryPeriod != 0 { + expiry := time.Now().Add(time.Hour * 24 * time.Duration(c.PasswordExpirySettings.DefaultExpiryPeriod)) resource.Expired = &api.Time{Time: expiry} } diff --git a/helper/resource_update.go b/helper/resource_update.go index 3c6b82b..d91bb0f 100644 --- a/helper/resource_update.go +++ b/helper/resource_update.go @@ -377,9 +377,8 @@ func UpdateResource(ctx context.Context, c *api.Client, resourceID, name, userna }) } - passwordExpirySettings := c.GetPasswordExpirySettings() - if resource.Expired != nil && passwordExpirySettings.AutomaticUpdate { - expiry := time.Now().Add(time.Hour * 24 * time.Duration(passwordExpirySettings.DefaultExpiryPeriod)) + if resource.Expired != nil && c.PasswordExpirySettings.AutomaticUpdate { + expiry := time.Now().Add(time.Hour * 24 * time.Duration(c.PasswordExpirySettings.DefaultExpiryPeriod)) newResource.Expired = &api.Time{expiry} }