Skip to main content
The Infisical Perl SDK, Infisical::SDK, lets a Perl application log in to Infisical as a machine identity and create, update, fetch, list, and delete secrets. It can also store the secrets of a folder in %ENV, so that every program your application starts gets the secrets as environment variables. This page covers the main methods of the SDK. For every method and option, see the Infisical::SDK documentation on MetaCPAN.

Prerequisites

  • Perl 5.14 or later
  • A machine identity that uses Universal Auth, and its client ID and client secret
  • The machine identity added to your project with a role that can read secrets, such as Viewer (or Member, if your application creates, updates, or deletes secrets)

Installation

Getting started

If you self-host Infisical, set site_url to the URL of your instance. For the EU region of Infisical Cloud, set site_url to https://eu.infisical.com.

Client options

new takes these options, and each of them is optional:
  • site_url (string): the URL of your Infisical instance, starting with http:// or https:// (defaults to https://app.infisical.com)
  • timeout (number): the number of seconds to wait for each request (defaults to 10)
  • max_retries (integer): the number of times to retry a request after Infisical rate-limits it or after a temporary network error, such as a timeout (defaults to 4)
  • ua (object): the HTTP client that the SDK sends requests with, such as an HTTP::Tiny object with proxy settings (any object with HTTP::Tiny’s request method works)
If a request changes a secret, the SDK retries the request only if it never reached Infisical, so a retry can’t apply a change twice.

Core methods

The client’s methods are in two groups:
  • auth: logs the client in
  • secrets: creates, updates, fetches, lists, and deletes secrets
Every method takes named arguments. Argument names are in snake case, such as project_id. If you pass an argument that the method doesn’t take, such as projectId, the method throws an error and sends nothing to Infisical.

auth

Universal Auth

Parameters:
  • client_id (string, optional): the client ID of the machine identity (defaults to the value of the INFISICAL_UNIVERSAL_AUTH_CLIENT_ID environment variable)
  • client_secret (string, optional): the client secret of the machine identity (defaults to the value of the INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET environment variable)
  • organization_slug (string, optional): the slug of a sub-organization to log in to (defaults to the organization where the machine identity was created)
Returns:
  • Infisical::SDK: the client, so you can create the client and log in with one statement
The SDK doesn’t renew the access token that login gets. The token lasts as long as the Access Token TTL in the machine identity’s Universal Auth settings. If your application runs longer than that, call login again.

secrets

Each secrets method works on one folder, which these arguments select:
  • project_id (string): the ID of your project
  • environment (string): the slug of the environment, such as dev
  • secret_path (string, optional): the path of the folder, such as /backend (defaults to /)
list and get replace each secret reference, such as ${dev.DB_HOST}, with the value that the reference points to. For the full reference of these methods, see Infisical::SDK::Secrets.

List secrets

Parameters:
  • recursive (boolean, optional): whether to also list the secrets in every subfolder of secret_path (defaults to false)
  • view_secret_value (boolean, optional): whether to return the secrets’ values (defaults to true; if false, each secret’s secret_value_hidden is true and its value is a placeholder)
  • tag_slugs (array reference, optional): tag slugs, to list only the secrets that have at least one of these tags
  • attach_to_env (boolean, optional): whether to also load the secrets into %ENV (defaults to false)
Returns:
  • A list of Infisical::SDK::Secret objects, or the number of secrets if you call list in scalar context

Get secret by name

Parameters:
  • secret_name (string): the name of the secret
  • version (integer, optional): the version of the secret to fetch (defaults to the latest version)
  • view_secret_value (boolean, optional): whether to return the secret’s value (defaults to true)
Returns:
  • Infisical::SDK::Secret: the secret

Create secret

Parameters:
  • secret_name (string): the name of the secret
  • secret_value (string): the value of the secret, which can be an empty string
  • secret_comment (string, optional): a comment that Infisical shows with the secret
  • tag_ids (array reference, optional): the IDs of the tags to add to the secret
  • secret_metadata (array reference, optional): key-value pairs to store with the secret, each a hash reference with key, value, and an optional boolean is_encrypted
  • skip_multiline_encoding (boolean, optional): whether to store a multi-line value without encoding its line breaks
Returns:
  • Infisical::SDK::Secret: the new secret, without its tags and metadata (call get for the full secret)

Update secret

Parameters:
  • secret_name (string): the current name of the secret
  • new_secret_name (string, optional): a new name for the secret
  • secret_value, secret_comment, tag_ids, secret_metadata, and skip_multiline_encoding (optional): the new values, in the same format as for create
Returns:
  • Infisical::SDK::Secret: the new version of the secret, in which secret_value and secret_comment hold only the values that this call sent, and tags and metadata are empty (call get for the full secret)

Delete secret

Parameters:
  • secret_name (string): the name of the secret
Returns:
  • Infisical::SDK::Secret: the deleted secret, with the values it had before the delete

Secret objects

list, get, create, update, and delete return Infisical::SDK::Secret objects. Each field has a read-only method of the same name: For an imported secret, secret_path and environment are the folder and environment that the secret was imported from. For every field, see Infisical::SDK::Secret.

Error handling

If a method fails, it throws an Infisical::SDK::Error object, or an object of one of these subclasses: This example creates a secret if it doesn’t exist:
For every error class and method, see Infisical::SDK::Error.