Go SDK: sdk
The Golang version of CTO.ai SDK works in conjunction with our Docker base images. The SDK allows the development of automations with rich user interfaces, that run in both the local terminal and remotly on the CTO.ai Platform.
Supported methods
The following SDK methods are supported in Golang:
- GetHostOS
- GetInterfaceType
- GetSecret
- GetStatePath
- HomeDir
- SetSecret
- Track
- GetState
- SetState
- GetConfig
- GetAllConfig
- SetConfig
- user
- team
To use the SDK, you need to create a new SDK object:
Alternatively, the SDK object is included in the Client object:
func (*Sdk) Start
Starts a remote command/pipeline/service that belongs to the same team as the “op” that executes the method.
func (*Sdk) Start(workflowName string) error
Example:
func (*Sdk) GetHostOS
func (*Sdk) GetHostOS() string
Returns the current host OS.
Example
Output
func (*Sdk) GetInterfaceType
func (*Sdk) GetInterfaceType() string
Returns the interface type that the Command, Service, or Pipeline is attached to (e.g. terminal, web interface or Slack).
Example
Output
func (*Sdk) GetSecret
func (*Sdk) GetSecret(key string, options ...GetSecretOption) (string, error)
Requests a secret from the secret store by key
.
If the secret exists, it is returned. A notification is printed to the user that the secret has been accessed, unless the OptGetSecretHidden
option is passed.
If the secret does not exist, the user is prompted to provide a replacement, either from the secret store or by direct entry through their interface.
Example
Output
func (*Sdk) HomeDir
func (*Sdk) HomeDir() string
Returns the location of the user home directory.
Example
Output
func (*Sdk) SetSecret
func (*Sdk) SetSecret(key string, value string) (string, error)
Sets a particular value into the secret store.
If the secret already exists, the user is prompted on whether to overwrite it.
Example
Output
func (*Sdk) Track
The track function allows you to store and retrieve custom analytic data.
func (*Sdk) Track(tags []string, event string, metadata map[string]interface{}) error
tags
field is deprecated. Please only pass []string{}
as the tags argument, and do not use this field for data.Example
Using Track for Workflow Metrics
Tracking Workflow Metrics using CTO.ai can give deep insight into your team’s activity.
To use track to send a Workflow Metric event, place your event data in the metadata
field like so:
The first two arguments to client.Sdk.Track
are left blank because they required by Track
, but are not used by the metrics dashboard.
NOTE: currenlty the supported values forevent_action
are succeeded
or failure
.
More information about Workflow Metrics can be found on the Insights: Getting Started page.
func (*Sdk) Events
func (*Sdk) Events(starttime string, endtime string) ([]map[string]interface{}, error)
Retrieves events to the CTO.ai analytics system.
This is the public facing API to enable developers to retrieve workflow events.
Example
The event, tags, and payload will be retrieved from the events system.
func (s *Sdk) GetConfig
func (s *Sdk) GetConfig(key string) (string, error)
Returns a value from the team configuration store. If the value does not exist, returns an empty string.
Example
func (s *Sdk) GetAllConfig
func (s *Sdk) GetAllConfig() (map[string]string, error)
Returns the contents of the team configuration store, as a map of keys to values.
Example
func (s *Sdk) SetConfig
func (s *Sdk) SetConfig(key string, value string) error
Sets a value in the team configuration store.
Example
func (s *Sdk) DeleteConfig
func (s *Sdk) DeleteConfig(key string) (bool, error)
Deletes a key-value pair in the persistent team configuration. Returns true
if the key exists and the deletion is successful, or false
if the key cannot be found.
Example
func (*Sdk) User() (UserInfo, error)
User allows an Command to get information about the CTO.ai user running it such as: id, username, & email. For example, you can set the username or email for a text field that corresponds with who created a ticket or flagged an incident.
Example
Output
func (*Sdk) Team() (TeamInfo, error)
Allows a command to request the basic team information like team id and team name.