diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..261f45a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,250 @@ + +# Created by https://www.gitignore.io/api/macos,windows,go,vim,emacs,sublimetext,textmate,visualstudiocode,windows,eclipse + +### macOS ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon +# Thumbnails +._* +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### Windows ### +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +### Go ### +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# external packages folder +vendor/ + + +### Vim ### +# swap +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +# session +Session.vim +# temporary +.netrwhist +*~ +# auto-generated tag files +tags + + +### Emacs ### +# -*- mode: gitignore; -*- +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + + +### SublimeText ### +# cache files for sublime text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# workspace files are user-specific +*.sublime-workspace + +# project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using SublimeText +# *.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + + +### TextMate ### +*.tmproj +*.tmproject +tmtags + + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + + +### Windows ### +# Windows image file caches + +# Folder config file + +# Recycle Bin used on file shares + +# Windows Installer files + +# Windows shortcuts + + +### Eclipse ### + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..0bb7d049 --- /dev/null +++ b/Makefile @@ -0,0 +1,124 @@ +# Metadata about this makefile and position +MKFILE_PATH := $(lastword $(MAKEFILE_LIST)) +CURRENT_DIR := $(dir $(realpath $(MKFILE_PATH))) +CURRENT_DIR := $(CURRENT_DIR:/=) + +# Get the project metadata +GOVERSION := 1.7.4 +VERSION := 0.1.0 +PROJECT := github.com/hashicorp/consul-template +OWNER := $(dir $(PROJECT)) +OWNER := $(notdir $(OWNER:/=)) +NAME := $(notdir $(PROJECT)) +EXTERNAL_TOOLS = + +# Current system information (this is the invoking system) +ME_OS = $(shell go env GOOS) +ME_ARCH = $(shell go env GOARCH) + +# Default os-arch combination to build +XC_OS ?= linux +XC_ARCH ?= amd64 +XC_EXCLUDE ?= + +# GPG Signing key (blank by default, means no GPG signing) +GPG_KEY ?= + +# List of tests to run +TEST ?= ./... + +# List all our actual files, excluding vendor +GOFILES = $(shell go list $(TEST) | grep -v /vendor/) + +# bin builds the project by invoking the compile script inside of a Docker +# container. Invokers can override the target OS or architecture using +# environment variables. +bin: + @echo "==> Building ${PROJECT}..." + @docker run \ + --rm \ + --env="VERSION=${VERSION}" \ + --env="PROJECT=${PROJECT}" \ + --env="OWNER=${OWNER}" \ + --env="NAME=${NAME}" \ + --env="XC_OS=${XC_OS}" \ + --env="XC_ARCH=${XC_ARCH}" \ + --env="XC_EXCLUDE=${XC_EXCLUDE}" \ + --env="DIST=${DIST}" \ + --workdir="/go/src/${PROJECT}" \ + --volume="${CURRENT_DIR}:/go/src/${PROJECT}" \ + "golang:${GOVERSION}" /usr/bin/env sh -c "scripts/compile.sh" + +# bin-local builds the project using the local go environment. This is only +# recommended for advanced users or users who do not wish to use the Docker +# build process. +bin-local: + @echo "==> Building ${PROJECT} (locally)..." + @env \ + VERSION="${VERSION}" \ + PROJECT="${PROJECT}" \ + OWNER="${OWNER}" \ + NAME="${NAME}" \ + XC_OS="${XC_OS}" \ + XC_ARCH="${XC_ARCH}" \ + XC_EXCLUDE="${XC_EXCLUDE}" \ + DIST="${DIST}" \ + /usr/bin/env sh -c "scripts/compile.sh" + +# bootstrap installs the necessary go tools for development or build +bootstrap: + @echo "==> Bootstrapping ${PROJECT}..." + @for t in ${EXTERNAL_TOOLS}; do \ + echo "--> Installing "$$t"..." ; \ + go get -u "$$t"; \ + done + +# deps gets all the dependencies for this repository and vendors them. +deps: + @echo "==> Updating dependencies..." + @echo "--> Installing dependency manager..." + @go get -u github.com/kardianos/govendor + @govendor init + @echo "--> Installing all dependencies..." + @govendor fetch -v +outside + +# dev builds the project for the current system as defined by go env. +dev: + @env \ + XC_OS="${ME_OS}" \ + XC_ARCH="${ME_ARCH}" \ + $(MAKE) -f "${MKFILE_PATH}" bin + @echo "--> Moving into bin/" + @mkdir -p "${CURRENT_DIR}/bin/" + @cp "${CURRENT_DIR}/pkg/${ME_OS}_${ME_ARCH}/${NAME}" "${CURRENT_DIR}/bin/" +ifdef GOPATH + @echo "--> Moving into GOPATH/" + @mkdir -p "${GOPATH}/bin/" + @cp "${CURRENT_DIR}/pkg/${ME_OS}_${ME_ARCH}/${NAME}" "${GOPATH}/bin/" +endif + +# dist builds the binaries and then signs and packages them for distribution +dist: + @${MAKE} -f "${MKFILE_PATH}" bin DIST=1 + @echo "==> Tagging release (v${VERSION})..." +ifdef GPG_KEY + @git commit --allow-empty --gpg-sign="${GPG_KEY}" -m "Release v${VERSION}" + @git tag -a -m "Version ${VERSION}" -s -u "${GPG_KEY}" "v${VERSION}" master + @gpg --default-key "${GPG_KEY}" --detach-sig "${CURRENT_DIR}/pkg/dist/${NAME}_${VERSION}_SHA256SUMS" +else + @git commit --allow-empty -m "Release v${VERSION}" + @git tag -a -m "Version ${VERSION}" "v${VERSION}" master +endif + +# test runs the test suite +test: + @echo "==> Testing ${PROJECT}..." + @go test -timeout=60s -parallel=10 ${GOFILES} ${TESTARGS} + +# test-race runs the race checker +test-race: + @echo "==> Testing ${PROJECT} (race)..." + @go test -timeout=60s -race ${GOFILES} ${TESTARGS} + +.PHONY: bin bin-local bootstrap deps dev dist test test-race + diff --git a/broker.go b/broker.go new file mode 100644 index 00000000..dc948606 --- /dev/null +++ b/broker.go @@ -0,0 +1,69 @@ +package main + +import ( + "context" + + "code.cloudfoundry.org/lager" + + "github.com/pivotal-cf/brokerapi" +) + +var _ brokerapi.ServiceBroker = (*Broker)(nil) + +type Broker struct { + log lager.Logger +} + +func (b *Broker) Services(ctx context.Context) []brokerapi.Service { + b.log.Debug("building services catalog") + return nil +} + +func (b *Broker) Provision(ctx context.Context, instanceID string, details brokerapi.ProvisionDetails, async bool) (brokerapi.ProvisionedServiceSpec, error) { + b.log.Debug("provisioning new instance", lager.Data{ + "instance-id": instanceID, + }) + + return brokerapi.ProvisionedServiceSpec{}, nil +} + +func (b *Broker) Deprovision(ctx context.Context, instanceID string, details brokerapi.DeprovisionDetails, async bool) (brokerapi.DeprovisionServiceSpec, error) { + b.log.Debug("deprovisioning new instance", lager.Data{ + "instance-id": instanceID, + }) + + return brokerapi.DeprovisionServiceSpec{}, nil +} + +func (b *Broker) Bind(ctx context.Context, instanceID, bindingID string, details brokerapi.BindDetails) (brokerapi.Binding, error) { + b.log.Debug("binding service", lager.Data{ + "binding-id": bindingID, + "instance-id": instanceID, + }) + + return brokerapi.Binding{}, nil +} + +func (b *Broker) Unbind(ctx context.Context, instanceID, bindingID string, details brokerapi.UnbindDetails) error { + b.log.Debug("unbinding service", lager.Data{ + "binding-id": bindingID, + "instance-id": instanceID, + }) + + return nil +} + +func (b *Broker) Update(ctx context.Context, instanceID string, details brokerapi.UpdateDetails, async bool) (brokerapi.UpdateServiceSpec, error) { + b.log.Debug("updating service", lager.Data{ + "instance-id": instanceID, + }) + return brokerapi.UpdateServiceSpec{}, nil +} + +func (b *Broker) LastOperation(ctx context.Context, instanceID, operationData string) (brokerapi.LastOperation, error) { + b.log.Debug("returning last operation", lager.Data{ + "instance-id": instanceID, + }) + + return brokerapi.LastOperation{}, nil +} diff --git a/broker_test.go b/broker_test.go new file mode 100644 index 00000000..56bec7d9 --- /dev/null +++ b/broker_test.go @@ -0,0 +1,31 @@ +package main + +import "testing" + +func TestBroker_Services(t *testing.T) { + t.Skip("pending") +} + +func TestBroker_Provision(t *testing.T) { + t.Skip("pending") +} + +func TestBroker_Deprovision(t *testing.T) { + t.Skip("pending") +} + +func TestBroker_Bind(t *testing.T) { + t.Skip("pending") +} + +func TestBroker_Unbind(t *testing.T) { + t.Skip("pending") +} + +func TestBroker_Update(t *testing.T) { + t.Skip("pending") +} + +func TestBroker_LastOperation(t *testing.T) { + t.Skip("pending") +} diff --git a/main.go b/main.go new file mode 100644 index 00000000..34f633dd --- /dev/null +++ b/main.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "log" + "os" + "strings" + + "code.cloudfoundry.org/lager" +) + +func main() { + logLevel, err := parseLogLevel(os.Getenv("LOG_LEVEL")) + if err != nil { + log.Fatal(err) + } + + log := lager.NewLogger("vault-broker") + log.RegisterSink(lager.NewWriterSink(os.Stderr, logLevel)) +} + +// parseLogLevel takes a string and returns an associated lager log level or +// an error if one does not exist. +func parseLogLevel(s string) (lager.LogLevel, error) { + switch strings.ToUpper(s) { + case "DEBUG": + return lager.DEBUG, nil + case "INFO": + return lager.INFO, nil + case "ERROR": + return lager.ERROR, nil + case "FATAL": + return lager.FATAL, nil + default: + return 0, fmt.Errorf("invalid log level %q", s) + } +} diff --git a/scripts/compile.sh b/scripts/compile.sh new file mode 100755 index 00000000..2cb08897 --- /dev/null +++ b/scripts/compile.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env sh +set -e + +if [ -z "$NAME" ]; then + echo "Missing \$NAME!" + exit 127 +fi + +if [ -z "$PROJECT" ]; then + echo "Missing \$PROJECT!" + exit 127 +fi + +# Get the git commit information +GIT_COMMIT="$(git rev-parse --short HEAD)" +GIT_DIRTY="$(test -n "$(git status --porcelain)" && echo "+CHANGES" || true)" + +# Remove old builds +rm -rf bin/* +rm -rf pkg/* + +# Runtime variables +LDFLAGS="-s -w" +LDFLAGS="$LDFLAGS -X main.Name=${NAME}" +LDFLAGS="$LDFLAGS -X main.Version=${VERSION}" +LDFLAGS="$LDFLAGS -X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" + +# Build! +for GOOS in $XC_OS; do + for GOARCH in $XC_ARCH; do + COMBO="${GOOS}/${GOARCH}" + if test "${XC_EXCLUDE#*$COMBO}" != "${XC_EXCLUDE}"; then + printf "%s%20s %s\n" "-->" "${GOOS}/${GOARCH}:" "${PROJECT} (excluded)" + continue + fi + + printf "%s%20s %s\n" "-->" "${GOOS}/${GOARCH}:" "${PROJECT}" + env -i \ + PATH="$PATH" \ + CGO_ENABLED=0 \ + GOPATH="$GOPATH" \ + GOROOT="$GOROOT" \ + GOOS="${GOOS}" \ + GOARCH="${GOARCH}" \ + go build \ + -a \ + -ldflags="$LDFLAGS" \ + -o="pkg/${GOOS}_${GOARCH}/${NAME}" \ + . + done +done + +# If we are not in distribution mode, exit now +if [ -z "$DIST" ]; then + exit 0 +fi + +echo "--> Compressing..." + +mkdir pkg/dist +for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do + OSARCH=$(basename ${PLATFORM}) + if [ "$OSARCH" = "dist" ]; then + continue + fi + + cd $PLATFORM + tar -czf ../dist/${NAME}_${VERSION}_${OSARCH}.tgz ${NAME} + cd - >/dev/null 2>&1 +done + +echo "--> Checksumming..." +cd pkg/dist +shasum -a256 * > "${NAME}_${VERSION}_SHA256SUMS" +cd - >/dev/null 2>&1 + diff --git a/server.go b/server.go new file mode 100644 index 00000000..57f2ade9 --- /dev/null +++ b/server.go @@ -0,0 +1,3 @@ +package main + +type Server struct{}