Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Naming adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvdg committed Mar 6, 2019
1 parent 1837a96 commit 7d3724f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions cmd/secrethub-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"os/signal"
"syscall"

"github.com/keylockerbv/secrethub-clientd/pkg/restproxy"
"github.com/keylockerbv/secrethub-go/pkg/secrethub"
"github.com/keylockerbv/secrethub-proxy/pkg/restproxy"
)

var (
Expand Down Expand Up @@ -39,7 +39,7 @@ func init() {
}

func main() {
proxy := restproxy.NewSecretHubRESTProxy(client, port)
proxy := restproxy.NewRESTProxy(client, port)

go gracefulShutdown(proxy)

Expand All @@ -50,7 +50,7 @@ func main() {
}
}

func gracefulShutdown(proxy restproxy.SecretHubProxy) {
func gracefulShutdown(proxy restproxy.ClientProxy) {
sigint := make(chan os.Signal, 1)

signal.Notify(sigint, os.Interrupt)
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/keylockerbv/secrethub v0.17.0 h1:ynvH2JWotytvtLpGE8Bu4hPIV1m+OS/tTlmTGlv8Hmk=
github.com/keylockerbv/secrethub v0.17.0/go.mod h1:EibHbXBS5k+Cw+XEo4rveG+ONA2Czl1VFpVl7+jDYOc=
github.com/keylockerbv/secrethub-clientd v0.0.0-20190225134359-9c3d34a96705 h1:5fRK0U5z2CtqZsRha/5+cdyazD/4zjzcfODaoE2ZCzI=
github.com/keylockerbv/secrethub-go v0.0.0-20190225132925-244d98858e9d h1:NxCFGfkmBF9RaloxF5c/J5knS3FE/g+uWOZ9ENucc1M=
github.com/keylockerbv/secrethub-go v0.0.0-20190225132925-244d98858e9d/go.mod h1:U086plZMagUfy92G4DgCsRAns20Q5j+Rf8bYDXiDxMw=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand Down
32 changes: 16 additions & 16 deletions pkg/restproxy/rest_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ import (
"github.com/keylockerbv/secrethub/core/errio"
)

// SecretHubProxy gives the SecretHub Client a certain communication layer
type SecretHubProxy interface {
// ClientProxy gives the SecretHub Client a certain communication layer
type ClientProxy interface {
Start() error
Stop() error
}

type secretHubRESTProxy struct {
SecretHubProxy
type restProxy struct {
ClientProxy
client secrethub.Client
server *http.Server
}

// NewSecretHubRESTProxy creates a proxy of the SecretHub Client, giving it a RESTful interface
func NewSecretHubRESTProxy(client secrethub.Client, port int) SecretHubProxy {
// NewRESTProxy creates a proxy for the SecretHub Client, giving it a RESTful interface
func NewRESTProxy(client secrethub.Client, port int) ClientProxy {
if port == 0 {
port = 8080
}

router := mux.NewRouter()
proxy := &secretHubRESTProxy{
proxy := &restProxy{
client: client,
server: &http.Server{
Addr: fmt.Sprintf(":%v", port),
Expand All @@ -44,25 +44,25 @@ func NewSecretHubRESTProxy(client secrethub.Client, port int) SecretHubProxy {
return proxy
}

func (proxy *secretHubRESTProxy) addRoutes(r *mux.Router) {
func (p *restProxy) addRoutes(r *mux.Router) {
v1 := r.PathPrefix("/v1/").Subrouter()

v1.PathPrefix("/secrets/").Handler(
http.StripPrefix("/v1/secrets/", http.HandlerFunc(proxy.handleSecret)),
http.StripPrefix("/v1/secrets/", http.HandlerFunc(p.handleSecret)),
)
}

// Start starts the SecretHub REST proxy, starting an HTTP server
func (proxy *secretHubRESTProxy) Start() error {
return proxy.server.ListenAndServe()
func (p *restProxy) Start() error {
return p.server.ListenAndServe()
}

// Stop stops the SecretHub REST proxy, stopping the HTTP server
func (proxy *secretHubRESTProxy) Stop() error {
return proxy.server.Shutdown(context.Background())
func (p *restProxy) Stop() error {
return p.server.Shutdown(context.Background())
}

func (proxy *secretHubRESTProxy) handleSecret(w http.ResponseWriter, r *http.Request) {
func (p *restProxy) handleSecret(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
err := api.ValidateSecretPath(path)
if err != nil {
Expand All @@ -73,7 +73,7 @@ func (proxy *secretHubRESTProxy) handleSecret(w http.ResponseWriter, r *http.Req

switch r.Method {
case "GET":
secret, err := proxy.client.Secrets().Versions().GetWithData(path)
secret, err := p.client.Secrets().Versions().GetWithData(path)
if err != nil {
var errCode int

Expand All @@ -100,7 +100,7 @@ func (proxy *secretHubRESTProxy) handleSecret(w http.ResponseWriter, r *http.Req
return
}

_, err = proxy.client.Secrets().Write(path, secret)
_, err = p.client.Secrets().Write(path, secret)
if err != nil {
var errCode int

Expand Down

0 comments on commit 7d3724f

Please sign in to comment.