Skip to content

Commit d62be26

Browse files
authored
Merge pull request #1058 from dipti-pai/github-app-auth
[RFC-007] GitHub App authentication support for github and github-dispatch providers
2 parents c476965 + bc7166d commit d62be26

16 files changed

+494
-159
lines changed

docs/spec/v1beta3/providers.md

+33-7
Original file line numberDiff line numberDiff line change
@@ -1300,14 +1300,18 @@ spec:
13001300
type: githubdispatch
13011301
address: https://github.com/stefanprodan/podinfo
13021302
secretRef:
1303-
name: api-token
1303+
name: auth-secret
13041304
```
13051305

13061306
The `address` is the address of your repository where you want to send webhooks to trigger GitHub workflows.
13071307

1308-
GitHub uses personal access tokens for authentication with its API:
1308+
GitHub uses [personal access
1309+
tokens]((https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token))
1310+
or [GitHub
1311+
app]((https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation))
1312+
for authentication with its API:
13091313

1310-
* [GitHub personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token)
1314+
#### GitHub personal access token
13111315

13121316
The provider requires a secret in the same format, with the personal access token as the value for the token key:
13131317

@@ -1316,12 +1320,19 @@ The provider requires a secret in the same format, with the personal access toke
13161320
apiVersion: v1
13171321
kind: Secret
13181322
metadata:
1319-
name: api-token
1323+
name: auth-secret
13201324
namespace: default
13211325
stringData:
13221326
token: <personal-access-tokens>
13231327
```
13241328

