hooks

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: Apache-2.0 Imports: 10 Imported by: 2

README

edgex-snap-hooks

Snap hooks library use by Go EdgeX service snaps.

What is this repository for?

This module provides support for Go-based configure an install hooks...

Installation
  • Make sure you have modules enabled, i.e. have an initialized go.mod file
  • If your code is in your GOPATH then make sure GO111MODULE=on is set
  • Run go get github.com/canonical/edgex-snap-hooks
    • This will add the edgex-snap-hooks to the go.mod file and download it into the module cache
How to Use

Documentation

Index

Constants

View Source
const (
	// AutostartConfig is a configuration key used indicate that a
	// service (application or device) should be autostarted on install
	AutostartConfig = "autostart"
	// EnvConfig is the prefix used for configure hook keys used for
	// EdgeX configuration overrides.
	EnvConfig = "env"
	// ProfileConfig is a configuration key that specifies a named
	// configuration profile
	ProfileConfig = "profile"
	// ServiceConsul is the service key for Consul.
	ServiceConsul = "consul"
	// ServiceRedis is the service key for Redis.
	ServiceRedis = "redis"
	// ServiceData is the service key for EdgeX Core Data.
	ServiceData = "core-data"
	// ServiceMetadata is the service key for EdgeX Core MetaData.
	ServiceMetadata = "core-metadata"
	// ServiceCommand is the service key for EdgeX Core Command.
	ServiceCommand = "core-command"
	// ServiceNotify is the service key for EdgeX Support Notifications.
	ServiceNotify = "support-notifications"
	// ServiceSched is the service key for EdgeX Support Scheduler.
	ServiceSched = "support-scheduler"
	// ServiceAppCfg is the service key for EdgeX App Service Configurable.
	ServiceAppCfg = "app-service-configurable"
	// ServiceDevVirt is the service key for EdgeX Device Virtual.
	ServiceDevVirt = "device-virtual"
	// ServiceSecStore is the service key for EdgeX Security Secret Store (aka Vault).
	ServiceSecStore = "security-secret-store"
	// ServiceProxy is the service key for EdgeX API Gateway (aka Kong).
	ServiceProxy = "security-proxy"
	// ServiceSysMgmt is the service key for EdgeX SMA (sys-mgmt-agent).
	ServiceSysMgmt = "sys-mgmt-agent"
	// ServiceKuiper is the service key for the Kuiper rules engine.
	ServiceKuiper = "kuiper"
)

Variables

View Source
var (

	// Snap contains the value of the SNAP environment variable.
	Snap string
	// SnapConf contains the expanded path '$SNAP/config'.
	SnapConf string
	// SnapCommon contains the value of the SNAP_COMMON environment variable.
	SnapCommon string
	// SnapData contains the value of the SNAP_DATA environment variable.
	SnapData string
	// SnapDataConf contains the expanded path '$SNAP_DATA/config'.
	SnapDataConf string
	// SnapInst contains the value of the SNAP_INSTANCE_NAME environment variable.
	SnapInst string
	// SnapName contains the value of the SNAP_NAME environment variable.
	SnapName string
	// SnapRev contains the value of the SNAP_REVISION environment variable.
	SnapRev string
)
View Source
var ConfToEnv = map[string]string{

	"service.boot-timeout":     "SERVICE_BOOTTIMEOUT",
	"service.check-interval":   "SERVICE_CHECKINTERVAL",
	"service.host":             "SERVICE_HOST",
	"service.server-bind-addr": "SERVICE_SERVERBINDADDR",
	"service.port":             "SERVICE_PORT",
	"service.protocol":         "SERVICE_PROTOCOL",
	"service.max-result-count": "SERVICE_MAXRESULTCOUNT",
	"service.read-max-limit":   "SERVICE_READMAXLIMIT",
	"service.startup-msg":      "SERVICE_STARTUPMSG",
	"service.timeout":          "SERVICE_TIMEOUT",

	"clients.command.port": "CLIENTS_COMMAND_PORT",

	"clients.coredata.port": "CLIENTS_COREDATA_PORT",

	"clients.data.port": "CLIENTS_DATA_PORT",

	"clients.metadata.port": "CLIENTS_METADATA_PORT",

	"clients.notifications.port": "CLIENTS_NOTIFICATIONS_PORT",

	"clients.scheduler.port": "CLIENTS_SCHEDULER_PORT",

	"messagequeue.topic": "core-data/MESSAGEQUEUE_TOPIC",

	"secretstore.additional-retry-attempts": "SECRETSTORE_ADDITIONALRETRYATTEMPTS",
	"secretstore.retry-wait-period":         "SECRETSTORE_RETRYWAITPERIOD",

	"binding.type":            "app/BINDING_TYPE",
	"binding.subscribe-topic": "app/BINDING_SUBSCRIBE_TOPIC",
	"binding.publish-topic":   "app/BINDING_PUBLISH_TOPIC",

	"message-bus.subscribe-host.port": "app/MESSAGEBUS_SUBSCRIBEHOST_PORT",

	"message-bus.publish-host.port": "app/MESSAGEBUS_PUBLISHHOST_PORT",

	"smtp.host":                    "support-notifications/SMTP_HOST",
	"smtp.username":                "support-notifications/SMTP_USERNAME",
	"smtp.password":                "support-notifications/SMTP_PASSWORD",
	"smtp.port":                    "support-notifications/SMTP_PORT",
	"smtp.sender":                  "support-notifications/SMTP_SENDER",
	"smtp.enable-self-signed-cert": "support-notifications/SMTP_ENABLE_SELF_SIGNED_CERT",

	"add-proxy-route": "security-proxy/ADD_PROXY_ROUTE",

	"kongauth.name": "security-proxy/KONGAUTH_NAME",

	"add-secretstore-tokens": "security-secret-store/ADD_SECRETSTORE_TOKENS",
}

