plugin

package
v0.0.0-...-9150249 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: BSD-3-Clause Imports: 23 Imported by: 0

README

CDS Plugin

How to implement a plugin

    package main

    import "github.com/ovh/cds/sdk/plugin"

    type DummyPlugin struct {
        plugin.Common
    }

    func (d DummyPlugin) Name() string        { return "dummy-plugin" }
    func (d DummyPlugin) Description() string { return "This is a dummy plugin" }
    func (d DummyPlugin) Author() string      { return "François SAMIN <francois.samin@corp.ovh.com>" }

    //Parameters return parameters description
    func (d DummyPlugin) Parameters() plugin.Parameters {
        params := plugin.NewParameters()
        params.Add("param1", "string", "this is a parameter", "default value")
        return params
    }

    //Run execute the action
    func (d DummyPlugin) Run(a plugin.IAction) plugin.Result {
        err := plugin.SendLog(a, "PLUGIN", "This is a log from %s", d.Name())
        if err != nil {
            return plugin.Fail
        }
        return plugin.Success
    }

    func main() {
        plugin.Main(DummyPlugin{})
    }

Documentation

Index

Constants

View Source
const (
	MaxTries            = 5
	RequestTimeout      = time.Minute
	AuthHeader          = "X_AUTH_HEADER"
	RequestedWithValue  = "X-CDS-SDK"
	RequestedWithHeader = "X-Requested-With"
)

HTTP Constants

Variables

View Source
var Handshake = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "CDS_PLUGIN_MAGIC_COOKIE",
	MagicCookieValue: "Q0RTX1BMVUdJTl9NQUdJQ19DT09LSUU=",
}

Handshake is the HandshakeConfig used to configure clients and servers.

View Source
var (

	//Trace is a debug logger
	Trace *log.Logger
)
View Source
var VERSION = "snapshot"

VERSION is set with -ldflags "-X main.VERSION={{.cds.proj.version}}+{{.cds.version}}"

Functions

func GetExternalServices

func GetExternalServices(j IJob, serviceType string) (sdk.ExternalService, error)

GetExternalServices call worker to get external service configuration

func InfoMarkdown

func InfoMarkdown(pl CDSAction) string

InfoMarkdown returns string formatted with markdown

func Main

func Main(p CDSAction)

Main func call by plugin, display info only

func SendLog

func SendLog(j IJob, format string, i ...interface{}) error

SendLog send logs to CDS engine for the current

func SendVulnerabilityReport

func SendVulnerabilityReport(j IJob, report sdk.VulnerabilityReport) error

SendVulnerabilityReport call worker to send vulnerabiliry report to API

func Serve

func Serve(a CDSAction)

Serve has to be called in main func of every plugin

func SetTrace

func SetTrace(traceHandle io.Writer)

SetTrace is for debug

Types

type Arguments

type Arguments struct {
	Data map[string]string
}

Arguments type, key: var name, value: value of argument

func (Arguments) Exists

func (p Arguments) Exists(key string) bool

Exists returns true if argument exists

func (Arguments) Get

func (p Arguments) Get(key string) string

Get returns an argument from key

func (*Arguments) Set

func (p *Arguments) Set(key, value string)

Set sets an argument with key / value

type CDSAction

type CDSAction interface {
	Init(IOptions) string
	Version() string
	Name() string
	Description() string
	Author() string
	Parameters() Parameters
	Run(IJob) Result
}

CDSAction is the standard CDSAction Plugin interface

type CDSActionPlugin

type CDSActionPlugin struct {
	CDSAction
}

CDSActionPlugin is the implementation of plugin.Plugin so we can serve/consume this

func (CDSActionPlugin) Client

