Compare commits

..

1 commit

Author SHA1 Message Date
Nelson Isioma
1704d5387c
Merge 5b34b6da86 into ffcbf94cf4 2025-06-23 02:47:02 +01:00
4 changed files with 13 additions and 21 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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}
}

View file

@ -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}
}