Skip to content

Commit f4494a1

Browse files
authored
Update go version and fix small errors (#8)
* Update to go 1.15 * Upadate mux version * Add linter and fix lint errors * Fix spelling in README
1 parent f4f6163 commit f4494a1

File tree

9 files changed

+56
-30
lines changed

9 files changed

+56
-30
lines changed

.github/workflows/go-test.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/go.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: go
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: golangci-lint
15+
uses: golangci/golangci-lint-action@v1
16+
with:
17+
version: v1.30
18+
args: -E misspell
19+
test:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Setup go
24+
uses: actions/setup-go@v1
25+
with:
26+
go-version: 1.15
27+
- run: make test

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.14.4 as builder
1+
FROM golang:1.15 as builder
22
RUN mkdir /build
33
ADD . /build/
44
WORKDIR /build

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ assets:
55
draw.io -b 10 -x -f png -p 0 -o assets/architecture.png assets/diagram.drawio
66
.PHONY: assets
77

8+
lint:
9+
golangci-lint run -E misspell
10+
811
fmt:
912
go fmt ./...
1013

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ of automation cumbersome if multiple tokens are needed with limited scopes.
1212
<img src="./assets/architecture.png">
1313
</p>
1414

15-
Azure Devops Proxy (azdo-proxy) is an attempt to solve this issue by enabling a single PAT
15+
Azure DevOps Proxy (azdo-proxy) is an attempt to solve this issue by enabling a single PAT
1616
to be shared by many applications, while at the same time limiting access for each application.
1717
Requests are sent to azdo-proxy together with a token, which gives access to a specific repository.
1818
The request is checked and if allowed forwarded to Azure DevOps with the PAT appended to the request.
@@ -57,10 +57,9 @@ There should now be a azdo-proxy Pod and Service in the cluster, ready to proxy
5757

5858
### GIT
5959
Cloning a repository through the proxy is not too different from doing so directly from Azure DevOps.
60-
The only limitation is that it is not possible to clone through ssh, as azdo-proxy only proxies http traffic.
61-
To clone the repository `repo-1` [get the clone url from the respository page](https://docs.microsoft.com/en-us/azure/devops/repos/git/clone?view=azure-devops&tabs=visual-studio#get-the-clone-url-to-your-repo).
62-
Then replace the host part of the url with `azdo-proxy` and att the token as a basci auth parameter.
63-
The result should be similar to below.
60+
The only limitation is that it is not possible to clone through ssh, as azdo-proxy only proxies HTTP traffic.
61+
To clone the repository `repo-1` [get the clone URL from the repository page](https://docs.microsoft.com/en-us/azure/devops/repos/git/clone?view=azure-devops&tabs=visual-studio#get-the-clone-url-to-your-repo).
62+
Then replace the host part of the URL with `azdo-proxy` and add the token as a basic auth parameter. The result should be similar to below.
6463
```shell
6564
git clone http://<token-1>@azdo-proxy/org/proj/_git/repo-1
6665
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/go-logr/logr v0.2.0
77
github.com/go-logr/zapr v0.2.0
88
github.com/go-playground/validator/v10 v10.3.0
9-
github.com/gorilla/mux v1.7.4
9+
github.com/gorilla/mux v1.8.0
1010
github.com/spf13/pflag v1.0.5
1111
go.uber.org/zap v1.15.0
1212
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ github.com/go-playground/validator/v10 v10.3.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GO
1919
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
2020
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
2121
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
22+
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
23+
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
2224
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
2325
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
2426
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

main.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ func main() {
6262
// Configure revers proxy and http server
6363
proxy := httputil.NewSingleHostReverseProxy(remote)
6464
router := mux.NewRouter()
65-
router.HandleFunc("/readyz", readinessHandler).Methods("GET")
66-
router.HandleFunc("/healthz", livenessHandler).Methods("GET")
65+
router.HandleFunc("/readyz", readinessHandler(log.WithName("readiness"))).Methods("GET")
66+
router.HandleFunc("/healthz", livenessHandler(log.WithName("liveness"))).Methods("GET")
6767
router.PathPrefix("/").HandlerFunc(proxyHandler(proxy, log.WithName("reverse-proxy"), auth, config.Domain, config.Pat))
6868

6969
srv := &http.Server{
@@ -100,16 +100,24 @@ func main() {
100100
setupLog.Info("Server exited properly")
101101
}
102102

103-
func readinessHandler(w http.ResponseWriter, r *http.Request) {
104-
w.WriteHeader(http.StatusOK)
105-
w.Header().Set("Content-Type", "application/json")
106-
w.Write([]byte("{\"status\": \"ok\"}"))
103+
func readinessHandler(log logr.Logger) func(http.ResponseWriter, *http.Request) {
104+
return func(w http.ResponseWriter, r *http.Request) {
105+
w.WriteHeader(http.StatusOK)
106+
w.Header().Set("Content-Type", "application/json")
107+
if _, err := w.Write([]byte("{\"status\": \"ok\"}")); err != nil {
108+
log.Error(err, "Could not write response data")
109+
}
110+
}
107111
}
108112

109-
func livenessHandler(w http.ResponseWriter, r *http.Request) {
110-
w.WriteHeader(http.StatusOK)
111-
w.Header().Set("Content-Type", "application/json")
112-
w.Write([]byte("{\"status\": \"ok\"}"))
113+
func livenessHandler(log logr.Logger) func(http.ResponseWriter, *http.Request) {
114+
return func(w http.ResponseWriter, r *http.Request) {
115+
w.WriteHeader(http.StatusOK)
116+
w.Header().Set("Content-Type", "application/json")
117+
if _, err := w.Write([]byte("{\"status\": \"ok\"}")); err != nil {
118+
log.Error(err, "Could not write response data")
119+
}
120+
}
113121
}
114122

115123
func proxyHandler(p *httputil.ReverseProxy, log logr.Logger, a *auth.Authorization, domain string, pat string) func(http.ResponseWriter, *http.Request) {

0 commit comments

Comments
 (0)