Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support loading GitHub secrets from GCPSecretManager #2

Merged
merged 2 commits into from
Nov 20, 2022
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.16.1' # The Go version to download (if necessary) and use.
go-version: '1.19.2' # The Go version to download (if necessary) and use.
- run: go test ./...
- run: go build ./cmd/...
21 changes: 18 additions & 3 deletions cmd/github/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io/ioutil"
"os"

"github.com/jlewi/hydros/pkg/files"

"github.com/jlewi/hydros/pkg/github"
"github.com/jlewi/hydros/pkg/hydros"
"github.com/jlewi/hydros/pkg/util"
Expand All @@ -28,7 +30,20 @@ func NewAppTokenCmd(w io.Writer, level *string, devLogger *bool) *cobra.Command
Run: func(cmd *cobra.Command, args []string) {
log := util.SetupLogger(*level, *devLogger)
err := func() error {
manager, err := github.NewTransportManager(int64(githubAppID), secret, log)
f := &files.Factory{}
h, err := f.Get(secret)
if err != nil {
return err
}
r, err := h.NewReader(secret)
if err != nil {
return err
}
secretByte, err := io.ReadAll(r)
if err != nil {
return err
}
manager, err := github.NewTransportManager(int64(githubAppID), secretByte, log)
if err != nil {
return errors.Wrapf(err, "TransportManager creation failed")
}
Expand Down Expand Up @@ -58,12 +73,12 @@ func NewAppTokenCmd(w io.Writer, level *string, devLogger *bool) *cobra.Command
return nil
}()
if err != nil {
fmt.Fprintf(w, "Failed to get resource; error:\n%v", err)
fmt.Fprintf(w, "Failed to get resource; error:\n%+v", err)
}
},
}

cmd.Flags().StringVarP(&secret, "private-key", "", "", "Path to the file containing the secret for the GitHub App to Authenticate as.")
cmd.Flags().StringVarP(&secret, "private-key", "", "", "The uri containing the secret for the GitHub App to Authenticate as. Supported schema file, gcpSecretManager")
cmd.Flags().IntVarP(&githubAppID, "appId", "", hydros.HydrosGitHubAppID, "GitHubAppId.")
cmd.Flags().StringVarP(&org, "org", "o", "PrimerAI", "The GitHub org to obtain the token for")
cmd.Flags().StringVarP(&repo, "repo", "r", "", "The repo obtain the token for")
Expand Down
22 changes: 21 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"strings"
"time"

"github.com/jlewi/hydros/pkg/files"
"github.com/pkg/errors"

githubCmds "github.com/jlewi/hydros/cmd/github"
"github.com/jlewi/hydros/pkg/github"
"github.com/jlewi/hydros/pkg/hydros"
Expand Down Expand Up @@ -203,6 +206,19 @@ func newVersionCmd(w io.Writer) *cobra.Command {
return cmd
}

func readSecret(secret string) ([]byte, error) {
f := &files.Factory{}
h, err := f.Get(secret)
if err != nil {
return nil, err
}
r, err := h.NewReader(secret)
if err != nil {
return nil, err
}
return io.ReadAll(r)
}

