goforjj

package module
v0.0.0-...-7ac0fad Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: Apache-2.0 Imports: 27 Imported by: 7

README

GO Forjj

Introduction

This repo contains several golang packages and a golang generator to create a FORJJ plugin and implements the FORJJ plugin protocol in golang.

What's this repo provides?

2 things:

  • go-forjj package
  • a GO generate code from yaml file to build/maintain FORJJ plugin.
go-forjj package

This code provides several generic functions and the Plugin CLI default structure to create your plugin in GO.

list to TDB. Probably built from godoc For now, I suggest you to read the [main goforjj source file] (forjj-plugin-app.go)

Why creating your forjj plugin

Why will I need to create a forjj plugin? Well, usually, you won't need it.

But if you want to add an application that is not covered by current FORJJ plugins, then you will certainly need to write your own plugin to manage the new application (create/configure and maintain it) and share it.

You have 2 possibilities:

  1. create your own plugin in any language that must respect forjj plugin protocol. It can be a REST API or a simple script which return a json data and can be started from docker or natively where forjj is running.
  2. Use goforjj to create your plugin in golang.

golang is an awesome language that impressed me when developping forjj. To help you be focus in your core task (create an app returning json or create a FORJJ REST API ) I built some great fast and powerful golang code to create your first forjj plugin in minutes.

This code will implement the FORJJ plugin protocol.

Create your FORJJ plugin with GO

  1. Create an empty repository. The recommendation is to name it forjj-<pluginName>. But this is not a requirement. The core requirement is that your repository name is your plugin name.

    git init forjj-myplugin
    cd forjj-myplugin
    printf "# forjj-myplugin\n\n## Introduction\n\nThis is my first forjj plugin\n" > README.md
    git add README.md
    git commit -m "Initial commit"
    
  2. If you want your plugin to be part of Forjj ecosystem, the repository needs to be hosted in forj-oss organization. To create it, clone git@github.com:forj-oss/forj-oss-infra, and add your repository in the deployments/production/Forjfile (repositories) and a repository team (groups/<forjj-<pluginName>/members[]) This team will be owner of the repo.

    You have example in forj-oss-infra

    To attach your initial git repo to your new forj-oss/forjj-myplugin, do the following:

    git remote add origin git@github.com:<yourName>/forjj-myplugin
    git remote add upstream git@github.com:forjj-oss/forjj-myplugin
    

    As soon as forj-oss has created your repo, we should be able to

  3. Optionnally, with GO, a build-env repo helps to build forj-oss projects with your code/build specification. We assume, you are using bash as shell.

    Do the following:

    git clone git@github.com:forj-oss/build-env ../build-env
    ../build-env/configure-build-env.sh forjj-myplugin go
    

    Load the new build-env (bash script)

    source build-env.sh
    

    And create your GO build container

    create-go-build-env.sh
    

    As soon as your build-env is loaded, you have direct access via docker of go, glide and inenv

    When you want to unload your build environment, call build-env-unset

    When you want to load it again, call build-env (alias added your .bashrc)

    If you do not take care, the GO binary you will produce will have some dependency to the build environment libraries. To avoid that, edit build-env.sh and add export CGO_ENABLED=0 and edit build-unset.sh and add unset CGO_ENABLED

  4. You need the genapp binary in the /bin of your go tree genapp is part of goforjj project, currently you need to build it from the source.

    Build genapp instructions

  5. Move to your plugin directory and create a plugin.go with the following:

    package main
    
    //go:generate go build -o /go/bin/genapp forjj-myplugin/vendor/github.com/forj-oss/goforjj/genapp
    //go:generate /go/bin/genapp myplugin.yaml vendor/github.com/forj-oss/goforjj/genapp
    
    
  6. Then do :

    glide init           # Initialize of glide.yaml and glide.lock
    glide cc 		 # Optional, Clear glide cache if you have already download a template 
    glide get github.com/forj-oss/goforjj         # Get the goforjj project in te tree to access the template
    
    go generate           # To generate the flags management code.
    

    Depending on your plugin definition (/runtime/service_type), go generate will create several files:

    glide update           # Update dependencies
    

    the initial generated code is functionnal! So, you can do:

    go build           # Build plugin
    

