Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from fluxcd/gcr-specific
Browse files Browse the repository at this point in the history
Rename GCR-specific field to `GCR`
  • Loading branch information
squaremo authored May 12, 2020
2 parents 5a6d833 + 902e6eb commit 13a8781
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ exposing to the internet, because
- `GoogleContainerRegistry` image push events via pubsub
- `Nexus` image push events

Some of these have specific configuration options; see
[Source-specific configuration](#source-specific-configuration) below.

## How to use it

In short:
Expand Down Expand Up @@ -143,7 +146,7 @@ though you may want to supply the argument `--listen=localhost:3030`
to limit API access to localhost, if you don't already.

> If you do restrict API access to localhost, make sure you also
>
>
> - supply `--listen-metrics=:3031`
> - annotate the pod with `prometheus.io/port: "3031"`, so
> Prometheus knows which port to scrape).
Expand Down Expand Up @@ -306,3 +309,22 @@ trigger to refresh state, rather than as authoritative themselves. For
example, when informed of an image push, fluxd does not add the image
mentioned to its database -- it polls the image registry in question
to determine whether there is a new image.
### Source-specific configuration
#### Google Container Registry
The Google Container Registry endpoint expects a [push
subscription](https://cloud.google.com/pubsub/docs/push) to be set
up. If you include a `gcr` field in the endpoint configuration, it
will authenticate and verify the audience for incoming webhook
payloads:
```
fluxRecvVersion: 1
endpoints:
- source: GoogleContainerRegistry
keyPath: gcr.key
gcr:
audience: flux-push-notification
```
10 changes: 5 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/ghodss/yaml"
)

type Auth struct {
type GCRAuth struct {
Audience string `json:"audience"`
}

type Endpoint struct {
Source string `json:"source"`
RegistryHost string `json:"registryHost,omitempty"`
KeyPath string `json:"keyPath"`
Authentication *Auth `json:"authentication,omitempty"`
Source string `json:"source"`
RegistryHost string `json:"registryHost,omitempty"`
KeyPath string `json:"keyPath"`
GCR *GCRAuth `json:"gcr,omitempty"`
}

type Config struct {
Expand Down
4 changes: 2 additions & 2 deletions gcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func init() {

func handleGoogleContainerRegistry(s fluxapi.Server, _ []byte, w http.ResponseWriter, r *http.Request, config Endpoint) {
// authenticate based on config
if config.Authentication != nil {
if err := authenticateRequest(&http.Client{}, r.Header.Get("Authorization"), config.Authentication.Audience); err != nil {
if config.GCR != nil {
if err := authenticateRequest(&http.Client{}, r.Header.Get("Authorization"), config.GCR.Audience); err != nil {
http.Error(w, "Cannot authorize request", http.StatusOK)
log(GoogleContainerRegistry, err.Error())
return
Expand Down
2 changes: 1 addition & 1 deletion sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func Test_GoogleContainerRegistry_WhenNoAuth(t *testing.T) {
downstream := newDownstream(t, expectedGoogleContainerRegistry, &called)
defer downstream.Close()

endpoint := Endpoint{Source: GoogleContainerRegistry, KeyPath: "gcr_key", Authentication: nil}
endpoint := Endpoint{Source: GoogleContainerRegistry, KeyPath: "gcr_key", GCR: nil}
fp, handler, err := HandlerFromEndpoint("test/fixtures", downstream.URL, endpoint)
assert.NoError(t, err)

Expand Down

0 comments on commit 13a8781

Please sign in to comment.