Skip to content

Commit fb1752d

Browse files
authored
fix: correct config usage (#5)
* Add GITHUB_APP_TOKEN and use key to sign JWT * FindOrganizationInstallation using DEPENDABOT_ORG * Remove unused DEPENDABOT_OWNER configuration
1 parent 360d8fd commit fb1752d

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ The following instructions show how to setup the environment to run this code wi
5353
| CODEARTIFACT_DOMAIN_OWNER | Owner (AWS acc) for the AWS CodeArtifact domain. Also used when [using CodeArtifact with AWS Cli](https://docs.aws.amazon.com/cli/latest/reference/codeartifact/login.html) |
5454
| CODEARTIFACT_DURATION | Duration of the AWS CodeArtifact authToken. |
5555
| CODEARTIFACT_DOMAIN | AWS CodeArtifact Domain for which access is required. Also used when [using CodeArtifact with AWS Cli](https://docs.aws.amazon.com/cli/latest/reference/codeartifact/login.html) |
56-
| GITHUB_PRIVATE_KEY | GitHub secret for GitHub App authentication |
57-
| DEPENDABOT_OWNER | Owner of the GitHub organization |
5856
| DEPENDABOT_ORG | The GitHub organization for which the secret should be created |
57+
| GITHUB_PRIVATE_KEY | GitHub secret for GitHub App authentication |
5958
| GITHUB_APP_ID | The ID of the GitHub App used for authentication |
59+
| GITHUB_APP_TOKEN | GitHub App token used for encrypting secrets |
6060

6161
- Using env variables
6262
1. Setup environment variables regarding [point 1 from installation](#setup)
@@ -75,7 +75,7 @@ The following instructions show how to setup the environment to run this code wi
7575
./codeartifact-dependabot-sync -h
7676

7777
# run it with flag data
78-
./codeartifact-dependabot-sync -DEPENDABOT-ORG=exampleOrg -CODEARTIFACT_OWNER=exampleOwner ...
78+
./codeartifact-dependabot-sync -DEPENDABOT-ORG=exampleOrg ...
7979
```
8080

8181

github.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Permissions struct {
4444
}
4545

4646
func getJWT() (*string, error) {
47-
pemBytes := []byte(viper.GetString("DEPENDABOT_GITHUB_TOKEN"))
47+
pemBytes := []byte(viper.GetString("GITHUB_PRIVATE_KEY"))
4848

4949
block, _ := pem.Decode(pemBytes)
5050
key, err := x509.ParsePKCS1PrivateKey(block.Bytes)
@@ -74,7 +74,8 @@ func setupGitHubAppClient(ctx context.Context) (*github.Client, error) {
7474

7575
tempClient := newGitHubClient(ctx, *signedToken)
7676

77-
inst, _, err := tempClient.Apps.FindOrganizationInstallation(ctx, "TierMobility")
77+
78+
inst, _, err := tempClient.Apps.FindOrganizationInstallation(ctx, viper.GetString("DEPENDABOT_ORG"))
7879
if err != nil {
7980
return nil, fmt.Errorf("setting up GitHub App client: %w", err)
8081
}
@@ -147,7 +148,7 @@ func encryptSecret(plainSecret, key, tok string) (*string, error) {
147148
func createOrUpdateDependabotSecret(ctx context.Context, ghClient *github.Client, secret string) error {
148149
var (
149150
org = viper.GetString("DEPENDABOT_ORG")
150-
token = viper.GetString("DEPENDABOT_GITHUB_TOKEN")
151+
token = viper.GetString("GITHUB_APP_TOKEN")
151152
)
152153

153154
pk, _, err := ghClient.Dependabot.GetOrgPublicKey(ctx, org)

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121

2222
func setupViper() {
2323
var (
24-
organization = flag.String("DEPENDABOT_ORG", os.Getenv("DEPENDABOT_ORG"), "the GitHub organization for which the secret should be created")
2524
githubSecret = flag.String("GITHUB_PRIVATE_KEY", os.Getenv("GITHUB_PRIVATE_KEY"), "GitHub secret for GitHub App authentication")
2625
githubAppID = flag.String("GITHUB_APP_ID", os.Getenv("GITHUB_APP_ID"), "the ID of the GitHub App used for authentication")
27-
organizationOwner = flag.String("DEPENDABOT_OWNER", os.Getenv("DEPENDABOT_OWNER"), " owner of the GitHub organization")
26+
githubAppToken = flag.String("GITHUB_APP_TOKEN", os.Getenv("GITHUB_APP_TOKEN"), "the token of the GitHub App used for authentication")
27+
organization = flag.String("DEPENDABOT_ORG", os.Getenv("DEPENDABOT_ORG"), "the GitHub organization for which the secret should be created")
2828
tokenDuration = flag.String("CODEARTIFACT_DURATION", os.Getenv("CODEARTIFACT_DURATION"), "duration of the AWS CodeArtifact authToken")
2929
codeartifactDomain = flag.String("CODEARTIFACT_DOMAIN", os.Getenv("CODEARTIFACT_DOMAIN"), "AWS CodeArtifact Domain for which access is required")
3030
codeartifactDomainOwner = flag.String("CODEARTIFACT_DOMAIN_OWNER", os.Getenv("CODEARTIFACT_DOMAIN_OWNER"), "owner (AWS acc) for the AWS CodeArtifact domain")
@@ -34,9 +34,9 @@ func setupViper() {
3434
flag.Parse()
3535

3636
viper.Set("GITHUB_APP_ID", githubAppID)
37+
viper.Set("GITHUB_APP_TOKEN", githubAppToken)
3738
viper.Set("GITHUB_PRIVATE_KEY", githubSecret)
3839
viper.Set("DEPENDABOT_ORG", organization)
39-
viper.Set("DEPENDABOT_OWNER", organizationOwner)
4040
viper.Set("CODEARTIFACT_DURATION", tokenDuration)
4141
viper.Set("CODEARTIFACT_DOMAIN", codeartifactDomain)
4242
viper.Set("CODEARTIFACT_DOMAIN_OWNER", codeartifactDomainOwner)

0 commit comments

Comments
 (0)