Now you should have a hello-world plugin

  • REST API : Default.

If you have added some extra commands, a <command>.go will be also created the first time with initial code. So, you will just need to edit it and add your specific command code.

NOTE: A lot of features and flags values are managed by the goforjj package, please read the goforjj package [documentation above] (#go-forjj-package).

Writing your <plugin>.yaml file

This file is the plugin declarative part of your plugin.

It defines what your plugin exposes and how forjj do task with your plugin.

If you run a FORJJ plugin from the genapp templates (go generate), this file is also used to generate/maintain some GO source files.

The yaml file must be structured as follow:

---
plugin: <PluginName>       // Required
version: <PluginVersion>   // Optional
description: <description> // Optional
created_flag_file: "{{ .InstanceName }}/{{.Name}}.yaml" # Optional. By default "{{ .InstanceName }}/{{.Name}}.yaml". Usually is the <plugin>.yaml source file stored in the infra source repository. Ex: github/github.yaml
runtime:   // Define how the plugin is started
  docker:  // This is the default and only way to get it working today.
    image: "string" // Docker Image name to use
  service_type: "" // "REST API" or "shell"
  service:
    socket: "string" // Optional: Name of the socket to use. By default, it creates <PluginName>.sock
    parameters: [ "string", ... ] // Optional: Collection of parameters to start the plugin service.
actions: // Obsolete. Is replaced by task_flags and objects.
  common: // Flags defined for each tasks
    <FlagName>: // Please note the spaces shift for next lines. It have to be indented from the <FlagName> string position.
      help: "<Help string>"  // If missing, no help is displayed.
      required: <false/true> // If missing, required is false.
      hidden: <false/true>   // if missing, hidden is false.
      group: "string"        // Used in GO genapp templates to regroup several fields in a struct.
      short: '<caracter>'    // single caracter for short option. if Missing no short option set.
      secure: <false/true>   // false by default. If the flag is given, forjj will save in a `forjj-creds.yml` like file in your workspace. The plugin should not save it anywhere.
      [...]                    // Collection of FlagName...
  create:   // Flags defined for 'create' task. Same syntax as found in 'common' section.
      ...
  update:   // Flags defined for 'update infra' infra task. Same syntax as found in 'common' section.
      ...
  maintain: // Flags defined for 'maintain' task. Same syntax as found in 'common' section.
      ...
task_flags:
  common: // Flags defined for each tasks
    <FlagName>: // Please note the spaces shift for next lines. It have to be indented from the <FlagName> string position.
      help: "<Help string>"  // If missing, no help is displayed.
      required: <false/true> // If missing, required is false.
      hidden: <false/true>   // if missing, hidden is false.
      short: '<caracter>'    // single caracter for short option. if Missing no short option set.
      secure: <false/true>   // false by default. If the flag is given, forjj will save in a `forjj-creds.yml` like file in your workspace. The plugin should not save it anywhere.
      [...]                    // Collection of FlagName...

  add:     // Flags defined for 'add' or others tasks. Same syntax as found in 'common' section.
  remove:
  rename:
  list:
  maintain:
objects:          // Collection of options that the plugin expose to forjj.
  <object_name>:
    actions :     // By default: [ "add", "update", "remove", "rename", "list"]. If you limit to few actions, set it here.
    flags:        // Collection of flags for the object to be managed by forjj.
      <flagName>:
        only-for-actions: ["string", ...] // If missing, use the actions defined at object level.
        help: "<Help string>"             // If missing, no help is displayed.
        required: <false/true>            // If missing, required is false.
        hidden: <false/true>              // if missing, hidden is false.
        short: '<caracter>'               // single caracter for short option. if Missing no short option set.
Short examples

In order to start defining your own plugin declaration, here is few examples to highlight how to set it.

First of all, here is a minimal version:

plugin: my-plugin
runtime:
  docker:
    image: "myimage" // Docker Image name to use

But to be honest, with this yaml file, it will work, for sure, because you ask forjj to do ... nothing.

So, you will need to enhance it with at least, one flag

plugin: my-plugin
runtime:
  docker:
    image: "myimage" // Docker Image name to use
actions:
  add:
    my-flag:
      help: Help about my flag
      required : true

This one expose 1 flag that forjj will list as possible and REQUIRED when we do a create.

So, you could ask forjj to provide this flag as follow:

forjj create ~/tmp/my-workspace --apps mycateg:myplugin --myplugin-my-flag flag-value
forjj create ~/tmp/my-workspace --apps mycateg:myplugin:myinstance --myinstance-my-flag flag-value
forjj add repo mycateg:myplugin --my-flag flag-value
forjj add repo mycateg:myplugin:myinstance --my-flag flag-value

In this case, forjj will create a workspace, add your plugin in the list of managed applications and provide the flag-value to the flag name my-first-flag

You can get some forjj internal variables with forjj-<data> Ex:

plugin: my-plugin
runtime:
  docker:
    image: "myimage" // Docker Image name to use
actions:
  add:
    my-flag:
      help: Help about my flag
      required : true
    forjj-organization:

In this example, forjj will provide a forjj-organization flag to your plugin with the organization name created by forjj.

Under actions, you can set common, create, update and maintain

Except common, those entries are main forjj actions for forjj infra object type.

common helps you to declare same flags for create and update.

Ex: --my-first-flag usable for create and update infra tasks

plugin: my-plugin
runtime:
  docker:
    image: "myimage" // Docker Image name to use
actions:
  common:
    my-common-flag:
      help: Help about my flag
      required : true

You can also expose some objects that your plugin will manage and that you want forjj to expose to end users.

Ex:

plugin: my-plugin
runtime:
  docker:
    image: "myimage" // Docker Image name to use
objects:
  user:
    flags:
      my-first-flag:
        help: Help about my flag
        required : true

In this case, you can add, update, remove, rename, list one or more user.

Ex:

forjj add user --my-first-flag flag-value
forjj remove user --my-first-flag flag-value
forjj list user
forjj create ~/tmp/my-workspace --apps categ:my-plugin

You can limit some flags to less actions:

plugin: my-plugin
runtime:
  docker:
    image: "myimage" // Docker Image name to use
objects:
  user:
    flags:
      my-first-flag:
        only-for-actions: ["add", "remove"]
        help: Help about my flag
        required : true

Documentation

Index

Constants

View Source
const (
	FilesSource = "source"
	FilesDeploy = "deploy"
)
View Source
const Latest = "latest"
View Source
const ObjectApp = "app"
View Source
const SocketPathLimit = 108 // See syscall.RawSockaddrUnix.Path in ztypes_linux_amd64.go - Linux limit

Variables

This section is empty.

Functions

func DefaultQuit

func DefaultQuit(w http.ResponseWriter, ExitMessage string)

func InArray

func InArray(v interface{}, in interface{}) (ok bool, i int)

func PingHandler

func PingHandler(w http.ResponseWriter, _ *http.Request)

Predefined Ping handler.

Types

type DockerContainer

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

DockerContainer is the named container information

func (*DockerContainer) AddEnv

func (d *DockerContainer) AddEnv(key, value string)

AddEnv add an environment variable to the container via -e key=value

func (*DockerContainer) AddHiddenEnv

func (d *DockerContainer) AddHiddenEnv(key, value string)

AddHiddenEnv add an environment variable to the container via -e key and the environment variable to the docker run command.

func (*DockerContainer) AddOpts

func (d *DockerContainer) AddOpts(opts ...string)

AddOpts add some docker options (passed before the image name)

func (*DockerContainer) AddVolume

func (d *DockerContainer) AddVolume(volume string)

AddVolume add a volume for a docker container

func (*DockerContainer) ContainerHasChanged

func (d *DockerContainer) ContainerHasChanged() (changed bool)

ContainerHasChanged simply return true is the container

func (*DockerContainer) Init

func (d *DockerContainer) Init(name string)

Init initialize the DockerContainer structure.

func (*DockerContainer) Inspect

func (d *DockerContainer) Inspect(name string, data string) (ret string, _ error)

Inspect the named container.

func (*DockerContainer) Logs

func (d *DockerContainer) Logs(dopts []string, out func(string)) error

Logs printout the log to the out function.

func (*DockerContainer) Name

func (d *DockerContainer) Name() string

Name return the container name to use.

func (*DockerContainer) Pull

func (d *DockerContainer) Pull(dopts []string) error

Pull the container image

func (*DockerContainer) Remove

func (d *DockerContainer) Remove() error

Remove a container

func (*DockerContainer) Run

func (d *DockerContainer) Run(cmd string, args []string) error

Run the container

func (*DockerContainer) SetImageName

func (d *DockerContainer) SetImageName(image string)

SetImageName define the image name to use for the container.

func (*DockerContainer) Start

func (d *DockerContainer) Start(dopts []string) error

Start the named container

func (*DockerContainer) Status

func (d *DockerContainer) Status() (string, error)

Status get container status field

func (*DockerContainer) Stop

func (d *DockerContainer) Stop(dopts []string) error

Stop stop the named container

type DockerService

type DockerService struct {
	Volumes map[string]byte
	Env     map[string]byte
}

type DockerStruct

type DockerStruct struct {
	Image   string            // Image name declared by the plugin.
	Dood    bool              `yaml:",omitempty"`
	Volumes []string          `yaml:",omitempty"`
	Env     map[string]string `yaml:",omitempty"`
	User    string            `yaml:",omitempty"`
}

type Driver

type Driver struct {
	// Driver define an instance of a driver
	Result *PluginResult // Json data structured returned.
	Yaml   *YamlPlugin   // Yaml data definition

	// in docker run syntax, -v Source_path:SourceMount
	Source_path string // Plugin source path from Forjj point of view
	SourceMount string // Where the driver will have his source code.

	// in docker run syntax, -v Workspace_path:WorkspaceMount
	Workspace_path string // Plugin Workspace path from Forjj point of view
	WorkspaceMount string // where the driver has his workspace.

	// in docker run syntax, -v DeployPath:DestMount
	DeployPath string // Plugin Deployment path
	DestMount  string // Where the driver will have his generated code.

	DeployName string // Plugin Deployment name in path

	Version string // Plugin version to load
	// contains filtered or unexported fields
}

func NewDriver

func NewDriver(plugin *YamlPlugin) (p *Driver)

func (*Driver) CheckServiceUp

func (p *Driver) CheckServiceUp() bool

func (*Driver) DefineDockerDood

func (p *Driver) DefineDockerDood() (err error)

DefineDockerDood detect and/or define DooD required parameters if the plugin requires it.

It uses goforjj/runcontext module to define and share for new DooD containers the DooD setup.

It manages 2 different context:

  • DOCKER_DOOD. It regroups options to enable DooD with docker socket, docker static binary and docker group ID Those data are set in the new container that forjj will create thanks to addVolume/Env/Opts functions given and "DOCKER_DOOD" will be the last docker env variable which contains all docker run options for the same, shared in the new container to be started by forjj. It requires the container to start as root , in order to update/create the docker group in the container if missing if the container have to be used as a user (non root) it must be created/assigned in the docker image.
  • DOCKER_DOOD_BECOME. It regroups options to enable impersonation in the container. The container started as root will ask the container to update few things and become the wanted user with a specific UID/GID given. The container have to update the wanted user UID and GID

func (*Driver) DefineDockerForjjMounts

func (p *Driver) DefineDockerForjjMounts() error

DefineDockerForjjMounts create a share of forjj driver mounts

func (*Driver) DefineDockerProxyParameters

func (p *Driver) DefineDockerProxyParameters()

DefineDockerProxyParameters return the list of Proxy parameters Shared as DOCKER_DOOD_PROXY

func (*Driver) GetDockerDoodParameters deprecated

func (p *Driver) GetDockerDoodParameters() (mount, become []string, err error)

Deprecated: GetDockerDoodParameters is kept for build compatibility. It is replaced by DefineDockerDooD()

func (*Driver) PluginBase

func (p *Driver) PluginBase(mount string)

PluginBase define the source Base mount to use for DooD mount

func (*Driver) PluginDefLoad

func (p *Driver) PluginDefLoad(yaml_data []byte) error

PluginDefLoad Load yaml raw data in YamlPlugin data structure

func (*Driver) PluginDockerBin

func (p *Driver) PluginDockerBin(thePath string) error

func (*Driver) PluginInit

func (p *Driver) PluginInit(instance string) error

PluginInit Initialize Plugin with Definition data.

func (*Driver) PluginLoadFrom

func (p *Driver) PluginLoadFrom(name string, runtime *YamlPluginRuntime) error

PluginLoadFrom do a load of the plugin Def Runtime section This information is saved by forjj to avoid reloding the plugin.yaml A plugin already loaded is not refreshed. NOTE: Workspace_path, Source_path and SourceMount must be set in PluginDef to make it work. TODO: Add a Plugin refresh? Not sure if forjj could do it or not differently...

func (*Driver) PluginRunAction

func (p *Driver) PluginRunAction(action string, d *PluginReqData) (*PluginResult, error)

PluginRunAction Function which will execute the action requested. If the plugin is a REST API, communicate with real basic REST API protocol Basic RESTFul means : GET/POST, simple unique route, no version, payload with everything. If needed in a next iteration, we can move the API to match fully the RESTFul API with forjj objects/actions. else start a shell or a container to get the json data.

func (*Driver) PluginSetDeployment

func (p *Driver) PluginSetDeployment(path string)

PluginSetDeployment set Deploy path from forjj perspective

func (*Driver) PluginSetDeploymentMount

func (p *Driver) PluginSetDeploymentMount(path string)

PluginSetDeploymentMount set Deploy path from forjj perspective

func (*Driver) PluginSetDeploymentName

func (p *Driver) PluginSetDeploymentName(name string)

func (*Driver) PluginSetSource

func (p *Driver) PluginSetSource(path string)

PluginSetSource Set plugin source path from forjj perspective. Created later by docker_start_service

func (*Driver) PluginSetSourceMount

func (p *Driver) PluginSetSourceMount(path string)

PluginSetSourceMount Set plugin source path mount where source will be mounted in the plugin container.

func (*Driver) PluginSetVersion

func (p *Driver) PluginSetVersion(version string)

func (*Driver) PluginSetWorkspace

func (p *Driver) PluginSetWorkspace(path string)

PluginSetWorkspace set workspace path from forjj perspective

func (*Driver) PluginSetWorkspaceMount

func (p *Driver) PluginSetWorkspaceMount(path string)

PluginSetWorkspaceMount set workspace path from forjj perspective

func (*Driver) PluginSocketPath

func (p *Driver) PluginSocketPath(path string)

PluginSocketPath Declare the socket path. It will be created later by function socket_prepare

func (*Driver) PluginStartService

func (p *Driver) PluginStartService() (err error)

PluginStartService This function start the service as daemon and register it If the service is already started, just use it.

func (*Driver) PluginStopService

func (p *Driver) PluginStopService()

PluginStopService To stop the plugin service if the service was started before by goforjj

func (*Driver) RunningFromDebugger

func (p *Driver) RunningFromDebugger()

func (*Driver) ServiceAddEnv

func (p *Driver) ServiceAddEnv(name, value string, hidden bool)

ServiceAddEnv add environment variable to the service runner

func (*Driver) SetDefaultMounts

func (p *Driver) SetDefaultMounts()

SetDefaultMounts defines container (src/deploy/workspace) mounts to default path

type ForjjPluginApp

type ForjjPluginApp struct {
	App     *kingpin.Application // The kingpin Application structure for CLI flags management.
	IsInfra *bool                // True when creating infra repositories
	Tasks   map[string]PluginTask
	Flags   map[string]*string // Values for global flags
}

type InstanceExtentKeys

type InstanceExtentKeys map[string]*ValueStruct

InstanceExtentKeys is the collection of key/values which is stored as "extent" in InstanceKeys.

type InstanceKeys

type InstanceKeys map[string]interface{}

InstanceKeys is a collection of key/values or under key "extent" a collection of key/values (intanceExtentKeys)

type ObjectInstances

type ObjectInstances map[string]InstanceKeys

ObjectInstances is a collection of instanceKeys

type PluginData

type PluginData struct {
	Repos         map[string]PluginRepo   `json:",omitempty"` // List of repository data
	Services      PluginService           `json:",omitempty"` // web service url. ex: https://github.hpe.com
	Status        string                  // Status message
	CommitMessage string                  `json:",omitempty"` // Action commit message for Create/Update
	ErrorMessage  string                  // Found only if error detected
	Files         map[string][]string     `json:",omitempty"` // List of files managed by the plugin
	Options       map[string]PluginOption `json:",omitempty"` // List of options needed at maintain use case, returned from create/update. Usually used to provide credentials.
}

REST API json data

func (*PluginData) AddFile

func (d *PluginData) AddFile(where, file string)

AddFile add a file the list of files Forjj will take care in GIT.

func (*PluginData) Errorf

func (o *PluginData) Errorf(s string, args ...interface{}) string

Errorf to store error message made by all other functions and return it to the API caller

func (*PluginData) StatusAdd

func (o *PluginData) StatusAdd(n string, args ...interface{}) string

StatusAdd Add status information to the API caller.

type PluginOption

type PluginOption struct {
	Help  string // Help about plugin options required at maintain phase
	Value string // Value set/loaded at create/update phase
}

type PluginRepo

type PluginRepo struct {
	Name          string                         // name of the repository
	Exist         bool                           // True if the repo exist.
	Remotes       map[string]PluginRepoRemoteUrl // k: remote name, v: remote url
	BranchConnect map[string]string              // k: local branch name, v: remote/branch
	Owner         string                         `json:",omitempty"` // Owner name return by the plugin.
}

func NewRepo

func NewRepo() *PluginRepo

func (*PluginRepo) GetOrigin

func (r *PluginRepo) GetOrigin(forGit bool) string

func (*PluginRepo) GetUpstream

func (r *PluginRepo) GetUpstream(forGit bool) string

GetUpstream Currently get the 'upstream' if exist or 'origin' url

type PluginRepoRemoteUrl

type PluginRepoRemoteUrl struct {
	Url string // Public URL (http or https)
	Ssh string // SSH String formatted as (ssh://User@Server:Path or User@Server:Path) for GIT
}

type PluginReqData

type PluginReqData struct {
	// Collection of Forjj flags requested by the plugin or given by default by Forjj
	Forj       map[string]string
	ForjExtent map[string]string `json:",omitempty"` // Extended Forjj flags
	// Define the list of Forjj objects data transmitted. object_type, instance, action.
	Objects map[string]ObjectInstances
	Creds   map[string]string `json:",omitempty"` // Contains credentials requested by the plugin for a specific action.
}

PluginReqData define the API data request to send to forjj plugins

func NewReqData

func NewReqData() (r *PluginReqData)

NewReqData return an empty API request structure.

func (*PluginReqData) AddObjectActions

func (r *PluginReqData) AddObjectActions(objectType, objectName string, keys InstanceKeys, extent InstanceExtentKeys, creds map[string]string)

AddObjectActions add in the request, the collection of keys/values or extent/keys/values for each objects/instances

func (*PluginReqData) SetForjFlag

func (r *PluginReqData) SetForjFlag(key, value string, cred, extent bool)

SetForjFlag initialize forj part of the request with key/value or extent key/value.

type PluginResult

type PluginResult struct {
	Data       PluginData
	State_code int // 200 OK
}

Shell json data

func (*PluginResult) JsonPrint

func (p *PluginResult) JsonPrint() error

JsonPrint to print out json data

type PluginService

type PluginService struct {
	Urls map[string]string
}

type PluginTask

type PluginTask struct {
	Cmd   *kingpin.CmdClause
	Flags map[string]*string // Values for commands flags.
}

Defines default internal structure to enhance in the plugin.

type Plugins

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

Plugins define a structure to store all plugins loaded.

func NewPlugins

func NewPlugins() (ret *Plugins)

NewPlugins create the list of plugins in memory.

func (*Plugins) Load

func (ps *Plugins) Load(instanceName, pluginName, pluginType string, loader map[string]func(*YamlPlugin) (yaml_data []byte, err error)) (driver *Driver, err error)

Load the instance plugin and return the driver object All plugin instances can share the same plugin. So that a plugin definition is loaded only once. But each driver are instance unique.

type ValueStruct

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

ValueStruct Represents a flag value. Can be of type string or []string

func NewValueStruct

func NewValueStruct(value interface{}) (ret *ValueStruct)

NewValueStruct Create a ValueStruct data from the input given. Support string and []string

func (*ValueStruct) Equal

func (v *ValueStruct) Equal(value *ValueStruct) bool

Equal return true, if value compared are equal. The equality depends on internal type: - string : string equality - []string : same list of elements and each elements are at the same position

func (*ValueStruct) Evaluate

func (v *ValueStruct) Evaluate(data interface{}) error

func (*ValueStruct) Get

func (v *ValueStruct) Get() (value interface{})

func (*ValueStruct) GetString

func (v *ValueStruct) GetString() string

func (*ValueStruct) GetStringSlice

func (v *ValueStruct) GetStringSlice() []string

func (ValueStruct) MarshalJSON

func (v ValueStruct) MarshalJSON() ([]byte, error)

func (ValueStruct) MarshalYAML

func (v ValueStruct) MarshalYAML() (interface{}, error)

func (*ValueStruct) Set

func (v *ValueStruct) Set(value interface{}) (ret *ValueStruct)

Set the Value given to ValueStruct. Support string and []string

func (*ValueStruct) SetIfFound

func (v *ValueStruct) SetIfFound(value interface{}, found bool) (ret *ValueStruct, ret_bool bool)

func (*ValueStruct) SetString

func (v *ValueStruct) SetString(value string)

func (*ValueStruct) Type

func (v *ValueStruct) Type() string

func (*ValueStruct) UnmarshalYAML

func (v *ValueStruct) UnmarshalYAML(unmarchal func(interface{}) error) error

type YamlFlag

type YamlFlag struct {
	Options      YamlFlagOptions `yaml:",inline"`
	Help         string
	FormatRegexp string   `yaml:"format-regexp"`
	Actions      []string `yaml:"only-for-actions"`

	// Define how flags are going to be declared to forjj cli as flags
	CliExport     bool     `yaml:"cli-exported"`            // true if the object flag must be exported to the forjj cli. Used by objects only.
	CliCmdActions []string `yaml:"cli-exported-to-actions"` // List of actions to export the flag to. Used for `application` object type only.

	Type      string `yaml:"of-type"`
	FlagScope string `yaml:"flag-scope"` // 'object' by default. Flag is not prefixed by instance name.
	// 'instance' Flag is prefixed by instance name if certain condition.
	FieldScope string `yaml:"fields-scope"` // 'object' by default. Means field is added at Object level.
	// contains filtered or unexported fields
}

data structure in /objects/<Object Name>/flags/<flag name>

flags:
  <flag name>:
    help: string - Help attached to the flag
    required: bool - true if this flag is required.

func (*YamlFlag) IsExtentFlag

func (f *YamlFlag) IsExtentFlag() bool

IsExtentFlag is True if the flag was defined as extent.

type YamlFlagOptions

type YamlFlagOptions struct {
	Required bool
	Hidden   bool   // Used by the plugin.
	Default  string // Used by the plugin.
	Secure   bool   // true if the data must be securely stored, ie not in the git repo. The flag must be defined in 'common' or 'maintain' flag group.
	Envar    string // Environment variable name to use.
}

type YamlObject

type YamlObject struct {
	Actions    []string `yaml:"default-actions"` // Collection of actions for the group given.
	Help       string
	FlagsScope string `yaml:"flags-scope"` // 'object' by default. flag name is NOT prefixed
	// 'instance' flag name is prefixed by instance name.
	FieldsScope string `yaml:"fields-scope"` // 'global' by default. Means field is added at Object level.
	// 'instance' Means fields is added at object instance level.
	Identified_by_flag string // Multiple object configuration. each instance will have a key from a flag value
	Groups             map[string]YamlObjectGroup
	Flags              map[string]YamlFlag
	Lists              map[string]YamlObjectList
}

YamlObject data structure in /objects/<Object Name>

flags:
  <flag name>:
    help: string - Help attached to the object
    actions: collection of forjj actions (add/update/rename/remove/list)

func (*YamlObject) FlagsRange

func (o *YamlObject) FlagsRange(action string) (res map[string]YamlFlag)

func (*YamlObject) HasValidKey

func (o *YamlObject) HasValidKey(key string) bool

type YamlObjectGroup

type YamlObjectGroup struct {
	Actions []string `yaml:"default-actions"` // Collection of actions for the group given.
	Flags   map[string]YamlFlag
}

data structure in /objects/<Object Name>/groups/<group_name>

type YamlObjectList

type YamlObjectList struct {
	Sep       string `yaml:"separator"`
	Help      string
	ExtRegexp string `yaml:"defined-by"`
}

data structure in /objects/<Object Name>/lists/<list_name>

type YamlPlugin

type YamlPlugin struct {
	Name                   string `yaml:"plugin"`
	Version                string `yaml:",omitempty"`
	Description            string `yaml:",omitempty"`
	CreatedFile            string `yaml:"created_flag_file"`
	ExtendRelPath          string `yaml:"extend_relative_path,omitempty"`
	Runtime                YamlPluginRuntime
	YamlPluginTasksObjects `yaml:",inline"`
	// contains filtered or unexported fields
}

Data structure in / --- plugin: string - Driver name (Name) version: string - driver version description: string - driver description runtime: struct - See YamlPluginRuntime actions: hash of struct - See YamlPluginDef - must be common/create/update/maintain as hash keys only.

func NewYamlPlugin

func NewYamlPlugin() (ret *YamlPlugin)

func (*YamlPlugin) MergeWith

func (p *YamlPlugin) MergeWith(instance string, extended *YamlPluginTasksObjects) (merged *YamlPlugin)

MergeWith creates a new Yamlplugin object built from a merged between this plugin and the extension. except instance Details, source data won't be modified as there is no object pointer

type YamlPluginComm

type YamlPluginComm struct {
	Socket     string   `yaml:",omitempty"`
	Port       uint     `yaml:",omitempty"`      // Not yet implemented
	Command    string   `yaml:",omitempty"`      // Not yet implemented
	Parameters []string `yaml:",omitempty,flow"` // Not yet implemented
}

data structure in /runtime/service 'service' defines how forjj communicate with the driver If service is not defined, socket will be used. runtime:

service:
  socket: string - default set to the driver name with '.sock' as extension.
                   The socket path is set by forjj.
                   Socket file name to use between forjj and the driver
  port: uint     - Port used to communicate between forjj and the driver
  parameters: Array of strings - List of parameters to provide to the shell/binary
                   Support {{Socket}}

type YamlPluginRuntime

type YamlPluginRuntime struct {
	Service_type string
	Docker       DockerStruct   `yaml:",omitempty"`
	Service      YamlPluginComm `yaml:",omitempty"`
}

data structure in /runtime runtime:

service_type: string - Support "REST API" and "shell"
                       REST API means the driver comply to REST API served as web service
                       shell means, the driver is called as shell with parameters and return a json data.
image_docker: string - Docker image containing the driver to start

type YamlPluginTasksObjects

type YamlPluginTasksObjects struct {
	Tasks   map[string]map[string]YamlFlag `yaml:"task_flags"`
	Objects map[string]YamlObject
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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