From f8f7dbab2c7eeaf9df2c37c385866bb8a1d5eb84 Mon Sep 17 00:00:00 2001 From: Jun Sakata Date: Fri, 26 Apr 2024 12:31:41 +0900 Subject: [PATCH] directly read key --- flow/flow.go | 16 ++++++++-------- flow/process.go | 2 +- gitbot/client.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/flow/flow.go b/flow/flow.go index ce922c1..fc0a30c 100644 --- a/flow/flow.go +++ b/flow/flow.go @@ -16,12 +16,12 @@ var ( ) type Flow struct { - Env string - useApp bool - githubToken *string - githubAppID *int64 - githubAppInstlationID *int64 - githubAppPrivateKeyPath *string + Env string + useApp bool + githubToken *string + githubAppID *int64 + githubAppInstlationID *int64 + githubAppPrivateKey *string } func New(c *Config) (*Flow, error) { @@ -31,7 +31,7 @@ func New(c *Config) (*Flow, error) { githubToken := os.Getenv("FLOW_GITHUB_TOKEN") githubAppID := os.Getenv("FLOW_GITHUB_APP_ID") githubAppInstlationID := os.Getenv("FLOW_GITHUB_APP_INSTALLATION_ID") - githubAppPrivateKeyPath := os.Getenv("FLOW_GITHUB_APP_PRIVATE_KEY_PATH") + githubAppPrivateKey := os.Getenv("FLOW_GITHUB_APP_PRIVATE_KEY") f.githubToken = &githubToken @@ -50,7 +50,7 @@ func New(c *Config) (*Flow, error) { } f.githubAppInstlationID = &githubAppInstlationIDInt - f.githubAppPrivateKeyPath = &githubAppPrivateKeyPath + f.githubAppPrivateKey = &githubAppPrivateKey } if !f.useApp && f.githubToken == nil { diff --git a/flow/process.go b/flow/process.go index 4653f04..c28afb4 100644 --- a/flow/process.go +++ b/flow/process.go @@ -49,7 +49,7 @@ func (f *Flow) processImage(ctx context.Context, image, version string) error { func (f *Flow) getGitbotClient(ctx context.Context) *github.Client { if f.useApp { - return gitbot.NewGitHubClientWithApp(ctx, *f.githubAppID, *f.githubAppInstlationID, *f.githubAppPrivateKeyPath) + return gitbot.NewGitHubClientWithApp(ctx, *f.githubAppID, *f.githubAppInstlationID, *f.githubAppPrivateKey) } return gitbot.NewGitHubClient(ctx, *f.githubToken) } diff --git a/gitbot/client.go b/gitbot/client.go index 1859ebf..8e9f8f0 100644 --- a/gitbot/client.go +++ b/gitbot/client.go @@ -17,9 +17,9 @@ func NewGitHubClient(ctx context.Context, token string) *github.Client { return github.NewClient(tc) } -func NewGitHubClientWithApp(ctx context.Context, appID, installationID int64, privateKeyPath string) *github.Client { +func NewGitHubClientWithApp(ctx context.Context, appID, installationID int64, privateKey string) *github.Client { tr := http.DefaultTransport - itr, err := ghinstallation.NewKeyFromFile(tr, appID, installationID, privateKeyPath) + itr, err := ghinstallation.New(tr, appID, installationID, []byte(privateKey)) if err != nil { log.Fatal(err) }