Skip to content

Commit 108b902

Browse files
authored
Add support for GitHub (#38)
* Upgrade dependencies * Add support for GitHub using Applications
1 parent d003466 commit 108b902

20 files changed

+814
-384
lines changed

Dockerfile

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

go.mod

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module github.com/xenitab/azdo-proxy
22

3-
go 1.16
3+
go 1.17
44

55
require (
6+
github.com/bradleyfalzon/ghinstallation/v2 v2.0.3
7+
github.com/cristalhq/aconfig v0.16.6
68
github.com/go-logr/logr v0.4.0
79
github.com/go-logr/zapr v0.4.0
810
github.com/go-playground/validator/v10 v10.9.0
@@ -14,13 +16,57 @@ require (
1416
github.com/prometheus/client_golang v1.11.0
1517
github.com/slok/go-http-metrics v0.9.0
1618
github.com/spf13/afero v1.6.0
17-
github.com/spf13/pflag v1.0.5
1819
github.com/stretchr/objx v0.2.0 // indirect
1920
github.com/stretchr/testify v1.7.0
2021
go.uber.org/zap v1.18.1
2122
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
22-
google.golang.org/appengine v1.6.6 // indirect
23-
k8s.io/api v0.22.1
24-
k8s.io/apimachinery v0.22.1
25-
k8s.io/client-go v0.22.1
23+
k8s.io/api v0.22.2
24+
k8s.io/apimachinery v0.22.2
25+
k8s.io/client-go v0.22.2
26+
)
27+
28+
require (
29+
github.com/beorn7/perks v1.0.1 // indirect
30+
github.com/cespare/xxhash/v2 v2.1.1 // indirect
31+
github.com/davecgh/go-spew v1.1.1 // indirect
32+
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
33+
github.com/go-playground/locales v0.14.0 // indirect
34+
github.com/go-playground/universal-translator v0.18.0 // indirect
35+
github.com/gogo/protobuf v1.3.2 // indirect
36+
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
37+
github.com/golang/protobuf v1.5.2 // indirect
38+
github.com/google/go-cmp v0.5.6 // indirect
39+
github.com/google/go-github/v39 v39.0.0 // indirect
40+
github.com/google/go-querystring v1.1.0 // indirect
41+
github.com/google/gofuzz v1.1.0 // indirect
42+
github.com/googleapis/gnostic v0.5.5 // indirect
43+
github.com/json-iterator/go v1.1.11 // indirect
44+
github.com/leodido/go-urn v1.2.1 // indirect
45+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
46+
github.com/modern-go/reflect2 v1.0.1 // indirect
47+
github.com/pkg/errors v0.9.1 // indirect
48+
github.com/pmezard/go-difflib v1.0.0 // indirect
49+
github.com/prometheus/client_model v0.2.0 // indirect
50+
github.com/prometheus/common v0.26.0 // indirect
51+
github.com/prometheus/procfs v0.6.0 // indirect
52+
github.com/spf13/pflag v1.0.5 // indirect
53+
go.uber.org/atomic v1.7.0 // indirect
54+
go.uber.org/multierr v1.6.0 // indirect
55+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
56+
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
57+
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
58+
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 // indirect
59+
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
60+
golang.org/x/text v0.3.6 // indirect
61+
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
62+
google.golang.org/appengine v1.6.7 // indirect
63+
google.golang.org/protobuf v1.26.0 // indirect
64+
gopkg.in/inf.v0 v0.9.1 // indirect
65+
gopkg.in/yaml.v2 v2.4.0 // indirect
66+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
67+
k8s.io/klog/v2 v2.9.0 // indirect
68+
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect
69+
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a // indirect
70+
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
71+
sigs.k8s.io/yaml v1.2.0 // indirect
2672
)

go.sum

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
4646
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
4747
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
4848
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
49+
github.com/bradleyfalzon/ghinstallation/v2 v2.0.3 h1:ywF/8q+GVpvlsEuvRb1SGSDQDUxntW1d4kFu/9q/YAE=
50+
github.com/bradleyfalzon/ghinstallation/v2 v2.0.3/go.mod h1:tlgi+JWCXnKFx/Y4WtnDbZEINo31N5bcvnCoqieefmk=
4951
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
5052
github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM=
5153
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
@@ -55,6 +57,8 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
5557
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
5658
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5759
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
60+
github.com/cristalhq/aconfig v0.16.6 h1:SnwVPXhJldbu8bFos1ru29Xmxi3yZRXkSL6SiHJmGFQ=
61+
github.com/cristalhq/aconfig v0.16.6/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
5862
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5963
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
6064
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -107,6 +111,8 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
107111
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
108112
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
109113
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
114+
github.com/golang-jwt/jwt/v4 v4.0.0 h1:RAqyYixv1p7uEnocuy8P1nru5wprCh/MH2BIlW5z5/o=
115+
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
110116
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
111117
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
112118
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -141,9 +147,15 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
141147
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
142148
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
143149
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
150+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
144151
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
145-
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
146152
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
153+
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
154+
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
155+
github.com/google/go-github/v39 v39.0.0 h1:pygGA5ySwxEez1N39GnDauD0PaWWuGgayudyZAc941s=
156+
github.com/google/go-github/v39 v39.0.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE=
157+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
158+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
147159
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
148160
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
149161
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -333,8 +345,9 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
333345
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
334346
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
335347
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
336-
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
337348
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
349+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
350+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
338351
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
339352
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
340353
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -527,8 +540,8 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
527540
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
528541
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
529542
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
530-
google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc=
531-
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
543+
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
544+
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
532545
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
533546
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
534547
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
@@ -599,20 +612,20 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
599612
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
600613
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
601614
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
602-
k8s.io/api v0.22.1 h1:ISu3tD/jRhYfSW8jI/Q1e+lRxkR7w9UwQEZ7FgslrwY=
603-
k8s.io/api v0.22.1/go.mod h1:bh13rkTp3F1XEaLGykbyRD2QaTTzPm0e/BMd8ptFONY=
604-
k8s.io/apimachinery v0.22.1 h1:DTARnyzmdHMz7bFWFDDm22AM4pLWTQECMpRTFu2d2OM=
605-
k8s.io/apimachinery v0.22.1/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0=
606-
k8s.io/client-go v0.22.1 h1:jW0ZSHi8wW260FvcXHkIa0NLxFBQszTlhiAVsU5mopw=
607-
k8s.io/client-go v0.22.1/go.mod h1:BquC5A4UOo4qVDUtoc04/+Nxp1MeHcVc1HJm1KmG8kk=
615+
k8s.io/api v0.22.2 h1:M8ZzAD0V6725Fjg53fKeTJxGsJvRbk4TEm/fexHMtfw=
616+
k8s.io/api v0.22.2/go.mod h1:y3ydYpLJAaDI+BbSe2xmGcqxiWHmWjkEeIbiwHvnPR8=
617+
k8s.io/apimachinery v0.22.2 h1:ejz6y/zNma8clPVfNDLnPbleBo6MpoFy/HBiBqCouVk=
618+
k8s.io/apimachinery v0.22.2/go.mod h1:O3oNtNadZdeOMxHFVxOreoznohCpy0z6mocxbZr7oJ0=
619+
k8s.io/client-go v0.22.2 h1:DaSQgs02aCC1QcwUdkKZWOeaVsQjYvWv8ZazcZ6JcHc=
620+
k8s.io/client-go v0.22.2/go.mod h1:sAlhrkVDf50ZHx6z4K0S40wISNTarf1r800F+RlCF6U=
608621
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
609622
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
610623
k8s.io/klog/v2 v2.9.0 h1:D7HV+n1V57XeZ0m6tdRkfknthUaM06VFbWldOFh8kzM=
611624
k8s.io/klog/v2 v2.9.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
612625
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e h1:KLHHjkdQFomZy8+06csTWZ0m1343QqxZhR2LJ1OxCYM=
613626
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw=
614-
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9 h1:imL9YgXQ9p7xmPzHFm/vVd/cF78jad+n4wK1ABwYtMM=
615-
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
627+
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a h1:8dYfu/Fc9Gz2rNJKB9IQRGgQOh2clmRzNIPPY1xLY5g=
628+
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
616629
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
617630
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
618631
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

main.go

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import (
77
"net/http"
88
"os"
99
"os/signal"
10-
"path/filepath"
1110
"syscall"
1211
"time"
1312

1413
"golang.org/x/sync/errgroup"
1514

15+
"github.com/cristalhq/aconfig"
1616
"github.com/go-logr/logr"
1717
"github.com/go-logr/zapr"
1818
"github.com/prometheus/client_golang/prometheus/promhttp"
19-
flag "github.com/spf13/pflag"
19+
"github.com/spf13/afero"
2020
"go.uber.org/zap"
2121
"k8s.io/client-go/kubernetes"
2222
"k8s.io/client-go/rest"
@@ -28,19 +28,11 @@ import (
2828
"github.com/xenitab/azdo-proxy/pkg/token"
2929
)
3030

31-
var (
32-
port string
33-
metricsPort string
34-
kubeconfigPath string
35-
configPath string
36-
)
37-
38-
func init() {
39-
flag.StringVar(&port, "port", ":8080", "port to bind proxy server to.")
40-
flag.StringVar(&metricsPort, "metrics-port", ":9090", "port to bind metrics endpoint to.")
41-
flag.StringVar(&kubeconfigPath, "kubeconfig", "", "absolute path to the kubeconfig file.")
42-
flag.StringVar(&configPath, "config", "/var/config.json", "path to configuration file.")
43-
flag.Parse()
31+
type cfg struct {
32+
Addr string `flag:"addr" default:":8080"`
33+
MetricsAddr string `flag:"metrics-addr" default:":9090"`
34+
KubeconfigPath string `flag:"kubeconfig"`
35+
ConfigPath string `flag:"config"`
4436
}
4537

4638
func main() {
@@ -49,22 +41,33 @@ func main() {
4941
panic(fmt.Sprintf("who watches the watchmen (%v)?", err))
5042
}
5143
logger := zapr.NewLogger(zapLog)
52-
if err := run(logger, configPath, metricsPort); err != nil {
44+
if err := run(logger); err != nil {
5345
logger.WithName("main").Error(err, "run error")
5446
os.Exit(1)
5547
}
5648
}
5749

58-
func run(logger logr.Logger, configPath string, metricsPort string) error {
50+
// nolint:funlen // cant make this shorter
51+
func run(logger logr.Logger) error {
5952
mainLogger := logger.WithName("main")
60-
mainLogger.Info("read configuration from", "path", configPath)
61-
mainLogger.Info("serve metrics", "port", metricsPort, "endpoint", "/metrics")
6253

63-
authz, err := getAutorization(configPath)
54+
cfg := &cfg{}
55+
loader := aconfig.LoaderFor(cfg, aconfig.Config{
56+
FlagDelimiter: "-",
57+
AllFieldRequired: false,
58+
})
59+
if err := loader.Load(); err != nil {
60+
return err
61+
}
62+
63+
mainLogger.Info("read configuration from", "path", cfg.ConfigPath)
64+
mainLogger.Info("serve metrics", "port", cfg.MetricsAddr, "endpoint", "/metrics")
65+
66+
authz, err := getAutorization(cfg.ConfigPath)
6467
if err != nil {
6568
return err
6669
}
67-
client, err := getKubernetesClient(kubeconfigPath)
70+
client, err := getKubernetesClient(cfg.KubeconfigPath)
6871
if err != nil {
6972
return fmt.Errorf("invalid kubernetes client: %w", err)
7073
}
@@ -79,7 +82,7 @@ func run(logger logr.Logger, configPath string, metricsPort string) error {
7982
signal.Notify(stopCh, syscall.SIGTERM, syscall.SIGINT)
8083
defer signal.Stop(stopCh)
8184

82-
metricsSrv := &http.Server{Addr: metricsPort, Handler: promhttp.Handler()}
85+
metricsSrv := &http.Server{Addr: cfg.MetricsAddr, Handler: promhttp.Handler()}
8386
g.Go(func() error {
8487
if err := metricsSrv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
8588
return err
@@ -93,12 +96,9 @@ func run(logger logr.Logger, configPath string, metricsPort string) error {
9396
}
9497
return nil
9598
})
96-
azdoSrv, err := server.NewAzdoServer(logger, port, authz)
97-
if err != nil {
98-
return fmt.Errorf("could not create azdo proxy server: %w", err)
99-
}
99+
srv := server.NewServer(logger, cfg.Addr, authz)
100100
g.Go(func() error {
101-
if err := azdoSrv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
101+
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
102102
return err
103103
}
104104
return nil
@@ -125,7 +125,7 @@ func run(logger logr.Logger, configPath string, metricsPort string) error {
125125
return nil
126126
})
127127
g.Go(func() error {
128-
if err := azdoSrv.Shutdown(timeoutCtx); err != nil {
128+
if err := srv.Shutdown(timeoutCtx); err != nil {
129129
return err
130130
}
131131
return nil
@@ -138,18 +138,14 @@ func run(logger logr.Logger, configPath string, metricsPort string) error {
138138
return nil
139139
}
140140

141-
func getAutorization(path string) (auth.Authorization, error) {
142-
path, err := filepath.Rel("/", path)
143-
if err != nil {
144-
return auth.Authorization{}, fmt.Errorf("could not get relative path: %w", err)
145-
}
146-
cfg, err := config.LoadConfiguration(os.DirFS("/"), path)
141+
func getAutorization(path string) (*auth.Authorizer, error) {
142+
cfg, err := config.LoadConfiguration(afero.NewOsFs(), path)
147143
if err != nil {
148-
return auth.Authorization{}, fmt.Errorf("could not load configuration: %w", err)
144+
return nil, fmt.Errorf("could not load configuration: %w", err)
149145
}
150-
authz, err := auth.NewAuthorization(cfg)
146+
authz, err := auth.NewAuthorizer(cfg)
151147
if err != nil {
152-
return auth.Authorization{}, fmt.Errorf("could not generate authorization: %w", err)
148+
return nil, fmt.Errorf("could not generate authorization: %w", err)
153149
}
154150
return authz, nil
155151
}

0 commit comments

Comments
 (0)