mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-06-28 06:49:36 +00:00
cleanups
This commit is contained in:
parent
5b34b6da86
commit
fb0ce5892b
4 changed files with 21 additions and 13 deletions
|
@ -37,7 +37,7 @@ type Client struct {
|
||||||
metadataKeySettings MetadataKeySettings
|
metadataKeySettings MetadataKeySettings
|
||||||
|
|
||||||
// Server Settings for password expiry
|
// 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.
|
// 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 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setPasswordExpirySettings Gets and configures the Client to use the password expiry plugin
|
// setPasswordExpirySettings fetches and configures the Client to use the password expiry plugin
|
||||||
func (c *Client) setPasswordExpirySettings(ctx context.Context, settings *ServerSettingsResponse) error {
|
func (c *Client) setPasswordExpirySettings(ctx context.Context, settings *ServerSettingsResponse) error {
|
||||||
if settings.Passbolt.IsPluginEnabled("passwordExpiry") && settings.Passbolt.IsPluginEnabled("passwordExpiryPolicies") {
|
if settings.Passbolt.IsPluginEnabled("passwordExpiry") && settings.Passbolt.IsPluginEnabled("passwordExpiryPolicies") {
|
||||||
c.log("Server has password expiry plugin enabled.")
|
c.log("Server has password expiry plugin enabled.")
|
||||||
passwordExpirySettings, err := c.GetServerPasswordExpirySettings(ctx)
|
passwordExpirySettings, err := c.getServerPasswordExpirySettings(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Getting Password Expiry Settings: %w", err)
|
return fmt.Errorf("Getting Password Expiry Settings: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.log("passwordExpirySettings: %+v", passwordExpirySettings)
|
c.log("passwordExpirySettings: %+v", passwordExpirySettings)
|
||||||
c.PasswordExpirySettings = *passwordExpirySettings
|
c.passwordExpirySettings = *passwordExpirySettings
|
||||||
} else {
|
} else {
|
||||||
c.log("Server has password expiry plugin disabled or not installed.")
|
c.log("Server has password expiry plugin disabled or not installed.")
|
||||||
c.PasswordExpirySettings = getDefaultPasswordExpirySettings()
|
c.passwordExpirySettings = getDefaultPasswordExpirySettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -262,3 +262,8 @@ func (c *Client) setPasswordExpirySettings(ctx context.Context, settings *Server
|
||||||
func (c *Client) GetPGPHandle() *crypto.PGPHandle {
|
func (c *Client) GetPGPHandle() *crypto.PGPHandle {
|
||||||
return c.pgp
|
return c.pgp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPasswordExpirySettings returns the password expiry settings for the client
|
||||||
|
func (c *Client) GetPasswordExpirySettings() PasswordExpirySettings {
|
||||||
|
return c.passwordExpirySettings
|
||||||
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ type PasswordExpirySettings struct {
|
||||||
ModifiedBy string `json:"modified_by"`
|
ModifiedBy string `json:"modified_by"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetServerPasswordExpirySettings gets the servers password expiry settings
|
// getServerPasswordExpirySettings gets the servers password expiry settings
|
||||||
func (c *Client) GetServerPasswordExpirySettings(ctx context.Context) (*PasswordExpirySettings, error) {
|
func (c *Client) getServerPasswordExpirySettings(ctx context.Context) (*PasswordExpirySettings, error) {
|
||||||
msg, err := c.DoCustomRequestV5(ctx, "GET", "/password-expiry/settings.json", nil, nil)
|
msg, err := c.DoCustomRequestV5(ctx, "GET", "/password-expiry/settings.json", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -100,8 +100,9 @@ func CreateResourceV5(ctx context.Context, c *api.Client, folderParentID, name,
|
||||||
}
|
}
|
||||||
resource.Secrets = []api.Secret{{Data: encSecretData}}
|
resource.Secrets = []api.Secret{{Data: encSecretData}}
|
||||||
|
|
||||||
if c.PasswordExpirySettings.DefaultExpiryPeriod != 0 {
|
passwordExpirySettings := c.GetPasswordExpirySettings()
|
||||||
expiry := time.Now().Add(time.Hour * 24 * time.Duration(c.PasswordExpirySettings.DefaultExpiryPeriod))
|
if passwordExpirySettings.DefaultExpiryPeriod != 0 {
|
||||||
|
expiry := time.Now().Add(time.Hour * 24 * time.Duration(passwordExpirySettings.DefaultExpiryPeriod))
|
||||||
resource.Expired = &api.Time{Time: expiry}
|
resource.Expired = &api.Time{Time: expiry}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,8 +161,9 @@ func CreateResourceV4(ctx context.Context, c *api.Client, folderParentID, name,
|
||||||
}
|
}
|
||||||
resource.Secrets = []api.Secret{{Data: encSecretData}}
|
resource.Secrets = []api.Secret{{Data: encSecretData}}
|
||||||
|
|
||||||
if c.PasswordExpirySettings.DefaultExpiryPeriod != 0 {
|
passwordExpirySettings := c.GetPasswordExpirySettings()
|
||||||
expiry := time.Now().Add(time.Hour * 24 * time.Duration(c.PasswordExpirySettings.DefaultExpiryPeriod))
|
if passwordExpirySettings.DefaultExpiryPeriod != 0 {
|
||||||
|
expiry := time.Now().Add(time.Hour * 24 * time.Duration(passwordExpirySettings.DefaultExpiryPeriod))
|
||||||
resource.Expired = &api.Time{Time: expiry}
|
resource.Expired = &api.Time{Time: expiry}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -377,8 +377,9 @@ func UpdateResource(ctx context.Context, c *api.Client, resourceID, name, userna
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if resource.Expired != nil && c.PasswordExpirySettings.AutomaticUpdate {
|
passwordExpirySettings := c.GetPasswordExpirySettings()
|
||||||
expiry := time.Now().Add(time.Hour * 24 * time.Duration(c.PasswordExpirySettings.DefaultExpiryPeriod))
|
if resource.Expired != nil && passwordExpirySettings.AutomaticUpdate {
|
||||||
|
expiry := time.Now().Add(time.Hour * 24 * time.Duration(passwordExpirySettings.DefaultExpiryPeriod))
|
||||||
newResource.Expired = &api.Time{expiry}
|
newResource.Expired = &api.Time{expiry}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue