cidsdk

package module
v0.0.0-...-81f7454 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 20 Imported by: 62

README

CID - Go SDK

go sdk for cid

Configuration

The SDK will detect the endpoint (unix socket or http api) automatically when initialized as part of a action or workflow run based on the follwing envionrment properties:

Property Description
CID_API_SOCKET unix socket file
CID_API_ADDR http endpoint
CID_API_SECRET temporary api key to securely access the api

For local testing run cid api and set CID_API_ADDR to http://localhost:7400.

Code Example

// sdk
cid, _ := cidsdk.NewSDK()
currentModule, _ := cid.CurrentModule()

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JoinSeparator = ""

Functions

func JoinPath

func JoinPath(elem ...string) string

func OverwriteFromEnv

func OverwriteFromEnv(data interface{})

OverwriteFromEnv will overwrite values with the given env values if present

Types

type APIError

type APIError struct {
	Detail string `json:"detail,omitempty"`
	Status int    `json:"status,omitempty"`
	Title  string `json:"title,omitempty"`
}

APIError defines model for Error.

func (*APIError) Error

func (e *APIError) Error() string

type Action

type Action interface {
	Execute() error
}

Action is the common interface for all actions

type ActionArtifact

type ActionArtifact struct {
	BuildID       string `json:"build_id,omitempty"`
	JobID         string `json:"job_id,omitempty"`
	ID            string `json:"id,omitempty"`
	Module        string `json:"module,omitempty"`
	Type          string `json:"type,omitempty"`
	Name          string `json:"name,omitempty"`
	Format        string `json:"format,omitempty"`
	FormatVersion string `json:"format_version,omitempty"`
}

ActionArtifact contains information about generated artifacts

type ArtifactDownloadByteArrayRequest

type ArtifactDownloadByteArrayRequest struct {
	ID string `json:"id"`
}

type ArtifactDownloadRequest

type ArtifactDownloadRequest struct {
	ID         string `json:"id"`
	TargetFile string `json:"target_file"`
}

type ArtifactListRequest

type ArtifactListRequest struct {
	Query string `json:"query"`
}

type ArtifactUploadRequest

type ArtifactUploadRequest struct {
	File          string `json:"file"`
	Content       string `json:"content"`
	ContentBytes  []byte `json:"content_bytes"`
	Module        string `json:"module"`
	Type          string `json:"type"`
	Format        string `json:"format"`
	FormatVersion string `json:"format_version"`
	ExtractFile   bool   `json:"extract_file"`
}

type CurrentConfig

type CurrentConfig struct {
	Debug        bool              `json:"debug,omitempty"`
	Log          map[string]string `json:"log,omitempty"`
	ProjectDir   string            `json:"project_dir,omitempty"`
	TempDir      string            `json:"temp_dir,omitempty"`
	ArtifactDir  string            `json:"artifact_dir,omitempty"`
	HostName     string            `json:"host_name,omitempty"`
	HostUserId   string            `json:"host_user_id,omitempty"`
	HostUserName string            `json:"host_user_name,omitempty"`
	HostGroupId  string            `json:"host_group_id,omitempty"`
	Config       string            `json:"config,omitempty"`
}

CurrentConfig defines model for CurrentConfig.

func (CurrentConfig) DebugFlag

func (c CurrentConfig) DebugFlag(id string, flag string) string

type ExecuteCommandRequest

type ExecuteCommandRequest struct {
	// CaptureOutput capture and return the output (stdout and stderr will be passed through if not set)
	CaptureOutput bool `json:"capture_output,omitempty"`

	// Command command
	Command string `json:"command,omitempty"`

	// WorkDir directory to execute the command in (default = project root)
	WorkDir string `json:"work_dir,omitempty"`

	// Env contains additional env properties
	Env map[string]string `json:"env,omitempty"`

	// Ports that will be exposed
	Ports []int `json:"ports,omitempty"`

	// A version Constraint for the binary used in command
	Constraint []int `json:"constraint,omitempty"`
}

ExecuteCommandRequest defines model for ExecuteCommandRequest.

type ExecuteCommandResponse

type ExecuteCommandResponse struct {
	// Code command exit code
	Code int `json:"code,omitempty"`

	// Command the command being executed
	Command string `json:"command,omitempty"`

	// Dir directory the command is executed in
	Dir string `json:"dir,omitempty"`

	// Error error message
	Error string `json:"error,omitempty"`

	// Stderr error output (if capture-output was request, empty otherwise)
	Stderr string `json:"stderr,omitempty"`

	// Stdout standard output (if capture-output was request, empty otherwise)
	Stdout string `json:"stdout,omitempty"`
}

ExecuteCommandResponse defines model for ExecuteCommandResponse.

type File

type File struct {
	Path      string `json:"path"`
	Directory string `json:"dir"`
	Name      string `json:"name"`
	NameShort string `json:"name_short"`
	Extension string `json:"ext"`
}

func NewFile

func NewFile(path string) File

type FileRequest

type FileRequest struct {
	Directory  string   `json:"dir"`
	Extensions []string `json:"ext"`
}

type HealthcheckResponse

type HealthcheckResponse struct {
	Status string `json:"status"`
}

HealthcheckResponse defines model for HealthcheckResponse.

type LogMessageRequest

type LogMessageRequest struct {
	Level   string                 `json:"level"`
	Message string                 `json:"message"`
	Context map[string]interface{} `json:"context"`
}

type ModuleActionData

type ModuleActionData struct {
	ProjectDir string
	Module     ProjectModule
	Config     CurrentConfig
	Env        map[string]string
}

type ProjectActionData

type ProjectActionData struct {
	ProjectDir string
	Config     CurrentConfig
	Modules    []ProjectModule
	Env        map[string]string
}

type ProjectBuildSystem

type ProjectBuildSystem string
const (
	BuildSystemGradle          ProjectBuildSystem = "gradle"
	BuildSystemMaven           ProjectBuildSystem = "maven"
	BuildSystemGoMod           ProjectBuildSystem = "gomod"
	BuildSystemNpm             ProjectBuildSystem = "npm"
	BuildSystemHugo            ProjectBuildSystem = "hugo"
	BuildSystemHelm            ProjectBuildSystem = "helm"
	BuildSystemContainer       ProjectBuildSystem = "container"
	BuildSystemRequirementsTXT ProjectBuildSystem = "python-requirements.txt"
	BuildSystemPipfile         ProjectBuildSystem = "pipfile"
	BuildSystemSetupPy         ProjectBuildSystem = "setup.py"
	BuildSystemMkdocs          ProjectBuildSystem = "mkdocs"
	BuildSystemComposer        ProjectBuildSystem = "composer"
	BuildSystemDotNet          ProjectBuildSystem = "dotnet"
	BuildSystemCargo           ProjectBuildSystem = "cargo"
)

type ProjectBuildSystemSyntax

type ProjectBuildSystemSyntax string
const (
	BuildSystemSyntaxDefault ProjectBuildSystemSyntax = "default"
	GradleGroovyDSL          ProjectBuildSystemSyntax = "groovy"
	GradleKotlinDSL          ProjectBuildSystemSyntax = "kotlin"
	ContainerFile            ProjectBuildSystemSyntax = "containerfile"
	ContainerBuildahScript   ProjectBuildSystemSyntax = "buildah-script"
	MkdocsTechdocs           ProjectBuildSystemSyntax = "mkdocs-techdocs"
)

type ProjectDependency

type ProjectDependency struct {
	Id      string `json:"id,omitempty"`
	Type    string `json:"type,omitempty"`
	Version string `json:"version,omitempty"`
}

ProjectDependency defines model for ProjectDependency.

type ProjectLanguage

type ProjectLanguage string
const (
	LanguageGolang     ProjectLanguage = "go"
	LanguageJava       ProjectLanguage = "java"
	LanguageKotlin     ProjectLanguage = "kotlin"
	LanguageJavascript ProjectLanguage = "javascript"
	LanguageTypescript ProjectLanguage = "typescript"
	LanguagePython     ProjectLanguage = "python"
	LanguagePHP        ProjectLanguage = "php"
	LanguageRust       ProjectLanguage = "rust"
)

type ProjectModule

type ProjectModule struct {
	// ProjectDir project root directory
	ProjectDir string `json:"project_dir,omitempty"`

	// ModuleDir module root directory
	ModuleDir string `json:"module_dir,omitempty"`

	// Discovery module detected based on
	Discovery []ProjectModuleDiscovery `json:"discovery,omitempty"`

	// Name module name
	Name string `json:"name,omitempty"`

	// Slug module name
	Slug string `json:"slug,omitempty"`

	// BuildSystem module name
	BuildSystem string `json:"build_system,omitempty"`

	// BuildSystemSyntax module name
	BuildSystemSyntax string `json:"build_system_syntax,omitempty"`

	// Language module name
	Language *map[string]string `json:"language,omitempty"`

	// Dependencies module name
	Dependencies *[]ProjectDependency `json:"dependencies,omitempty"`

	// Files all files in the project directory
	Files []string `json:"files,omitempty"`

	// Submodules submodules
	Submodules *[]ProjectModule `json:"submodules,omitempty"`
}

