client

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package client provides a Cisco Modeling Labs API client

Package client provides configuration options for the CML client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// services
	Interface       *services.InterfaceService
	Lab             *services.LabService
	Link            *services.LinkService
	Node            *services.NodeService
	System          *services.SystemService
	Group           *services.GroupService
	User            *services.UserService
	ImageDefinition *services.ImageDefinitionService
	NodeDefinition  *services.NodeDefinitionService
	ExtConn         *services.ExtConnService
	Annotation      *services.AnnotationService
	SmartAnnotation *services.SmartAnnotationService
	// contains filtered or unexported fields
}

Client is the main CML API client that provides access to all services.

func New

func New(baseURL string, opts ...Option) (*Client, error)

New creates a new CML client with the given options.

func (*Client) Stats

func (c *Client) Stats() *models.Stats

Stats returns API client statistics.

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config holds the configuration for the CML client.

type Option

type Option func(*Config)

Option is a functional option for configuring the client.

func Conditional

func Conditional(condition bool, option Option) Option

Conditional applies an option only if the condition is true.

func SkipReadyCheck

func SkipReadyCheck() Option

SkipReadyCheck disables the automatic system readiness check during client initialization. By default, the client will call Ready() to verify the CML server is compatible and ready before returning. This check can be skipped for performance reasons or when working with servers that don't support the system_information endpoint.

func WithCACertPEM

func WithCACertPEM(certPEM []byte) Option

WithCACertPEM sets a custom CA certificate bundle (PEM). The certificates are added to the system cert pool.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithInsecureTLS

func WithInsecureTLS() Option

WithInsecureTLS skips TLS certificate verification.

func WithLogLevel

func WithLogLevel(level slog.Level) Option

WithLogLevel sets the log level for the default client logger.

This only affects the internally-created default logger. If WithLogger is provided, the supplied logger is used as-is.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger for the client.

func WithNodeExcludeConfigurations

func WithNodeExcludeConfigurations(v bool) Option

WithNodeExcludeConfigurations forces the node GET/LIST query parameter exclude_configurations.

Passing true omits configuration payloads, passing false includes configuration payloads. This is useful to keep node configuration shape stable across CML versions.

func WithStaticToken added in v0.2.1

func WithStaticToken(token string) Option

WithStaticToken sets a static bearer token for authentication.

Unlike WithToken, this token is not treated as a one-shot bootstrap token. The client will never attempt username/password authentication when this is configured.

func WithToken

func WithToken(token string) Option

WithToken sets the authentication token.

func WithTokenStorageFile

func WithTokenStorageFile(filename string) Option

WithTokenStorageFile sets the file to store the authentication token. If no stoken storage file is provided, memory storage is being used. There's a tradeoff with memory storage as it requires more authentication API calls which is costly especially when a lot of clients are instantiated during e.g. Terraform runs. The file storage saves the token in the file system but this has a security implication as the token might be retrieved. It's up to the user to remove the configured file with a potentially still valid token!

func WithUsernamePassword

func WithUsernamePassword(username, password string) Option

WithUsernamePassword sets the username and password for authentication.

func WithoutNamedConfigs

func WithoutNamedConfigs() Option

WithoutNamedConfigs enables support for named configurations. Named configurations were introduced with CML 2.7 and should be enabled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL