Key Lifecycle Rules

A KeyLifecycleRule represents a rule that applies to API keys, GPG keys, and SSH keys (also called User Public Keys) based on their inactivity or age.

Keys that have been unused for the specified number of days will be deleted. SSH keys can also be configured to expire after a specified number of days. SSH key expiration applies only to User Public Keys used for inbound SFTP/SSH login, not Remote Server outbound SSH keys.

List Key Lifecycle Rules

SDK Method

keylifecyclerule.List()

Return Object

[]*KeyLifecycleRule

Authorization Requirement

Requires a Site-Wide API key, or a User API key or session from a Site Administrator or a Workspace Administrator for the relevant workspace.

Additional Arguments

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    key_lifecycle_rule "github.com/Files-com/files-sdk-go/v3/keylifecyclerule"
)

keyLifecycleRuleIterator, err := key_lifecycle_rule.List(files_sdk.KeyLifecycleRuleListParams{})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

for keyLifecycleRuleIterator.Next() {
    keyLifecycleRule := keyLifecycleRuleIterator.keyLifecycleRule()
}
err = keyLifecycleRuleIterator.Err()
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

Show Key Lifecycle Rule

SDK Method

keylifecyclerule.Find()

Return Object

KeyLifecycleRule

Authorization Requirement

Requires a Site-Wide API key, or a User API key or session from a Site Administrator or a Workspace Administrator for the relevant workspace.

KeyLifecycleRuleFindParams Fields

FieldDescription
Id
int64
Required
Key Lifecycle Rule ID.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    key_lifecycle_rule "github.com/Files-com/files-sdk-go/v3/keylifecyclerule"
)

keyLifecycleRule, err := key_lifecycle_rule.Find(files_sdk.KeyLifecycleRuleFindParams{Id: 1})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

Create Key Lifecycle Rule

SDK Method

keylifecyclerule.Create()

Return Object

KeyLifecycleRule

Authorization Requirement

Requires a Site-Wide API key, or a User API key or session from a Site Administrator or a Workspace Administrator for the relevant workspace.

KeyLifecycleRuleCreateParams Fields

FieldDefaultDescription
ApplyToAllWorkspaces
boolean
falseIf true, a default-workspace rule also applies to keys in all workspaces.
ExpirationDays
int64
Number of days after creation before an SSH key expires. Applies only to SSH keys.
KeyType
string
Key type for which the rule will apply (gpg, ssh, or api).
Possible values: gpg, ssh, api
InactivityDays
int64
Number of days of inactivity before the rule applies.
Name
string
Key Lifecycle Rule name
WorkspaceId
int64
0Workspace ID. 0 means the default workspace.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    key_lifecycle_rule "github.com/Files-com/files-sdk-go/v3/keylifecyclerule"
)

keyLifecycleRule, err := key_lifecycle_rule.Create(files_sdk.KeyLifecycleRuleCreateParams{ApplyToAllWorkspaces: lib.Bool(true)})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

Update Key Lifecycle Rule

SDK Method

keylifecyclerule.Update()

Return Object

KeyLifecycleRule

Authorization Requirement

Requires a Site-Wide API key, or a User API key or session from a Site Administrator or a Workspace Administrator for the relevant workspace.

KeyLifecycleRuleUpdateParams Fields

FieldDescription
Id
int64
Required
Key Lifecycle Rule ID.
ApplyToAllWorkspaces
boolean
If true, a default-workspace rule also applies to keys in all workspaces.
ExpirationDays
int64
Number of days after creation before an SSH key expires. Applies only to SSH keys.
KeyType
string
Key type for which the rule will apply (gpg, ssh, or api).
Possible values: gpg, ssh, api
InactivityDays
int64
Number of days of inactivity before the rule applies.
Name
string
Key Lifecycle Rule name
WorkspaceId
int64
Workspace ID. 0 means the default workspace.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    key_lifecycle_rule "github.com/Files-com/files-sdk-go/v3/keylifecyclerule"
)

keyLifecycleRule, err := key_lifecycle_rule.Update(files_sdk.KeyLifecycleRuleUpdateParams{
  Id: 1,
  ApplyToAllWorkspaces: lib.Bool(true)
})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

Delete Key Lifecycle Rule

SDK Method

keylifecyclerule.Delete()

Return Object

No return value.

Authorization Requirement

Requires a Site-Wide API key, or a User API key or session from a Site Administrator or a Workspace Administrator for the relevant workspace.

KeyLifecycleRuleDeleteParams Fields

FieldDescription
Id
int64
Required
Key Lifecycle Rule ID.

Example Request

import (
    "fmt"
    "errors"

    files_sdk "github.com/Files-com/files-sdk-go/v3"
    key_lifecycle_rule "github.com/Files-com/files-sdk-go/v3/keylifecyclerule"
)

err := key_lifecycle_rule.Delete(files_sdk.KeyLifecycleRuleDeleteParams{Id: 1})
if err != nil {
    var respErr files_sdk.ResponseError
    if errors.As(err, &respErr) {
        fmt.Println("Response Error Occurred (" + respErr.Type + "): " + respErr.ErrorMessage)
    } else {
        fmt.Printf("Unexpected Error: %s\n", err.Error())
    }
}

The KeyLifecycleRule Object

Some of the methods above return a KeyLifecycleRule object. The attributes of this object are listed below.

AttributeDescription
Id
int64
Key Lifecycle Rule ID
KeyType
string
Key type for which the rule will apply (gpg, ssh, or api).
Possible values: gpg, ssh, api
InactivityDays
int64
Number of days of inactivity before the rule applies.
ExpirationDays
int64
Number of days after creation before an SSH key expires. Applies only to SSH keys.
ApplyToAllWorkspaces
boolean
If true, a default-workspace rule also applies to keys in all workspaces.
Name
string
Key Lifecycle Rule name
WorkspaceId
int64
Workspace ID. 0 means the default workspace.