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

Proxy shim for simplifying development environment workflow #1

Open
wants to merge 5 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ __pycache__/
# C extensions
*.so

# Test binary, build with `go test -c`
# Test binaries
*.test
sso-devproxy

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version := "v1.0.0"

commit := $(shell git rev-parse --short HEAD)

build: dist/sso-auth dist/sso-proxy
build: dist/sso-auth dist/sso-proxy dist/sso-devproxy

dist/sso-auth:
mkdir -p dist
Expand All @@ -12,6 +12,10 @@ dist/sso-proxy:
mkdir -p dist
go build -o dist/sso-proxy ./cmd/sso-proxy

dist/sso-devproxy:
mkdir -p dist
go build -o dist/sso-devproxy ./cmd/sso-devproxy

test:
./scripts/test

Expand Down
47 changes: 47 additions & 0 deletions cmd/sso-devproxy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"
"net/http"
"os"

"github.com/buzzfeed/sso/internal/devproxy"
log "github.com/buzzfeed/sso/internal/pkg/logging"
"github.com/kelseyhightower/envconfig"
)

func init() {
log.SetServiceName("sso-dev-proxy")
}

func main() {
logger := log.NewLogEntry()

opts := devproxy.NewOptions()

err := envconfig.Process("", opts)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right choice, to use environment variables for config. It's probably more common to use the flag package, but having a parallel structure to what's already there probably makes more sense.

if err != nil {
logger.Error(err, "error loading in env vars")
os.Exit(1)
}

err = opts.Validate()
if err != nil {
logger.Error(err, "error validing options")
os.Exit(1)
}

proxy, err := devproxy.NewDevProxy(opts)
if err != nil {
logger.Error(err, "error creating devproxy")
os.Exit(1)
}

s := &http.Server{
Addr: fmt.Sprintf(":%d", opts.Port),
ReadTimeout: opts.TCPReadTimeout,
WriteTimeout: opts.TCPWriteTimeout,
Handler: devproxy.NewLoggingHandler(os.Stdout, proxy.Handler(), opts.RequestLogging),
}
logger.Fatal(s.ListenAndServe())
}
Loading