Secrets Lua Reference Documentation

chilkat.Secrets

Current Version: 11.7.0

Markdown version of this page for AI tools (v 11.7.0) · all AI docs

Chilkat.Secrets

Manage application secrets through one consistent API.

Chilkat.Secrets provides a unified interface for storing, retrieving, listing, and deleting secrets across local, cloud-based, and in-memory secret stores. It supports string, binary, and JSON secrets, making it useful for passwords, API keys, OAuth credentials, tokens, unlock codes, certificates, and private configuration data.

Local secure storage

  • Windows Credential Manager
  • Apple Keychain

Cloud secret managers

  • AWS Secrets Manager
  • Azure Key Vault
  • IBM Cloud Secrets Manager
  • Oracle Cloud Secrets
  • Doppler Secrets

Temporary secrets

Use in-memory secrets when values should exist only for the lifetime of the running process.

Flexible content types

Store and retrieve secrets as strings, binary data, or structured JSON.

Note: Cloud-based secret managers often require local bootstrap credentials. These can be stored securely in the Windows Credential Manager or Apple Keychain and then used to authenticate to the cloud secret manager.

Object Creation

local chilkat = require("chilkat")

local secrets = chilkat.Secrets.new()
local secrets = chilkat.Secrets.new()

Creates the object (chilkat.Secrets() does the same). Lua's garbage collector frees it when it is no longer referenced; secrets:dispose() frees it at once, and in Lua 5.4 and later local secrets <close> = chilkat.Secrets.new() frees it when the block ends. Calling a method of a disposed object raises an error.

Errors

A method that fails returns nil followed by the error text, as io.open does: local body, err = secrets:method(...), where err is the object's last_error_text. Wrap the call in assert() to raise an error with that text instead. Methods that answer a question return true or false, numbers are returned as they are (check last_method_success where the description says a value means failure), and property reads and writes never fail for Chilkat reasons.