ConfToEnv defines mappings from snap config keys to EdgeX environment variable names that are used to override individual service configuration values via a .env file read by the snap service wrapper.

The syntax to set a configuration key is:

env.<service name>.<section>.<keyname>

Services is a string array of all of the edgexfoundry snap services.

Functions

func CopyFile

func CopyFile(srcPath, destPath string) error

CopyFile copies a file within the snap

func CopyFileReplace

func CopyFileReplace(srcPath, destPath string, rStrings map[string]string) error

CopyFileReplace copies a file within the snap and replaces strings using the string/replace values in the rStrings parameter.

func Debug

func Debug(msg string)

Debug writes the given msg to sylog (sev=LOG_DEBUG) if the associated global snap 'debug' configuration flag is set to 'true'.

func Error

func Error(msg string)

Error writes the given msg to sylog (sev=LOG_ERROR).

func HandleEdgeXConfig

func HandleEdgeXConfig(service, envJSON string, extraConf map[string]string) error

HandleEdgeXConfig processes snap configuration which can be used to override edgexfoundry configuration via environment variables sourced by the snap service wrapper script. The parameter service is used to create a new service specific file (named <service>.env) in the $SNAP_DATA/config/res directory of the service. The parameter envJSON is a JSON document holding the service's configuration as returned by snapd. The parameter extraConfig is a map of additional configuration keys supported by the snap. For example the following configuration option:

[Driver] MyDriverOption = "foo"

...would require an entry in extraConf like this:

extraConf["driver.mydriveroption"]"DRIVER_MYDRIVEROPTION"

.. and would be set like this for a device or application service:

``` $ sudo snap set mysnap env.driver.mydriveroption="foo" ```

func Info

func Info(msg string)

Info writes the given msg to sylog (sev=LOG_INFO).

func Init

func Init(setDebug bool, snapName string) error

Init creates a new syslog instance for the hook, sets the global debug flag based on the value of the setDebug parameter, and initializes global variables for the commonly used SNAP_ environment variables.

func Warn

func Warn(msg string)

Warn writes the given msg to sylog (sev=LOG_WARNING).

Types

type CtlCli

type CtlCli struct{}

CtlCli is the test obj for overridding functions

func NewSnapCtl

func NewSnapCtl() *CtlCli

NewSnapCtl returns a normal runtime client

func (*CtlCli) Config

func (cc *CtlCli) Config(key string) (string, error)

Config uses snapctl to get a value from a key, or returns error.

func (*CtlCli) SetConfig

func (cc *CtlCli) SetConfig(key string, val string) error

SetConfig uses snapctl to set a config value from a key, or returns error.

func (*CtlCli) Start

func (cc *CtlCli) Start(svc string, enable bool) error

Start uses snapctrl to start a service and optionally enable it

func (*CtlCli) Stop

func (cc *CtlCli) Stop(svc string, disable bool) error

Stop uses snapctrl to stop a service and optionally disable it

type SnapCtl

type SnapCtl interface {
	Config(key string) (string, error)
	SetConfig(key string, val string) error
	Stop(svc string, disable bool) error
}

SnapCtl interface provides abstration for unit testing

Jump to

Keyboard shortcuts

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