1329+
#### GitHub App
1330+
1331+
To use Github App authentication, make sure the GitHub App is registered and
1332+
installed with the necessary permissions and the github app secret is created as
1333+
described
1334+
[here](https://fluxcd.io/flux/components/source/gitrepositories/#github).
1335+
13251336
#### Setting up a GitHub workflow
13261337

13271338
To trigger a GitHub Actions workflow when a Flux Kustomization finishes reconciling,
@@ -1539,17 +1550,32 @@ spec:
15391550

15401551
#### GitHub
15411552

1542-
When `.spec.type` is set to `github`, the referenced secret must contain a key called `token` with the value set to a
1543-
[GitHub personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
1553+
When `.spec.type` is set to `github`, the referenced secret can contain a
1554+
personal access token OR github app details.
1555+
1556+
##### Personal Access Token
15441557

1545-
The token must have permissions to update the commit status for the GitHub repository specified in `.spec.address`.
1558+
To use personal access tokens, the secret must contain a key called `token` with
1559+
the value set to a [GitHub personal access
1560+
token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
1561+
The token must have permissions to update the commit status for the GitHub
1562+
repository specified in `.spec.address`.
15461563

15471564
You can create the secret with `kubectl` like this:
15481565

15491566
```shell
15501567
kubectl create secret generic github-token --from-literal=token=<GITHUB-TOKEN>
15511568
```
15521569

1570+
##### GitHub App
1571+
1572+
To use [Github App
1573+
authentication](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation),
1574+
make sure the GitHub App is registered and installed with the necessary
1575+
permissions to update the commit status and the github app secret is created as
1576+
described
1577+
[here](https://fluxcd.io/flux/components/source/gitrepositories/#github).
1578+
15531579
#### GitLab
15541580

15551581
When `.spec.type` is set to `gitlab`, the referenced secret must contain a key called `token` with the value set to a

go.mod

+9-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ require (
1919
github.com/fluxcd/notification-controller/api v1.5.0
2020
github.com/fluxcd/pkg/apis/event v0.16.0
2121
github.com/fluxcd/pkg/apis/meta v1.10.0
22-
github.com/fluxcd/pkg/git v0.24.0
22+
github.com/fluxcd/pkg/cache v0.7.0
23+
github.com/fluxcd/pkg/git v0.25.0
2324
github.com/fluxcd/pkg/masktoken v0.6.0
2425
github.com/fluxcd/pkg/runtime v0.55.0
2526
github.com/fluxcd/pkg/ssa v0.45.1
27+
github.com/fluxcd/pkg/ssh v0.17.0
2628
github.com/getsentry/sentry-go v0.31.1
2729
github.com/go-logr/logr v1.4.2
2830
github.com/google/cel-go v0.23.2
@@ -62,7 +64,7 @@ require (
6264
github.com/42wim/httpsig v1.2.1 // indirect
6365
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
6466
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 // indirect
65-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.1 // indirect
67+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2 // indirect
6668
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
6769
github.com/Azure/go-amqp v1.0.0 // indirect
6870
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
@@ -74,14 +76,14 @@ require (
7476
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
7577
github.com/Azure/go-autorest/logger v0.2.1 // indirect
7678
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
77-
github.com/AzureAD/microsoft-authentication-library-for-go v1.3.2 // indirect
79+
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.0 // indirect
7880
github.com/DataDog/zstd v1.5.2 // indirect
7981
github.com/MakeNowJust/heredoc v1.0.0 // indirect
8082
github.com/ProtonMail/go-crypto v1.1.5 // indirect
8183
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
8284
github.com/beorn7/perks v1.0.1 // indirect
8385
github.com/blang/semver/v4 v4.0.0 // indirect
84-
github.com/bradleyfalzon/ghinstallation/v2 v2.13.0 // indirect
86+
github.com/bradleyfalzon/ghinstallation/v2 v2.14.0 // indirect
8587
github.com/cespare/xxhash/v2 v2.3.0 // indirect
8688
github.com/chai2010/gettext-go v1.0.2 // indirect
8789
github.com/cloudevents/sdk-go/v2 v2.15.2 // indirect
@@ -97,7 +99,7 @@ require (
9799
github.com/felixge/httpsnoop v1.0.4 // indirect
98100
github.com/fluxcd/pkg/apis/acl v0.6.0 // indirect
99101
github.com/fluxcd/pkg/apis/kustomize v1.9.0 // indirect
100-
github.com/fluxcd/pkg/auth v0.3.0 // indirect
102+
github.com/fluxcd/pkg/auth v0.4.0 // indirect
101103
github.com/fsnotify/fsnotify v1.8.0 // indirect
102104
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
103105
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
@@ -119,7 +121,7 @@ require (
119121
github.com/google/btree v1.1.3 // indirect
120122
github.com/google/gnostic-models v0.6.9 // indirect
121123
github.com/google/go-cmp v0.7.0 // indirect
122-
github.com/google/go-github/v68 v68.0.0 // indirect
124+
github.com/google/go-github/v69 v69.2.0 // indirect
123125
github.com/google/go-querystring v1.1.0 // indirect
124126
github.com/google/gofuzz v1.2.0 // indirect
125127
github.com/google/s2a-go v0.1.9 // indirect
@@ -176,7 +178,7 @@ require (
176178
go.opentelemetry.io/otel/trace v1.34.0 // indirect
177179
go.uber.org/multierr v1.11.0 // indirect
178180
go.uber.org/zap v1.27.0 // indirect
179-
golang.org/x/crypto v0.33.0 // indirect
181+
golang.org/x/crypto v0.34.0 // indirect
180182
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
181183
golang.org/x/mod v0.22.0 // indirect
182184
golang.org/x/net v0.35.0 // indirect

go.sum

+20-18
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0
3232
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
3333
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 h1:g0EZJwz7xkXQiZAI5xi9f3WWFYBlX1CPTrR+NDToRkQ=
3434
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0/go.mod h1:XCW7KnZet0Opnr7HccfUw1PLc4CjHqpcaxW8DHklNkQ=
35-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.1 h1:1mvYtZfWQAnwNah/C+Z+Jb9rQH95LPE2vlmMuWAHJk8=
36-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.1/go.mod h1:75I/mXtme1JyWFtz8GocPHVFyH421IBoZErnO16dd0k=
37-
github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.1 h1:Bk5uOhSAenHyR5P61D/NzeQCv+4fEVV8mOkJ82NqpWw=
38-
github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.1/go.mod h1:QZ4pw3or1WPmRBxf0cHd1tknzrT54WPBOQoGutCPvSU=
35+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2 h1:F0gBpfdPLGsw+nsgk6aqqkZS1jiixa5WwFe3fk/T3Ys=
36+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2/go.mod h1:SqINnQ9lVVdRlyC8cd1lCI0SdX4n2paeABd2K8ggfnE=
37+
github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2 h1:yz1bePFlP5Vws5+8ez6T3HWXPmwOK7Yvq8QxDBD3SKY=
38+
github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2/go.mod h1:Pa9ZNPuoNu/GztvBSKk9J1cDJW6vk/n0zLtV4mgd8N8=
3939
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY=
4040
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY=
4141
github.com/Azure/go-amqp v1.0.0 h1:QfCugi1M+4F2JDTRgVnRw7PYXLXZ9hmqk3+9+oJh3OA=
@@ -68,8 +68,8 @@ github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUM
6868
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
6969
github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1 h1:WJTmL004Abzc5wDB5VtZG2PJk5ndYDgVacGqfirKxjM=
7070
github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1/go.mod h1:tCcJZ0uHAmvjsVYzEFivsRTN00oz5BEsRgQHu5JZ9WE=
71-
github.com/AzureAD/microsoft-authentication-library-for-go v1.3.2 h1:kYRSnvJju5gYVyhkij+RTJ/VR6QIUaCfWeaFm2ycsjQ=
72-
github.com/AzureAD/microsoft-authentication-library-for-go v1.3.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
71+
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.0 h1:MUkXAnvvDHgvPItl0nBj0hgk0f7hnnQbGm0h0+YxbN4=
72+
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
7373
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
7474
github.com/DataDog/datadog-api-client-go/v2 v2.35.0 h1:Fj0C0HH5nAolFVdagLOBYMqaYPQ7iy7hLEmS/6gJ9QE=
7575
github.com/DataDog/datadog-api-client-go/v2 v2.35.0/go.mod h1:d3tOEgUd2kfsr9uuHQdY+nXrWp4uikgTgVCPdKNK30U=
@@ -89,8 +89,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
8989
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
9090
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
9191
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
92-
github.com/bradleyfalzon/ghinstallation/v2 v2.13.0 h1:5FhjW93/YLQJDmPdeyMPw7IjAPzqsr+0jHPfrPz0sZI=
93-
github.com/bradleyfalzon/ghinstallation/v2 v2.13.0/go.mod h1:EJ6fgedVEHa2kUyBTTvslJCXJafS/mhJNNKEOCspZXQ=
92+
github.com/bradleyfalzon/ghinstallation/v2 v2.14.0 h1:0D4vKCHOvYrDU8u61TnE2JfNT4VRrBLphmxtqazTO+M=
93+
github.com/bradleyfalzon/ghinstallation/v2 v2.14.0/go.mod h1:LOVmdZYVZ8jqdr4n9wWm1ocDiMz9IfMGfRkaYC1a52A=
9494
github.com/cdevents/sdk-go v0.4.1 h1:Cr/iH/I51Z+slxKRx9AV7stn6hr2pjRHQ5wpPJhRLTU=
9595
github.com/cdevents/sdk-go v0.4.1/go.mod h1:3IhWLoY4vsyUEzv7XJbyr0BRQ0KPgvNx+wiD2hQGFNU=
9696
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -154,18 +154,20 @@ github.com/fluxcd/pkg/apis/kustomize v1.9.0 h1:SJpT1CK58AnTvCpDKeGfMNA0Xud/4VReZ
154154
github.com/fluxcd/pkg/apis/kustomize v1.9.0/go.mod h1:AZl2GU03oPVue6SUivdiIYd/3mvF94j7t1G2JO26d4s=
155155
github.com/fluxcd/pkg/apis/meta v1.10.0 h1:rqbAuyl5ug7A5jjRf/rNwBXmNl6tJ9wG2iIsriwnQUk=
156156
github.com/fluxcd/pkg/apis/meta v1.10.0/go.mod h1:n7NstXHDaleAUMajcXTVkhz0MYkvEXy1C/eLI/t1xoI=
157-
github.com/fluxcd/pkg/auth v0.3.0 h1:I1A3e81O+bpAgEcJ3e+rXqObKPjzBu6FLYXQTSxXLOs=
158-
github.com/fluxcd/pkg/auth v0.3.0/go.mod h1:g9KJ4iNcCd6Sb7al4yN1+olgOfgwmU4lgCWbwvMsFRE=
159-
github.com/fluxcd/pkg/git v0.24.0 h1:aMAL8MUNPZXyRia+LVVudTpmLHIpzmz9F5tedvhhLzs=
160-
github.com/fluxcd/pkg/git v0.24.0/go.mod h1:vxUhjBwnkvbAByN7UC5Go33/mgrLSIIg1rH+dyOZVRo=
157+
github.com/fluxcd/pkg/auth v0.4.0 h1:vk++cJmk28kyFRmG4CDFC6tKfTIq10tpewaobGp8ii4=
158+
github.com/fluxcd/pkg/auth v0.4.0/go.mod h1:2HGTvR/is/TEO6+W09IFGpca45wmoQBhJry7jrDDeKE=
159+
github.com/fluxcd/pkg/cache v0.7.0 h1:6TTWbxCyAxErIAT338KrLTy96ds+vSDw4sEyypSISfs=
160+
github.com/fluxcd/pkg/cache v0.7.0/go.mod h1:EHpyMSXf/ECKIoKEQmNCOesH2wfAdpmXR/ZXD6VwWRg=
161+
github.com/fluxcd/pkg/git v0.25.0 h1:AZKYKalzbbOXbnLvOZ1FbV3pl9qYCbstGjEXuiQQsKo=
162+
github.com/fluxcd/pkg/git v0.25.0/go.mod h1:xCs0kr/Z0LvZfocU3LxLLLKXsdSMoapFncc43snrc2c=
161163
github.com/fluxcd/pkg/masktoken v0.6.0 h1:ijSqMl2L9jBR3QFcHA0FX7kxV0xgSB4PY5p//8FdVR4=
162164
github.com/fluxcd/pkg/masktoken v0.6.0/go.mod h1:bMj45KySJ2gLeFiFaXD5nQLNFlvDqGbZolsiurZKVUU=
163165
github.com/fluxcd/pkg/runtime v0.55.0 h1:bjXz7t1g9DsXUtIbOWZAqAKOo/qccEPQ5JlHMeSO7bk=
164166
github.com/fluxcd/pkg/runtime v0.55.0/go.mod h1:PC73Yn/AaBQXnd2YYq0cnQqF3RmQKoM265crrjFJnKI=
165167
github.com/fluxcd/pkg/ssa v0.45.1 h1:ISl84TJwRP/GuZXrKiR9Tf8JOnG5XFgtjcYoR4XQYf4=
166168
github.com/fluxcd/pkg/ssa v0.45.1/go.mod h1:8Anf7XVZ0zxOve7HXbDaW1s0gfmP95ksJBlKfDYinhQ=
167-
github.com/fluxcd/pkg/ssh v0.16.0 h1:dhSWNp30p05EJ86bhICezad9pG3fJi4CAVKnZ3EmUV8=
168-
github.com/fluxcd/pkg/ssh v0.16.0/go.mod h1:MyDegNZHnKNDAwM5/A2t/1FjpvpS8BsRZQ4WqEwCHc0=
169+
github.com/fluxcd/pkg/ssh v0.17.0 h1:o+MgdM/OB8R/+KEc3W3ml/inEKZqCwT8V71dkbTAbm4=
170+
github.com/fluxcd/pkg/ssh v0.17.0/go.mod h1:4yU099LjFWOJXZiu73rvqA70mOoSXG2yqxfPBxhnGgQ=
169171
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
170172
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
171173
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
@@ -248,8 +250,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
248250
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
249251
github.com/google/go-github/v64 v64.0.0 h1:4G61sozmY3eiPAjjoOHponXDBONm+utovTKbyUb2Qdg=
250252
github.com/google/go-github/v64 v64.0.0/go.mod h1:xB3vqMQNdHzilXBiO2I+M7iEFtHf+DP/omBOv6tQzVo=
251-
github.com/google/go-github/v68 v68.0.0 h1:ZW57zeNZiXTdQ16qrDiZ0k6XucrxZ2CGmoTvcCyQG6s=
252-
github.com/google/go-github/v68 v68.0.0/go.mod h1:K9HAUBovM2sLwM408A18h+wd9vqdLOEqTUCbnRIcx68=
253+
github.com/google/go-github/v69 v69.2.0 h1:wR+Wi/fN2zdUx9YxSmYE0ktiX9IAR/BeePzeaUUbEHE=
254+
github.com/google/go-github/v69 v69.2.0/go.mod h1:xne4jymxLR6Uj9b7J7PyTpkMYstEMMwGZa0Aehh1azM=
253255
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
254256
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
255257
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -468,8 +470,8 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0
468470
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
469471
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
470472
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
471-
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
472-
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
473+
golang.org/x/crypto v0.34.0 h1:+/C6tk6rf/+t5DhUketUbD1aNGqiSX3j15Z6xuIDlBA=
474+
golang.org/x/crypto v0.34.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
473475
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
474476
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
475477
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=

internal/notifier/factory.go

+45-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"fmt"
2222

2323
apiv1 "github.com/fluxcd/notification-controller/api/v1beta3"
24+
25+
pkgcache "github.com/fluxcd/pkg/cache"
2426
)
2527

2628
var (
@@ -64,15 +66,19 @@ type notifierMap map[string]factoryFunc
6466
type factoryFunc func(opts notifierOptions) (Interface, error)
6567

6668
type notifierOptions struct {
67-
URL string
68-
ProxyURL string
69-
Username string
70-
Channel string
71-
Token string
72-
Headers map[string]string
73-
CertPool *x509.CertPool
74-
Password string
75-
CommitStatus string
69+
URL string
70+
ProxyURL string
71+
Username string
72+
Channel string
73+
Token string
74+
Headers map[string]string
75+
CertPool *x509.CertPool
76+
Password string
77+
CommitStatus string
78+
ProviderName string
79+
ProviderNamespace string
80+
SecretData map[string][]byte
81+
TokenCache *pkgcache.TokenCache
7682
}
7783

7884
type Factory struct {
@@ -138,6 +144,34 @@ func WithCommitStatus(commitStatus string) Option {
138144
}
139145
}
140146

147+
// WithProviderName sets the provider name for the notifier.
148+
func WithProviderName(name string) Option {
149+
return func(o *notifierOptions) {
150+
o.ProviderName = name
151+
}
152+
}
153+
154+
// WithProviderNamespace sets the provider namespace for the notifier.
155+
func WithProviderNamespace(namespace string) Option {
156+
return func(o *notifierOptions) {
157+
o.ProviderNamespace = namespace
158+
}
159+
}
160+
161+
// WithSecretData sets the secret data for the notifier.
162+
func WithSecretData(data map[string][]byte) Option {
163+
return func(o *notifierOptions) {
164+
o.SecretData = data
165+
}
166+
}
167+
168+
// WithTokenCache sets the token cache for the notifier.
169+
func WithTokenCache(cache *pkgcache.TokenCache) Option {
170+
return func(o *notifierOptions) {
171+
o.TokenCache = cache
172+
}
173+
}
174+
141175
// NewFactory creates a new notifier factory with the given URL and optional configurations.
142176
func NewFactory(url string, opts ...Option) *Factory {
143177
options := notifierOptions{
@@ -258,14 +292,14 @@ func gitHubNotifierFunc(opts notifierOptions) (Interface, error) {
258292
if opts.Token == "" && opts.Password != "" {
259293
opts.Token = opts.Password
260294
}
261-
return NewGitHub(opts.CommitStatus, opts.URL, opts.Token, opts.CertPool)
295+
return NewGitHub(opts.CommitStatus, opts.URL, opts.Token, opts.CertPool, opts.ProxyURL, opts.ProviderName, opts.ProviderNamespace, opts.SecretData, opts.TokenCache)
262296
}
263297

264298
func gitHubDispatchNotifierFunc(opts notifierOptions) (Interface, error) {
265299
if opts.Token == "" && opts.Password != "" {
266300
opts.Token = opts.Password
267301
}
268-
return NewGitHubDispatch(opts.URL, opts.Token, opts.CertPool)
302+
return NewGitHubDispatch(opts.URL, opts.Token, opts.CertPool, opts.ProxyURL, opts.ProviderName, opts.ProviderNamespace, opts.SecretData, opts.TokenCache)
269303
}
270304

271305
func gitLabNotifierFunc(opts notifierOptions) (Interface, error) {

0 commit comments

Comments
 (0)