plugin

package
v0.0.0-...-a57a29f Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2016 License: BSD-3-Clause Imports: 16 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() {
        p := DummyPlugin{}
        plugin.Serve(&p)
    }

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
)

Functions

func SendLog

func SendLog(a IAction, step, format string, i ...interface{}) error

SendLog send logs to CDS engine for the current

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 Action

type Action struct {
	IDActionBuild int64
	Args          Arguments
}

Action is the input of the plugin run function

func (Action) Arguments

func (a Action) Arguments() Arguments

func (Action) ID

func (a Action) ID() int64

type Arguments

type Arguments struct {
	Data map[string]string
}

func (Arguments) Exists

func (p Arguments) Exists(key string) bool

func (Arguments) Get

func (p Arguments) Get(key string) string

func (*Arguments) Set

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

type CDSAction

type CDSAction interface {
	Init(IOptions) string
	Name() string
	Description() string
	Author() string
	Parameters() Parameters
	Run(IAction) 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 IAction) Result

Run makes rpc call to Run() on client side

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()

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(name, binary, id, url string, tlsSkipVerify bool) *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{}

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

type IAction

type IAction interface {
	ID() int64
	Arguments() Arguments
}

IAction is the Run() input args of every plugin

type IArguments

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

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 Log

type Log struct {
	ActionID int64  `json:"action_build_id"`
	Step     string `json:"step"`
	Value    string `json:"value"`
}

Log a a struct to send log to CDS API

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"
	PasswordParameter    ParameterType = "password"
	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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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