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 either a Site-Wide API key or User API key or session from a User with Site Admin permissions.

Additional Arguments

Example Request

import KeyLifecycleRule from 'files.com/lib/models/KeyLifecycleRule';
import * as FilesErrors from 'files.com/lib/Errors';

try {
  const keyLifecycleRules = await KeyLifecycleRule.list();
  for (const keyLifecycleRule of keyLifecycleRules) {
    // Operate on keyLifecycleRule
  }
} catch (err) {
  if (err instanceof FilesErrors.NotAuthenticatedError) {
    console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
  } else if (err instanceof FilesErrors.FilesError) {
    console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
  } else {
    throw err;
  }
}

Show Key Lifecycle Rule

SDK Method

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

import KeyLifecycleRule from 'files.com/lib/models/KeyLifecycleRule';
import * as FilesErrors from 'files.com/lib/Errors';

try {
  const keyLifecycleRule = await KeyLifecycleRule.find(id);
  // Operate on keyLifecycleRule
} catch (err) {
  if (err instanceof FilesErrors.NotAuthenticatedError) {
    console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
  } else if (err instanceof FilesErrors.FilesError) {
    console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
  } else {
    throw err;
  }
}

Create Key Lifecycle Rule

SDK Method

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

import KeyLifecycleRule from 'files.com/lib/models/KeyLifecycleRule';
import * as FilesErrors from 'files.com/lib/Errors';

try {
  const keyLifecycleRule = await KeyLifecycleRule.create({
    apply_to_all_workspaces: true,
  });
  // Operate on keyLifecycleRule
} catch (err) {
  if (err instanceof FilesErrors.NotAuthenticatedError) {
    console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
  } else if (err instanceof FilesErrors.FilesError) {
    console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
  } else {
    throw err;
  }
}

Update Key Lifecycle Rule

SDK Method

keyLifecycleRule.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

import KeyLifecycleRule from 'files.com/lib/models/KeyLifecycleRule';
import * as FilesErrors from 'files.com/lib/Errors';

try {
  // Find the keyLifecycleRule object by its id.
  const keyLifecycleRule = await KeyLifecycleRule.find(id);
  await keyLifecycleRule.update({
    apply_to_all_workspaces: true,
  });
} catch (err) {
  if (err instanceof FilesErrors.NotAuthenticatedError) {
    console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
  } else if (err instanceof FilesErrors.FilesError) {
    console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
  } else {
    throw err;
  }
}

Delete Key Lifecycle Rule

SDK Method

keyLifecycleRule.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

import KeyLifecycleRule from 'files.com/lib/models/KeyLifecycleRule';
import * as FilesErrors from 'files.com/lib/Errors';

try {
  // Find the keyLifecycleRule object by its id.
  const keyLifecycleRule = await KeyLifecycleRule.find(id);
  await keyLifecycleRule.delete();
} catch (err) {
  if (err instanceof FilesErrors.NotAuthenticatedError) {
    console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
  } else if (err instanceof FilesErrors.FilesError) {
    console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
  } else {
    throw err;
  }
}

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.