ProjectModule defines model for ProjectModule.

type ProjectModuleDiscovery

type ProjectModuleDiscovery struct {
	File string `json:"file"`
}

ProjectModuleDiscovery contains info on the files used to discover the module

type SDK

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

func NewSDK

func NewSDK() (*SDK, error)

func (SDK) ArtifactDownload

func (sdk SDK) ArtifactDownload(request ArtifactDownloadRequest) error

ArtifactDownload request

func (SDK) ArtifactDownloadByteArray

func (sdk SDK) ArtifactDownloadByteArray(request ArtifactDownloadByteArrayRequest) ([]byte, error)

ArtifactDownloadByteArray request

func (SDK) ArtifactList

func (sdk SDK) ArtifactList(request ArtifactListRequest) (*[]ActionArtifact, error)

ArtifactList request

func (SDK) ArtifactUpload

func (sdk SDK) ArtifactUpload(request ArtifactUploadRequest) error

ArtifactUpload request

func (SDK) CurrentConfig

func (sdk SDK) CurrentConfig() (*CurrentConfig, error)

CurrentConfig request

func (SDK) CurrentModule

func (sdk SDK) CurrentModule() (*ProjectModule, error)

CurrentModule request

func (SDK) Env

func (sdk SDK) Env() (map[string]string, error)

Env request

func (SDK) ExecuteCommand

func (sdk SDK) ExecuteCommand(req ExecuteCommandRequest) (*ExecuteCommandResponse, error)

ExecuteCommand command

func (SDK) FileCopy

func (sdk SDK) FileCopy(old string, new string) error

FileCopy command

func (SDK) FileExists

func (sdk SDK) FileExists(file string) bool

FileExists command

func (SDK) FileList

func (sdk SDK) FileList(req FileRequest) (files []File, err error)

FileList command

func (SDK) FileRead

func (sdk SDK) FileRead(file string) (string, error)

FileRead command

func (SDK) FileRemove

func (sdk SDK) FileRemove(file string) error

FileRemove command

func (SDK) FileRename

func (sdk SDK) FileRename(old string, new string) error

FileRename command

func (SDK) FileWrite

func (sdk SDK) FileWrite(file string, content []byte) error

FileWrite command

func (SDK) Health

func (sdk SDK) Health() (*HealthcheckResponse, error)

Health request

func (SDK) Log

func (sdk SDK) Log(req LogMessageRequest) error

Log request

func (SDK) ModuleAction

func (sdk SDK) ModuleAction(cfg any) (ModuleActionData, error)

ModuleAction is a utility function to prepare to run a module-scoped action

func (SDK) Modules

func (sdk SDK) Modules() (*[]ProjectModule, error)

Modules request

func (SDK) ProjectAction

func (sdk SDK) ProjectAction(cfg any) (ProjectActionData, error)

ProjectAction is a utility function to prepare to run a project-scoped action

func (SDK) TARCreate

func (sdk SDK) TARCreate(inputDirectory string, outputFile string) error

TARCreate creates a tar archive of the directory at the given path.

func (SDK) TARExtract

func (sdk SDK) TARExtract(archiveFile string, outputDirectory string) error

TARExtract extracts a tar archive at the given path into the given directory.

func (SDK) UUID

func (sdk SDK) UUID() string

UUID request

func (SDK) VCSCommitByHash

func (sdk SDK) VCSCommitByHash(request VCSCommitByHashRequest) (*VCSCommit, error)

VCSCommitByHash request

func (SDK) VCSCommits

func (sdk SDK) VCSCommits(request VCSCommitsRequest) (*[]VCSCommit, error)

VCSCommits request

func (SDK) VCSDiff

func (sdk SDK) VCSDiff(request VCSDiffRequest) (*[]VCSDiff, error)

VCSDiff request

func (SDK) VCSReleases

func (sdk SDK) VCSReleases(request VCSReleasesRequest) (*[]VCSRelease, error)

VCSReleases request

func (SDK) VCSTags

func (sdk SDK) VCSTags() (*[]VCSTag, error)

VCSTags request

func (SDK) ZIPCreate

func (sdk SDK) ZIPCreate(inputDirectory string, outputFile string) error

ZIPCreate creates a zip archive of the directory at the given path.

func (SDK) ZIPExtract

func (sdk SDK) ZIPExtract(archiveFile string, outputDirectory string) error

