Skip to content

Commit

Permalink
sensuctl commands support (sensu#3274)
Browse files Browse the repository at this point in the history
* initial sensuctl command install & exec support

Signed-off-by: Justin Kolberg <[email protected]>

* add initial support for listing sensuctl commands

Signed-off-by: Justin Kolberg <[email protected]>

* add support for deleting sensuctl commands

Signed-off-by: Justin Kolberg <[email protected]>

* add context to ExecCommand args

Signed-off-by: Justin Kolberg <[email protected]>

* check asset type & provider before install

Signed-off-by: Justin Kolberg <[email protected]>

* appease the linter

Signed-off-by: Justin Kolberg <[email protected]>

* fix sensuctl command install via url

Signed-off-by: Justin Kolberg <[email protected]>

* verify checksum of command defs installed via url

Signed-off-by: Justin Kolberg <[email protected]>

* refresh tokens & set env for sensuctl commands

Signed-off-by: Justin Kolberg <[email protected]>

* bump go to 1.13.3

Signed-off-by: Justin Kolberg <[email protected]>

* verify go mods on appveyor

Signed-off-by: Justin Kolberg <[email protected]>

* use go mod download instead of verify

Signed-off-by: Justin Kolberg <[email protected]>

* RefreshAccessToken now takes *v2.Tokens

Signed-off-by: Justin Kolberg <[email protected]>

* add timeout to bolt in sensuctl command cmd

Signed-off-by: Justin Kolberg <[email protected]>

* start asset manager before opening commands.db to create cache dir

Signed-off-by: Justin Kolberg <[email protected]>

* update wording, make name && url/checksum flags mutually exclusive

Signed-off-by: Justin Kolberg <[email protected]>

* command install should use url to archive, not asset def

Signed-off-by: Justin Kolberg <[email protected]>

* return error when deleting a non-existant command

Signed-off-by: Justin Kolberg <[email protected]>

* add tests for InstallCommandFromBonsai

Signed-off-by: Justin Kolberg <[email protected]>

* add tests for InstallCommandFromURL

Signed-off-by: Justin Kolberg <[email protected]>

* add tests for ExecCommand

Signed-off-by: Justin Kolberg <[email protected]>

* append args to command in ExecCommand

Signed-off-by: Justin Kolberg <[email protected]>

* Get method for MockAssetGetter should use a pointer receiver

Signed-off-by: Justin Kolberg <[email protected]>
  • Loading branch information
amdprophet authored Nov 14, 2019
1 parent b908dcf commit 4a7d383
Show file tree
Hide file tree
Showing 16 changed files with 1,633 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cache:

environment:
GOPATH: c:\gopath
GOVERSION: 1.13.1
GOVERSION: 1.13.3
GO111MODULE: 'on'
GOPROXY: 'https://proxy.golang.org'

Expand All @@ -33,6 +33,7 @@ install:
- go version
- go env
- mkdir %GOPATH%\bin
- go mod download

platform:
- x64
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sensu_go_build_env: &sensu_go_build_env
#### /go/src/bitbucket.org/circleci/go-tool
working_directory: /go/src/github.com/sensu/sensu-go
docker:
- image: circleci/golang:1.13.1
- image: circleci/golang:1.13.3

jobs:
test:
Expand Down
28 changes: 28 additions & 0 deletions asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ package asset

import (
"context"
"fmt"
"os"
"path/filepath"
"strings"

corev2 "github.com/sensu/sensu-go/api/core/v2"
)
Expand Down Expand Up @@ -58,3 +61,28 @@ func (r *RuntimeAsset) LibDir() string {
func (r *RuntimeAsset) IncludeDir() string {
return filepath.Join(r.Path, includeDir)
}

// Env returns a list of environment variables (e.g. 'PATH=...', 'CPATH=...')
// with asset-specific paths prepended to the parent environment paths for
// each variable, allowing an asset to be used during execution.
func (r *RuntimeAsset) Env() []string {
assetEnv := []string{
fmt.Sprintf("PATH=%s${PATH}", r.joinPaths((*RuntimeAsset).BinDir)),
fmt.Sprintf("LD_LIBRARY_PATH=%s${LD_LIBRARY_PATH}", r.joinPaths((*RuntimeAsset).LibDir)),
fmt.Sprintf("CPATH=%s${CPATH}", r.joinPaths((*RuntimeAsset).IncludeDir)),
}
for i, envVar := range assetEnv {
// ExpandEnv replaces ${var} with the contents of var from the current
// environment, or an empty string if var doesn't exist.
assetEnv[i] = os.ExpandEnv(envVar)
}
return assetEnv
}

// joinPaths joins all paths of a given type for each asset in RuntimeAssetSet.
func (r *RuntimeAsset) joinPaths(pathFunc func(*RuntimeAsset) string) string {
var sb strings.Builder
sb.WriteString(pathFunc(r))
sb.WriteRune(os.PathListSeparator)
return sb.String()
}
5 changes: 5 additions & 0 deletions bonsai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type Config struct {
EndpointURL string
}

type Client interface {
FetchAsset(string, string) (*Asset, error)
FetchAssetVersion(string, string, string) (string, error)
}

// RestClient wraps resty.Client
type RestClient struct {
resty *resty.Client
Expand Down
Loading

0 comments on commit 4a7d383

Please sign in to comment.