func apply(a applyOptions, path string, syncNames map[string]string) error {
log.Info("Reading file", "path", path)
rNodes, err := util.ReadYaml(path)
Expand Down Expand Up @@ -238,7 +254,11 @@ func apply(a applyOptions, path string, syncNames map[string]string) error {
}
syncNames[name] = path

manager, err := github.NewTransportManager(int64(aOptions.githubAppID), aOptions.secret, log)
secret, err := readSecret(aOptions.secret)
if err != nil {
return errors.Wrapf(err, "Could not read file: %v", aOptions.secret)
}
manager, err := github.NewTransportManager(int64(aOptions.githubAppID), secret, log)
if err != nil {
log.Error(err, "TransportManager creation failed")
return err
Expand Down
78 changes: 28 additions & 50 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/jlewi/hydros

go 1.17
go 1.19

replace (
github.com/go-logr/logr => github.com/go-logr/logr v1.2.2
Expand All @@ -15,22 +15,19 @@ require (
github.com/bradleyfalzon/ghinstallation/v2 v2.0.4
github.com/cli/cli v0.10.1
github.com/ghodss/yaml v1.0.0
github.com/go-git/go-git/v5 v5.4.2
github.com/go-logr/logr v1.2.2
github.com/go-logr/zapr v1.2.3
github.com/google/go-cmp v0.5.7
github.com/google/go-cmp v0.5.9
github.com/google/go-containerregistry v0.8.1-0.20220216220642-00c59d91847c
github.com/google/uuid v1.3.0
github.com/kubeflow/testing/go v0.0.0-20210126230232-bd372c4d8694
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2
github.com/otiai10/copy v1.6.0
github.com/owenrumney/go-sarif v1.1.1
github.com/philhofer/fwd v1.1.1 // indirect
github.com/pkg/errors v0.9.1
github.com/shurcooL/githubv4 v0.0.0-20200414012201-bbc966b061dd
github.com/spf13/cobra v1.3.0
github.com/stretchr/testify v1.7.0
github.com/tektoncd/pipeline v0.33.2
go.uber.org/zap v1.19.1
gopkg.in/DataDog/dd-trace-go.v1 v1.33.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
Expand All @@ -44,58 +41,47 @@ require (
github.com/charmbracelet/glamour v0.3.0 // indirect
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 // indirect
github.com/evanphx/json-patch/v5 v5.6.0
github.com/jstemmer/go-junit-report v1.0.0 // indirect
k8s.io/client-go v1.5.2
knative.dev/pkg v0.0.0-20220131144930-f4b57aef0006
sigs.k8s.io/controller-runtime v0.11.1
k8s.io/client-go v1.5.2 // indirect
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/DataDog/datadog-go v4.8.3+incompatible
cloud.google.com/go/secretmanager v1.9.0
github.com/PrimerAI/go-micro-utils-public/gmu v0.0.0-20220526222947-c3eb3c2c79c8
github.com/thanhpk/randstr v1.0.4
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
google.golang.org/grpc v1.50.1
)

require (
cloud.google.com/go/compute v1.3.0 // indirect
cloud.google.com/go/monitoring v1.0.0 // indirect
cloud.google.com/go/trace v1.0.0 // indirect
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
cloud.google.com/go/iam v0.6.0 // indirect
cloud.google.com/go/monitoring v1.7.0 // indirect
cloud.google.com/go/trace v1.3.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.24 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/DataDog/datadog-go v4.8.3+incompatible // indirect
github.com/DataDog/sketches-go v1.0.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.20.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v0.20.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/Microsoft/hcsshim v0.8.23 // indirect
github.com/PrimerAI/go-micro-utils-public/gmu v0.0.0-20220526222947-c3eb3c2c79c8 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/alecthomas/chroma v0.8.2 // indirect
github.com/apex/log v1.9.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/briandowns/spinner v1.11.1 // indirect
github.com/buildpacks/imgutil v0.0.0-20210209163614-30601e371ce3 // indirect
github.com/buildpacks/lifecycle v0.10.2 // indirect
github.com/buildpacks/pack v0.18.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/containerd/containerd v1.5.9 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.11.0 // indirect
Expand All @@ -111,15 +97,10 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/emicklei/go-restful v2.15.0+incompatible // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-kit/log v0.1.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
Expand All @@ -132,14 +113,11 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/henvic/httpretty v0.0.5 // indirect
github.com/heroku/color v0.0.6 // indirect
github.com/imdario/mergo v0.3.12 // indirect
Expand Down Expand Up @@ -175,6 +153,8 @@ require (
github.com/muesli/reflow v0.2.0 // indirect
github.com/muesli/termenv v0.8.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.17.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
github.com/opencontainers/runc v1.0.2 // indirect
Expand All @@ -184,7 +164,6 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/statsd_exporter v0.21.0 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rivo/uniseg v0.1.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20201211074657-223ce5d391b0 // indirect
Expand All @@ -199,7 +178,6 @@ require (
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
github.com/yuin/goldmark v1.4.1 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel v0.20.0 // indirect
go.opentelemetry.io/otel/exporters/stdout v0.20.0 // indirect
Expand All @@ -210,27 +188,27 @@ require (
go.opentelemetry.io/otel/sdk/metric v0.20.0 // indirect
go.opentelemetry.io/otel/trace v0.20.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.7.0 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220223155357-96fed51e1446 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/api v0.67.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.102.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220207164111-0872dc986b00 // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gotest.tools/v3 v3.1.0 // indirect
k8s.io/klog/v2 v2.40.1 // indirect
k8s.io/kube-openapi v0.0.0-20220124234850-424119656bbf // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
Expand Down
Loading