Misuse raises a Lua error: a wrong argument type or a missing argument (bad argument #1 to ...), an unknown property name, a write to a read-only property, an out-of-range integer, or an object of the wrong class.

Names are Chilkat's in snake_case: QuickGetStr is quick_get_str, LastErrorText is last_error_text. Properties are fields (secrets.verbose_logging = true) and methods use the colon (secrets:method(...)). Strings are UTF-8; binary data is a Lua string of bytes. Indexes are 0-based, as in every Chilkat API. Unlocking: call chilkat.unlock_bundle("...") once at startup.

Properties

AutoSplit
-- boolVal is a boolean
local boolVal = secrets.auto_split
secrets.auto_split = boolVal
Introduced in version 10.1.0

The AutoSplit property is specific to local_manager secrets on Windows. The Windows Credentials Manager supports a maximum of 2560 bytes per secret. If a secret exceeds this size, it will be automatically compressed and split when created or updated, and automatically recomposed when retrieved.

A secret can be split into a maximum of 10 parts.

The default value is true.

top
Compression
-- boolVal is a boolean
local boolVal = secrets.compression
secrets.compression = boolVal
Introduced in version 10.1.0

If set to true, then the contents of the secret will be stored compressed. The default value of this property is false.

top
DebugLogFilePath
-- strVal is a string
local strVal = secrets.debug_log_file_path
secrets.debug_log_file_path = strVal

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
LastErrorHtml
-- strVal is a string (read-only)
local strVal = secrets.last_error_html

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
-- strVal is a string (read-only)
local strVal = secrets.last_error_text

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
-- strVal is a string (read-only)
local strVal = secrets.last_error_xml

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
-- boolVal is a boolean
local boolVal = secrets.last_method_success
secrets.last_method_success = boolVal

Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
Location
-- strVal is a string
local strVal = secrets.location
secrets.location = strVal
Introduced in version 10.1.0

The location of the secrets. Possible values are:

  • local_manager - On Windows this is the Credentials Manager. On MacOS and iOS it is the Keychain. This is not yet an option on Linux or Android.
  • aws_secrets_manager - AWS Secrets Manager
  • azure_key_vault - Azure Key Vault
  • ibm_cloud - IBM Cloud Secrets Manager
  • oracle_cloud - Oracle Cloud Secrets
  • doppler - Doppler Secrets
  • memory - In-Memory Secrets

The default location is the local_manager. On Linux and Android, local_manager will behave the same as memory.

top
UncommonOptions
-- strVal is a string
local strVal = secrets.uncommon_options
secrets.uncommon_options = strVal
Introduced in version 10.1.0

This is a catch-all property to be used for uncommon needs. This property defaults to the empty string and should typically remain empty.

top
VerboseLogging
-- boolVal is a boolean
local boolVal = secrets.verbose_logging
secrets.verbose_logging = boolVal

If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
-- strVal is a string (read-only)
local strVal = secrets.version

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

DeleteSecret
-- json_id is a chilkat.JsonObject
-- ok is true, or nil and err on failure
local ok, err = secrets:delete_secret(json_id)
Introduced in version 10.1.0

Deletes a secret. Cloud secrets managers will typically disable the secret and schedule the secret for deletion after some number of days.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
GetSecretBd
-- json_id is a chilkat.JsonObject
-- bd is a chilkat.BinData
-- ok is true, or nil and err on failure
local ok, err = secrets:get_secret_bd(json_id, bd)
Introduced in version 10.1.0

Fetches a binary secret and returns the content in bd.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
GetSecretJson
-- json_id is a chilkat.JsonObject
-- json_out is a chilkat.JsonObject
-- ok is true, or nil and err on failure
local ok, err = secrets:get_secret_json(json_id, json_out)
Introduced in version 10.1.0

Fetches a JSON secret and returns the content in json_out.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
GetSecretSb
-- json_id is a chilkat.JsonObject
-- sb is a chilkat.StringBuilder
-- ok is true, or nil and err on failure
local ok, err = secrets:get_secret_sb(json_id, sb)
Introduced in version 10.1.0

Fetches a string secret and returns the content in sb.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
GetSecretStr
-- json_id is a chilkat.JsonObject
-- str is a string, or nil and err on failure
local str, err = secrets:get_secret_str(json_id)
Introduced in version 10.1.0

Fetches a string secret and returns the content of the secret.

Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
ListSecrets
-- json is a chilkat.JsonObject
-- json_out is a chilkat.JsonObject
-- ok is true, or nil and err on failure
local ok, err = secrets:list_secrets(json, json_out)
Introduced in version 10.1.0

Lists secrets matching the wildcarded or exact values passed in json. The results of the query are returned in json_out.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
SecretSpecToJson
-- secret_spec is a string
-- json is a chilkat.JsonObject
-- ok is true, or nil and err on failure
local ok, err = secrets:secret_spec_to_json(secret_spec, json)
Introduced in version 11.5.0

Converts a secret specification string (secret_spec) to JSON. A secret specification string is formatted as "!!part1|part2|part3|part4" where parts 3 and 4 are optional. json is the output argument.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

More Information and Examples
top
SetBootstrapSecret
-- json_id is a chilkat.JsonObject
-- secret_content is a chilkat.Secrets
-- ok is true, or nil and err on failure
local ok, err = secrets:set_bootstrap_secret(json_id, secret_content)
Introduced in version 10.1.0

Accessing a cloud-based secrets manager requires authentication credentials, which cannot be stored in the manager itself. Instead, they must be securely stored locally.

One solution is to store the authentication credentials as a secret in the Windows Credentials Manager or Apple Keychain. These credentials serve as the bootstrap secret for authenticating with the cloud-based secrets manager.

json_id contains the name of the bootstrap secret. secret_content contains the bootstrap's secret content.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
UpdateSecretBd
-- json_id is a chilkat.JsonObject
-- secret is a chilkat.BinData
-- ok is true, or nil and err on failure
local ok, err = secrets:update_secret_bd(json_id, secret)
Introduced in version 10.1.0

Creates a binary secret if it does not yet exist, or updates an existing secret. The name of the secret is specified in json_id, and the binary content of the secret in secret.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
UpdateSecretJson
-- json_id is a chilkat.JsonObject
-- secret is a chilkat.JsonObject
-- ok is true, or nil and err on failure
local ok, err = secrets:update_secret_json(json_id, secret)
Introduced in version 10.1.0

Creates a JSON secret if it does not yet exist, or updates an existing secret. The name of the secret is specified in json_id, and the JSON content of the secret in secret.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
UpdateSecretSb
-- json_id is a chilkat.JsonObject
-- sb is a chilkat.StringBuilder
-- ok is true, or nil and err on failure
local ok, err = secrets:update_secret_sb(json_id, sb)
Introduced in version 10.1.0

Creates a string secret if it does not yet exist, or updates an existing secret. The name of the secret is specified in json_id, and the string content of the secret in sb.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top
UpdateSecretStr
-- json_id is a chilkat.JsonObject
-- secret is a string
-- ok is true, or nil and err on failure
local ok, err = secrets:update_secret_str(json_id, secret)
Introduced in version 10.1.0

Creates a string secret if it does not yet exist, or updates an existing secret. The name of the secret is specified in json_id, and the string content of the secret in secret.

Note: Starting in Chilkat v11.3.0, if the service = "Chilkat" and the username = "unlock_code", then the secret (which is the Chilkat unlock code) can be stored and retrieved without Chilkat being unlocked. This allows for the Chilkat unlock code itself to be persisted to a secrets manager.

Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.

top

Events

All Chilkat methods are synchronous: the call returns when the work is done. During a long-running call, chilkat.Secrets reports progress to the functions given to set_event_handler, in a table keyed by event name (plain functions, not methods: closures carry whatever state they need):

secrets:set_event_handler({
    percent_done  = function(pct) print(pct .. "%") end,              -- return true to abort
    progress_info = function(name, value) print(name, value) end,
})
secrets:set_event_handler({ event_name = function(...) ... end, ... })

Installs the handlers, replacing any installed before; secrets:set_event_handler(nil) removes them. The event names are checked when the table is installed: a misspelled one raises an error.

The abort_check handler is called periodically during long operations; percent_done is called when an operation's completion percentage is known; progress_info delivers named progress values. A true return from abort_check or percent_done aborts the running method, which then fails in the usual way (nil, err). An error raised in a handler aborts the method and is raised again from the method call; the object remains usable.

AbortCheck
-- handler: function() ... return abort end -- a true return aborts the method in progress
secrets:set_event_handler({ abort_check = function() ... end })

Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the HeartbeatMs property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.

More Information and Examples

Example

local deadline = os.time() + 30                  -- give up after 30 seconds
secrets:set_event_handler({ abort_check = function() return os.time() > deadline end })
top
PercentDone
-- handler: function(pct_done) ... return abort end -- a true return aborts
secrets:set_event_handler({ percent_done = function(pct_done) ... end })

This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).

The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.

To abort the operation, set the abort output argument to true. This will cause the method to terminate and return a failure status or corresponding failure value.

More Information and Examples

Example

secrets:set_event_handler({
    percent_done = function(pct_done)     -- 0 to 100
        print("Percent done: " .. pct_done)
        return false                       -- return true to abort the method in progress
    end,
})
top
ProgressInfo
-- handler: function(name, value) ... end
secrets:set_event_handler({ progress_info = function(name, value) ... end })

This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.

Note: Some Chilkat methods don't fire any ProgressInfo events.

More Information and Examples

Example

secrets:set_event_handler({
    progress_info = function(name, value) print(name .. ": " .. value) end,
})
top