ZIPExtract unzips the zip archive at the given path into the given directory.

type SDKClient

type SDKClient interface {
	Health() (*HealthcheckResponse, error)
	Log(req LogMessageRequest) error
	ModuleAction(cfg any) (ModuleActionData, error)
	ProjectAction(cfg any) (ProjectActionData, error)
	Env() (map[string]string, error)
	Modules() (*[]ProjectModule, error)
	CurrentModule() (*ProjectModule, error)
	CurrentConfig() (*CurrentConfig, error)
	VCSCommits(request VCSCommitsRequest) (*[]VCSCommit, error)
	VCSCommitByHash(request VCSCommitByHashRequest) (*VCSCommit, error)
	VCSTags() (*[]VCSTag, error)
	VCSReleases(request VCSReleasesRequest) (*[]VCSRelease, error)
	VCSDiff(request VCSDiffRequest) (*[]VCSDiff, error)
	ExecuteCommand(req ExecuteCommandRequest) (*ExecuteCommandResponse, error)
	FileRead(file string) (string, error)
	FileList(req FileRequest) (files []File, err error)
	FileRename(old string, new string) error
	FileRemove(file string) error
	FileWrite(file string, content []byte) error
	FileExists(file string) bool
	ZIPCreate(inputDirectory string, archiveFile string) error
	ZIPExtract(archiveFile string, outputDirectory string) error
	TARCreate(inputDirectory string, archiveFile string) error
	TARExtract(archiveFile string, outputDirectory string) error
	ArtifactList(request ArtifactListRequest) (*[]ActionArtifact, error)
	ArtifactUpload(request ArtifactUploadRequest) error
	ArtifactDownload(request ArtifactDownloadRequest) error
	ArtifactDownloadByteArray(request ArtifactDownloadByteArrayRequest) ([]byte, error)
	UUID() string
}

type VCSAuthor

type VCSAuthor struct {
	Name  string `json:"name,omitempty"`
	Email string `json:"email,omitempty"`
}

type VCSChange

type VCSChange struct {
	ChangeType string  `json:"type,omitempty"`
	FileFrom   VCSFile `json:"file_from,omitempty"`
	FileTo     VCSFile `json:"file_to,omitempty"`
	Patch      string  `json:"patch,omitempty"`
}

type VCSCommit

type VCSCommit struct {
	HashShort   string            `json:"hash_short,omitempty"`
	Hash        string            `json:"hash,omitempty"`
	Message     string            `json:"message,omitempty"`
	Description string            `json:"description,omitempty"`
	Author      VCSAuthor         `json:"author,omitempty"`
	Committer   VCSAuthor         `json:"committer,omitempty"`
	Tags        *[]VCSTag         `json:"tags,omitempty"`
	AuthoredAt  time.Time         `json:"authored_at,omitempty"`
	CommittedAt time.Time         `json:"committed_at,omitempty"`
	Changes     *[]VCSChange      `json:"changes,omitempty"`
	Context     map[string]string `json:"context,omitempty"`
}

type VCSCommitByHashRequest

type VCSCommitByHashRequest struct {
	Hash           string `json:"hash"`
	IncludeChanges bool   `json:"changes"`
}

type VCSCommitsRequest

type VCSCommitsRequest struct {
	FromHash       string `json:"from"`
	ToHash         string `json:"to"`
	IncludeChanges bool   `json:"changes"`
	Limit          int    `json:"limit"`
}

type VCSDiff

type VCSDiff struct {
	FileFrom VCSFile       `json:"file_from"`
	FileTo   VCSFile       `json:"file_to"`
	Lines    []VCSDiffLine `json:"lines,omitempty"`
}

type VCSDiffLine

type VCSDiffLine struct {
	Operation int    `json:"operation"`
	Content   string `json:"content"`
}

type VCSDiffRequest

type VCSDiffRequest struct {
	FromHash string `json:"from"`
	ToHash   string `json:"to"`
}

type VCSFile

type VCSFile struct {
	Name string `json:"name,omitempty"`
	Size int    `json:"size,omitempty"`
	Hash string `json:"hash,omitempty"`
}

type VCSRelease

type VCSRelease struct {
	Version string `json:"version,omitempty"`
	Ref     VCSTag `json:"ref,omitempty"`
}

type VCSReleasesRequest

type VCSReleasesRequest struct {
	Type string `json:"type"` // Type of the release: stable, unstable
}

type VCSTag

type VCSTag struct {
	RefType string `json:"type,omitempty"`
	Value   string `json:"value,omitempty"`
	Hash    string `json:"hash,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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