@@ -2,6 +2,7 @@ package main
22
33import (
44 "context"
5+ "encoding/base64"
56 "flag"
67 "fmt"
78 "log"
@@ -67,6 +68,16 @@ func main() {
6768 opts := slog.HandlerOptions {Level : slog .LevelInfo }
6869 slog .SetDefault (slog .New (slog .NewJSONHandler (os .Stdout , & opts )))
6970
71+ var ghAppPrivateKey []byte
72+ if b64Key := os .Getenv ("GH_APP_PRIVATE_KEY" ); b64Key != "" {
73+ var err error
74+ ghAppPrivateKey , err = base64 .StdEncoding .DecodeString (b64Key )
75+ if err != nil {
76+ slog .Error ("Failed to base64 decode GH_APP_PRIVATE_KEY" , "error" , err )
77+ os .Exit (1 )
78+ }
79+ }
80+
7081 var cntrlCfg = controller.Config {
7182 Template : getEnvOrDefault ("DN_TEMPLATE" , defaultTemplate ),
7283 LogicalEnvironment : os .Getenv ("LOGICAL_ENVIRONMENT" ),
@@ -76,10 +87,16 @@ func main() {
7687 BaseURL : getEnvOrDefault ("BASE_URL" , "api.github.com" ),
7788 GHAppID : getEnvOrDefault ("GH_APP_ID" , "" ),
7889 GHInstallID : getEnvOrDefault ("GH_INSTALL_ID" , "" ),
79- GHAppPrivateKey : getEnvOrDefault ("GH_APP_PRIV_KEY" , "" ),
90+ GHAppPrivateKey : ghAppPrivateKey ,
91+ GHAppPrivateKeyPath : getEnvOrDefault ("GH_APP_PRIV_KEY_PATH" , "" ),
8092 Organization : os .Getenv ("GITHUB_ORG" ),
8193 }
8294
95+ if len (cntrlCfg .GHAppPrivateKey ) > 0 && cntrlCfg .GHAppPrivateKeyPath != "" {
96+ slog .Error ("Both GH_APP_PRIVATE_KEY and GH_APP_PRIV_KEY_PATH are set. Only one can be used." )
97+ os .Exit (1 )
98+ }
99+
83100 if ! controller .ValidTemplate (cntrlCfg .Template ) {
84101 slog .Error ("Template must contain at least one placeholder" ,
85102 "template" , cntrlCfg .Template ,
0 commit comments