func (a CDSActionPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

Client must return an implementation of our interface that communicates over an RPC client. We return CDSActionRPC for this.

func (CDSActionPlugin) PluginName

func (a CDSActionPlugin) PluginName() string

PluginName is name for the plugin

func (CDSActionPlugin) Server

func (a CDSActionPlugin) Server(*plugin.MuxBroker) (interface{}, error)

Server must return an RPC server for this plugin type. We construct a CDSActionRPCServer for this.

type CDSActionRPC

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

CDSActionRPC is the struct used by the worker

func (*CDSActionRPC) Author

func (c *CDSActionRPC) Author() string

Author makes rpc call to Author()

func (*CDSActionRPC) Description

func (c *CDSActionRPC) Description() string

Description makes rpc call to Description()

func (*CDSActionRPC) Init

func (c *CDSActionRPC) Init(id IOptions) string

Init the plugin

func (*CDSActionRPC) Name

func (c *CDSActionRPC) Name() string

Name makes rpc call to Name()

func (*CDSActionRPC) Parameters

func (c *CDSActionRPC) Parameters() Parameters

Parameters makes rpc call to Parameters()

func (*CDSActionRPC) Run

func (c *CDSActionRPC) Run(a IJob) Result

Run makes rpc call to Run() on client side

func (*CDSActionRPC) Version

func (c *CDSActionRPC) Version() string

Version of the plugin

type CDSActionRPCServer

type CDSActionRPCServer struct {
	Impl CDSAction
}

CDSActionRPCServer is the struct called to serve the plugin

func (*CDSActionRPCServer) Author

func (c *CDSActionRPCServer) Author(args interface{}, resp *string) error

Author serves rpc call to Author()

func (*CDSActionRPCServer) Description

func (c *CDSActionRPCServer) Description(args interface{}, resp *string) error

Description serves rpc call to Description()

func (*CDSActionRPCServer) Init

func (c *CDSActionRPCServer) Init(args interface{}, resp *string) error

Init the rpc plugin

func (*CDSActionRPCServer) Name

func (c *CDSActionRPCServer) Name(args interface{}, resp *string) error

Name serves rpc call to Name()

func (*CDSActionRPCServer) Parameters

func (c *CDSActionRPCServer) Parameters(args interface{}, resp *Parameters) error

Parameters serves rpc call to Parameters()

func (*CDSActionRPCServer) Run

func (c *CDSActionRPCServer) Run(args interface{}, resp *Result) error

Run serves rpc call to Run()

func (*CDSActionRPCServer) Version

func (c *CDSActionRPCServer) Version(args interface{}, resp *string) error

Version of the rpc plugin

type Client

type Client struct {
	*plugin.Client
	// contains filtered or unexported fields
}

Client must be used from client side to call the plugin. It's managing plugin instanciation and initializing

func NewClient

func NewClient(ctx context.Context, name, binary, id, url string, tlsSkipVerify bool, envs ...string) *Client

NewClient has to be called every time we nedd to call a plugin

func (Client) Instance

func (p Client) Instance() (CDSAction, error)

Instance return a fresh instance of the CDSAction plugin dispensed by a RPC server

type Common

type Common struct {
	Name        string
	Description string
	Parameters  Parameters
	Author      string
	Format      string `json:"-" yaml:"-" xml:"-"`
}

Common is the base plugin struct every plugin should be composed by

func (*Common) Init

func (p *Common) Init(o IOptions) string

Init is a common function for all plugins

func (*Common) Version

func (*Common) Version() string

Version is a common function for all plugins

type IArguments

type IArguments interface {
	Get(string) string
	Exists(string) bool
}

type IJob

type IJob interface {
	ID() int64
	WorkflowNodeRunID() int64
	PipelineBuildID() int64
	StepOrder() int
	WorkerHTTPPort() int
	Arguments() Arguments
	Secrets() Secrets
}

IJob is the Run() input args of every plugin

type IOptions

type IOptions interface {
	Hash() string
	GetURL() string
	TLSSkipVerify() bool
}

IOptions is

type IParameters

type IParameters interface {
	Names() []string
	GetType(string) ParameterType
	GetDescription(string) string
	GetValue(string) string
}

type Job

type Job struct {
	IDPipelineJobBuild int64
	IDWorkflowNodeRun  int64
	IDPipelineBuild    int64
	Args               Arguments
	Secrts             Secrets
	OrderStep          int
	HTTPPortWorker     int
}

Job is the input of the plugin run function

func (Job) Arguments

func (j Job) Arguments() Arguments

func (Job) ID

func (j Job) ID() int64

func (Job) PipelineBuildID

func (j Job) PipelineBuildID() int64

func (Job) Secrets

func (j Job) Secrets() Secrets

func (Job) StepOrder

func (j Job) StepOrder() int

func (Job) WorkerHTTPPort

func (j Job) WorkerHTTPPort() int

func (Job) WorkflowNodeRunID

func (j Job) WorkflowNodeRunID() int64

type Log

type Log struct {
	BuildID            int64                `json:"builID"`
	PipelineBuildJobID int64                `json:"pipelineBuildJobID"`
	PipelineBuildID    int64                `json:"pipelineBuildID"`
	Start              *timestamp.Timestamp `json:"start"`
	LastModified       *timestamp.Timestamp `json:"lastModified"`
	Done               *timestamp.Timestamp `json:"done"`
	StepOrder          int                  `json:"stepOrder"`
	Value              string               `json:"val"`
}

Log struct holds a single line of build log

type Options

type Options struct {
	ID            string
	URL           string
	TlsSkipVerify bool
}

Options is

func (Options) GetURL

func (o Options) GetURL() string

GetURL prepare authentified requests

func (Options) Hash

func (o Options) Hash() string

Hash prepare authentified requests

func (Options) TLSSkipVerify

func (o Options) TLSSkipVerify() bool

TLSSkipVerify returns TLS_SKIP_VERIFY

type ParameterType

type ParameterType string
const (
	Success                            = "Success"
	Fail                               = "Fail"
	EnvironmentParameter ParameterType = "env"
	PipelineParameter    ParameterType = "pipeline"
	ListParameter        ParameterType = "list"
	NumberParameter      ParameterType = "number"
	StringParameter      ParameterType = "string"
	TextParameter        ParameterType = "text"
	BooleanParameter     ParameterType = "boolean"
)

Different values for result

type Parameters

type Parameters struct {
	Data            map[string]string
	DataType        map[string]ParameterType
	DataDescription map[string]string
}

func NewParameters

func NewParameters() Parameters

func (*Parameters) Add

func (p *Parameters) Add(name string, _type ParameterType, description string, value string)

func (*Parameters) GetDescription

func (p *Parameters) GetDescription(k string) string

func (*Parameters) GetType

func (p *Parameters) GetType(k string) ParameterType

func (*Parameters) GetValue

func (p *Parameters) GetValue(k string) string

func (*Parameters) Names

func (p *Parameters) Names() []string

type Result

type Result string

Result is the output of the plugin run function

type Secrets

type Secrets struct {
	Data map[string]string
}

Secrets type, key: var name, value: value of secret

func (Secrets) Exists

func (p Secrets) Exists(key string) bool

Exists returns true if secret exists

func (Secrets) Get

func (p Secrets) Get(key string) string

Get returns a secret from key

func (*Secrets) Set

func (p *Secrets) Set(key, value string)

Set sets a secret with key / value

Directories

Path Synopsis
caller command

Jump to

Keyboard shortcuts

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