-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
858 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.vscode* | ||
secretpublisher | ||
dist | ||
localvar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
env: | ||
- GO111MODULE=on | ||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
builds: | ||
# List of builds | ||
- # First Build | ||
env: | ||
- CGO_ENABLED=0 | ||
main: main.go | ||
ldflags: | ||
- -s -w -X main.Version={{.Version}} -X main.BuildInfo={{.Commit}} | ||
# Set the binary output location to bin/ so archive will comply with Sensu Go Asset structure | ||
binary: bin/{{ .ProjectName }} | ||
goos: | ||
- darwin | ||
- freebsd | ||
- linux | ||
- netbsd | ||
- solaris | ||
- windows | ||
goarch: | ||
- amd64 | ||
- 386 | ||
- arm | ||
- arm64 | ||
goarm: | ||
- 5 | ||
- 6 | ||
- 7 | ||
ignore: | ||
# TODO: add freebsd/arm support to gopsutil | ||
- goos: freebsd | ||
goarch: arm | ||
|
||
checksum: | ||
# You can change the name of the checksums file. | ||
# Default is `{{ .ProjectName }}_{{ .Version }}_checksums.txt`. | ||
name_template: "{{ .ProjectName }}_{{ .Version }}_sha512-checksums.txt" | ||
algorithm: sha512 | ||
|
||
archives: | ||
- | ||
format: tar.gz | ||
files: | ||
- LICENSE | ||
- README.md | ||
- CHANGELOG.md | ||
|
||
# You can change the name of the GitHub release. | ||
# This is parsed with the Go template engine and the following variables | ||
# are available: | ||
# - ProjectName | ||
# - Tag | ||
# - Version (Git tag without `v` prefix) | ||
# Default is `` | ||
#name_template: "{{.ProjectName}}-v{{.Version}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
language: go | ||
go: | ||
- 1.13.x | ||
install: | ||
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.22.2 | ||
script: | ||
- $(go env GOPATH)/bin/golangci-lint run | ||
- go test -v -race ./... | ||
|
||
before_script: | ||
- echo "REPO $TRAVIS_REPO_SLUG TAG ${TRAVIS_TAG}" | ||
|
||
deploy: | ||
- #goreleaser | ||
provider: script | ||
script: curl -sL https://git.io/goreleaser | bash | ||
skip_cleanup: true | ||
on: | ||
tags: true | ||
condition: $TRAVIS_OS_NAME = linux | ||
|
||
# after_deploy: | ||
# - git clone https://github.com/sensu/sensu-go-bonsai-asset.git bonsai | ||
# - bonsai/generate-sha512sum.sh | ||
# - bonsai/github-release-upload.sh github_api_token=$GITHUB_TOKEN repo_slug="$TRAVIS_REPO_SLUG" tag="${TRAVIS_TAG}" filename="dist/$(cat dist/sha512_file)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
## [0.0.1] - 2019-12-10 | ||
### Added | ||
- Sub-commands: create, update, check, delete to manage secrets and exist to check if one secret already exist and is up-to-date. | ||
- ENCODING_REQUEST variable to accepted only encoded requests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
secretpublisher | ||
============= | ||
|
||
Command line tool to use secretReceiver | ||
|
||
|
||
# Build | ||
|
||
```sh | ||
go build | ||
``` | ||
|
||
# Environment variables | ||
|
||
*ENCODING_REQUEST* is used to accepted only encoded requests. To send requests encoded, use [secretpublisher](githut.com/betorvs/secretpublisher) command line. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package appcontext | ||
|
||
import "sync" | ||
|
||
//List of consts containing the names of the available componentes in the Application Context - appcontext.Current | ||
const ( | ||
Repository = "Repository" | ||
) | ||
|
||
//Component is the Base interface for all Components | ||
type Component interface{} | ||
|
||
//ApplicationContext is the type defining a map of Components | ||
type ApplicationContext struct { | ||
components map[string]Component | ||
componentMu sync.Mutex | ||
} | ||
|
||
//Current keeps all components available, initialized in the application startup | ||
var Current ApplicationContext | ||
|
||
//Add a component By Name | ||
func (applicationContext *ApplicationContext) Add(componentName string, component Component) { | ||
applicationContext.componentMu.Lock() | ||
defer applicationContext.componentMu.Unlock() | ||
applicationContext.components[componentName] = component | ||
} | ||
|
||
//Get a component By Name | ||
func (applicationContext *ApplicationContext) Get(componentName string) Component { | ||
applicationContext.componentMu.Lock() | ||
defer applicationContext.componentMu.Unlock() | ||
return applicationContext.components[componentName] | ||
} | ||
|
||
//Delete a component By Name | ||
func (applicationContext *ApplicationContext) Delete(componentName string) { | ||
delete(applicationContext.components, componentName) | ||
} | ||
|
||
//Count returns the count of components registered | ||
func (applicationContext *ApplicationContext) Count() int { | ||
return len(applicationContext.components) | ||
} | ||
|
||
//CreateApplicationContext creates a new ApplicationContext instance | ||
func CreateApplicationContext() ApplicationContext { | ||
return ApplicationContext{components: make(map[string]Component)} | ||
} | ||
|
||
func init() { | ||
Current = CreateApplicationContext() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
// EncodingRequest string | ||
EncodingRequest string | ||
// ReceiverURL string | ||
ReceiverURL string | ||
// CommandTimeout string | ||
CommandTimeout string | ||
// SecretNamespace string | ||
SecretNamespace string | ||
// StringData map[string]string | ||
StringData map[string]string | ||
// PublisherTimeout time.Duration | ||
PublisherTimeout time.Duration | ||
// TestRun string | ||
TestRun string | ||
// Debug bool | ||
Debug bool | ||
) | ||
|
||
// ParseStringData func | ||
func ParseStringData() map[string]string { | ||
data := make(map[string]string) | ||
if os.Getenv("STRING_DATA") != "" { | ||
values := strings.Split(os.Getenv("STRING_DATA"), ",") | ||
for _, e := range values { | ||
parts := strings.Split(e, "=") | ||
data[parts[0]] = parts[1] | ||
} | ||
} | ||
return data | ||
} | ||
|
||
// ConfigureRootCommand func | ||
func ConfigureRootCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "secretpublisher", | ||
Short: "\nsecretpublisher is a command line tool to interact with secretreceiver", | ||
RunE: run, | ||
} | ||
cmd.PersistentFlags().StringVar(&EncodingRequest, "encodingRequest", os.Getenv("ENCODING_REQUEST"), "use ENCODING_REQUEST environment variable") | ||
cmd.PersistentFlags().StringVar(&ReceiverURL, "receiverURL", os.Getenv("RECEIVER_URL"), "use RECEIVER_URL environment variable") | ||
cmd.PersistentFlags().StringVar(&TestRun, "testRun", "false", "use TESTRUN environment variable") | ||
cmd.PersistentFlags().BoolVar(&Debug, "debug", false, "add --debug in the command") | ||
cmd.PersistentFlags().StringVar(&CommandTimeout, "commandTimeout", os.Getenv("COMMAND_TIMEOUT"), "use COMMAND_TIMEOUT environment variable") | ||
// cmd.PersistentFlags().StringToStringVar(&StringData, "stringData", getEnv(), "use STRING_DATA environment variable like: name=path_to_file,") | ||
return cmd | ||
} | ||
|
||
// run func do everything | ||
func run(cmd *cobra.Command, args []string) error { | ||
if ReceiverURL == "" { | ||
return fmt.Errorf("ReceiverURL is empty") | ||
} | ||
if EncodingRequest == "" { | ||
EncodingRequest = "disabled" | ||
} | ||
tmpTimeout, err := strconv.Atoi(CommandTimeout) | ||
if err != nil { | ||
tmpTimeout = 15 | ||
} | ||
PublisherTimeout = time.Duration(tmpTimeout) | ||
// errManage := usecase.ManageSecret() | ||
// if errManage != nil { | ||
// return errManage | ||
// } | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package domain | ||
|
||
import "github.com/betorvs/secretpublisher/appcontext" | ||
|
||
// Secret struct | ||
type Secret struct { | ||
Name string `json:"name"` | ||
Namespace string `json:"namespace"` | ||
Checksum string `json:"checksum"` | ||
Data map[string]string `json:"data"` | ||
} | ||
|
||
// Repository interface | ||
type Repository interface { | ||
appcontext.Component | ||
GetSecretByName(secret string, namespace string) (string, error) | ||
PostOrPUTSecret(method string, secret string, body []byte) error | ||
DeleteSecret(secret string, namespace string) error | ||
} | ||
|
||
// GetRepository func return Repository interface | ||
func GetRepository() Repository { | ||
return appcontext.Current.Get(appcontext.Repository).(Repository) | ||
} |
Oops, something went wrong.