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

\Files\Model\KeyLifecycleRule::list;

Return Object

KeyLifecycleRule[]

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Additional Arguments

Example Request

try {
  $key_lifecycle_rules = \Files\Model\KeyLifecycleRule::list();
  foreach ($key_lifecycle_rules as $key_lifecycle_rule) {
    // Operate on $key_lifecycle_rule
  }
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Show Key Lifecycle Rule

SDK Method

\Files\Model\KeyLifecycleRule::find;

Return Object

KeyLifecycleRule

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Method Arguments

ArgumentDescription
id
int64
Required
Key Lifecycle Rule ID.

Example Request

try {
  $key_lifecycle_rule = \Files\Model\KeyLifecycleRule::find($id);
  // Operate on $key_lifecycle_rule
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Create Key Lifecycle Rule

SDK Method

\Files\Model\KeyLifecycleRule::create;

Return Object

KeyLifecycleRule

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Method Arguments

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

Example Request

try {
  $key_lifecycle_rule = \Files\Model\KeyLifecycleRule::create([
    'apply_to_all_workspaces' => true
  ]);
  // Operate on $key_lifecycle_rule
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Update Key Lifecycle Rule

SDK Method

$key_lifecycle_rule->update;

Return Object

KeyLifecycleRule

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Method Arguments

ArgumentDescription
apply_to_all_workspaces
boolean
If true, a default-workspace rule also applies to keys in all workspaces.
expiration_days
int64
Number of days after creation before an SSH key expires. Applies only to SSH keys.
key_type
string
Key type for which the rule will apply (gpg, ssh, or api).
Possible values: gpg, ssh, api
inactivity_days
int64
Number of days of inactivity before the rule applies.
name
string
Key Lifecycle Rule name
workspace_id
int64
Workspace ID. 0 means the default workspace.

Example Request

try {
  // Find the key_lifecycle_rule object by its id.
  $key_lifecycle_rule = \Files\Model\KeyLifecycleRule::find(id);
  $key_lifecycle_rule->update([
    'apply_to_all_workspaces' => true
  ]);
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Delete Key Lifecycle Rule

SDK Method

$key_lifecycle_rule->delete;

Return Object

No return value.

Authorization Requirement

Requires either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Example Request

try {
  // Find the key_lifecycle_rule object by its id.
  $key_lifecycle_rule = \Files\Model\KeyLifecycleRule::find(id);
  $key_lifecycle_rule->delete();
} catch (\Files\NotAuthenticated\InvalidUsernameOrPasswordException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

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
key_type
string
Key type for which the rule will apply (gpg, ssh, or api).
Possible values: gpg, ssh, api
inactivity_days
int64
Number of days of inactivity before the rule applies.
expiration_days
int64
Number of days after creation before an SSH key expires. Applies only to SSH keys.
apply_to_all_workspaces
boolean
If true, a default-workspace rule also applies to keys in all workspaces.
name
string
Key Lifecycle Rule name
workspace_id
int64
Workspace ID. 0 means the default workspace.