Skip to content

Commit 5005b43

Browse files
committed
Introduce support for looking up GH app installation ID
Signed-off-by: Matheus Pimenta <[email protected]>
1 parent c125bcb commit 5005b43

File tree

9 files changed

+127
-147
lines changed

9 files changed

+127
-147
lines changed

cmd/flux/create_secret_github_app.go

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ var createSecretGitHubAppCmd = &cobra.Command{
4646
}
4747

4848
type secretGitHubAppFlags struct {
49-
appID string
50-
appInstallationID string
51-
privateKeyFile string
52-
baseURL string
49+
appID string
50+
appInstallationOwner string
51+
appInstallationID string
52+
privateKeyFile string
53+
baseURL string
5354
}
5455

5556
var secretGitHubAppArgs = secretGitHubAppFlags{}
5657

5758
func init() {
5859
createSecretGitHubAppCmd.Flags().StringVar(&secretGitHubAppArgs.appID, "app-id", "", "github app ID")
60+
createSecretGitHubAppCmd.Flags().StringVar(&secretGitHubAppArgs.appInstallationOwner, "app-installation-owner", "", "github app installation owner (user or organization)")
5961
createSecretGitHubAppCmd.Flags().StringVar(&secretGitHubAppArgs.appInstallationID, "app-installation-id", "", "github app installation ID")
6062
createSecretGitHubAppCmd.Flags().StringVar(&secretGitHubAppArgs.privateKeyFile, "app-private-key", "", "github app private key file path")
6163
createSecretGitHubAppCmd.Flags().StringVar(&secretGitHubAppArgs.baseURL, "app-base-url", "", "github app base URL")
@@ -70,29 +72,18 @@ func createSecretGitHubAppCmdRun(cmd *cobra.Command, args []string) error {
7072

7173
secretName := args[0]
7274

73-
if secretGitHubAppArgs.appID == "" {
74-
return fmt.Errorf("--app-id is required")
75-
}
76-
77-
if secretGitHubAppArgs.appInstallationID == "" {
78-
return fmt.Errorf("--app-installation-id is required")
79-
}
80-
81-
if secretGitHubAppArgs.privateKeyFile == "" {
82-
return fmt.Errorf("--app-private-key is required")
83-
}
84-
8575
privateKey, err := os.ReadFile(secretGitHubAppArgs.privateKeyFile)
8676
if err != nil {
8777
return fmt.Errorf("unable to read private key file: %w", err)
8878
}
8979

9080
opts := sourcesecret.Options{
91-
Name: secretName,
92-
Namespace: *kubeconfigArgs.Namespace,
93-
GitHubAppID: secretGitHubAppArgs.appID,
94-
GitHubAppInstallationID: secretGitHubAppArgs.appInstallationID,
95-
GitHubAppPrivateKey: string(privateKey),
81+
Name: secretName,
82+
Namespace: *kubeconfigArgs.Namespace,
83+
GitHubAppID: secretGitHubAppArgs.appID,
84+
GitHubAppInstallationOwner: secretGitHubAppArgs.appInstallationOwner,
85+
GitHubAppInstallationID: secretGitHubAppArgs.appInstallationID,
86+
GitHubAppPrivateKey: string(privateKey),
9687
}
9788

9889
if secretGitHubAppArgs.baseURL != "" {

cmd/flux/create_secret_githubapp_test.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,14 @@ func TestCreateSecretGitHubApp(t *testing.T) {
3131
args: "create secret githubapp",
3232
assert: assertError("name is required"),
3333
},
34-
{
35-
name: "create githubapp secret with missing app-id",
36-
args: "create secret githubapp appinfo",
37-
assert: assertError("--app-id is required"),
38-
},
39-
{
40-
name: "create githubapp secret with missing appInstallationID",
41-
args: "create secret githubapp appinfo --app-id 1",
42-
assert: assertError("--app-installation-id is required"),
43-
},
44-
{
45-
name: "create githubapp secret with missing private key file",
46-
args: "create secret githubapp appinfo --app-id 1 --app-installation-id 2",
47-
assert: assertError("--app-private-key is required"),
48-
},
4934
{
5035
name: "create githubapp secret with private key file that does not exist",
5136
args: "create secret githubapp appinfo --app-id 1 --app-installation-id 2 --app-private-key pk.pem",
5237
assert: assertError("unable to read private key file: open pk.pem: no such file or directory"),
5338
},
5439
{
5540
name: "create githubapp secret with app info",
56-
args: "create secret githubapp appinfo --namespace my-namespace --app-id 1 --app-installation-id 2 --app-private-key ./testdata/create_secret/githubapp/test-private-key.pem --export",
41+
args: "create secret githubapp appinfo --namespace my-namespace --app-id 1 --app-installation-owner my-org --app-private-key ./testdata/create_secret/githubapp/test-private-key.pem --export",
5742
assert: assertGoldenFile("testdata/create_secret/githubapp/secret.yaml"),
5843
},
5944
{

cmd/flux/testdata/create_secret/githubapp/secret.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
namespace: my-namespace
77
stringData:
88
githubAppID: "1"
9-
githubAppInstallationID: "2"
9+
githubAppInstallationOnwer: my-org
1010
githubAppPrivateKey: |-
1111
-----BEGIN RSA PRIVATE KEY-----
1212
YcE2CgWILk+uiVNseHnOU2frG7k2RJZtdDo8GNI6pQWFlwU/NsQoJBrtEDyYVkap

go.mod

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ replace gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.1
88
require (
99
github.com/Masterminds/semver/v3 v3.4.0
1010
github.com/ProtonMail/go-crypto v1.3.0
11-
github.com/cyphar/filepath-securejoin v0.6.0
11+
github.com/cyphar/filepath-securejoin v0.6.1
1212
github.com/distribution/distribution/v3 v3.0.0
1313
github.com/fluxcd/cli-utils v0.36.0-flux.15
1414
github.com/fluxcd/go-git-providers v0.25.0
@@ -18,23 +18,22 @@ require (
1818
github.com/fluxcd/kustomize-controller/api v1.7.3
1919
github.com/fluxcd/notification-controller/api v1.7.5
2020
github.com/fluxcd/pkg/apis/event v0.21.0
21-
github.com/fluxcd/pkg/apis/meta v1.23.0
21+
github.com/fluxcd/pkg/apis/meta v1.24.0
2222
github.com/fluxcd/pkg/auth v0.33.0
2323
github.com/fluxcd/pkg/chartutil v1.17.0
2424
github.com/fluxcd/pkg/envsubst v1.5.0
25-
github.com/fluxcd/pkg/git v0.38.0
26-
github.com/fluxcd/pkg/git/gogit v0.42.0
25+
github.com/fluxcd/pkg/git v0.40.0
2726
github.com/fluxcd/pkg/kustomize v1.24.0
2827
github.com/fluxcd/pkg/oci v0.58.0
29-
github.com/fluxcd/pkg/runtime v0.90.0
28+
github.com/fluxcd/pkg/runtime v0.95.0
3029
github.com/fluxcd/pkg/sourceignore v0.15.0
3130
github.com/fluxcd/pkg/ssa v0.61.0
3231
github.com/fluxcd/pkg/ssh v0.23.0
3332
github.com/fluxcd/pkg/tar v0.16.0
3433
github.com/fluxcd/pkg/version v0.11.0
3534
github.com/fluxcd/source-controller/api v1.7.4
3635
github.com/fluxcd/source-watcher/api/v2 v2.0.3
37-
github.com/go-git/go-git/v5 v5.16.3
36+
github.com/go-git/go-git/v5 v5.16.4
3837
github.com/go-logr/logr v1.4.3
3938
github.com/gonvenience/bunt v1.4.2
4039
github.com/gonvenience/ytbx v1.4.7
@@ -47,13 +46,13 @@ require (
4746
github.com/mattn/go-shellwords v1.0.12
4847
github.com/notaryproject/notation-go v1.3.2
4948
github.com/olekukonko/tablewriter v0.0.5
50-
github.com/onsi/gomega v1.38.2
49+
github.com/onsi/gomega v1.38.3
5150
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
5251
github.com/spf13/cobra v1.10.1
5352
github.com/theckman/yacspin v0.13.12
54-
golang.org/x/crypto v0.44.0
55-
golang.org/x/term v0.37.0
56-
golang.org/x/text v0.31.0
53+
golang.org/x/crypto v0.46.0
54+
golang.org/x/term v0.38.0
55+
golang.org/x/text v0.32.0
5756
k8s.io/api v0.34.2
5857
k8s.io/apiextensions-apiserver v0.34.2
5958
k8s.io/apimachinery v0.34.2
@@ -135,7 +134,7 @@ require (
135134
github.com/go-errors/errors v1.5.1 // indirect
136135
github.com/go-fed/httpsig v1.1.0 // indirect
137136
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
138-
github.com/go-git/go-billy/v5 v5.6.2 // indirect
137+
github.com/go-git/go-billy/v5 v5.7.0 // indirect
139138
github.com/go-ldap/ldap/v3 v3.4.10 // indirect
140139
github.com/go-logr/stdr v1.2.2 // indirect
141140
github.com/go-openapi/jsonpointer v0.21.1 // indirect
@@ -249,10 +248,10 @@ require (
249248
go.opentelemetry.io/proto/otlp v1.8.0 // indirect
250249
go.yaml.in/yaml/v2 v2.4.3 // indirect
251250
go.yaml.in/yaml/v3 v3.0.4 // indirect
252-
golang.org/x/net v0.47.0 // indirect
251+
golang.org/x/net v0.48.0 // indirect
253252
golang.org/x/oauth2 v0.33.0 // indirect
254-
golang.org/x/sync v0.18.0 // indirect
255-
golang.org/x/sys v0.38.0 // indirect
253+
golang.org/x/sync v0.19.0 // indirect
254+
golang.org/x/sys v0.39.0 // indirect
256255
golang.org/x/time v0.14.0 // indirect
257256
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
258257
google.golang.org/api v0.256.0 // indirect

0 commit comments

Comments
 (0)