Преглед на файлове

Update files for Github app config cleanup (#2930)

* Update files for github app config

* Change Env varible

* Fix Tests

* File Read-in

---------

Co-authored-by: Stefan McShane <stefanmcshane@users.noreply.github.com>
sdess09 преди 3 години
родител
ревизия
f6318cd495

+ 1 - 4
api/server/shared/config/env/envconfs.go

@@ -46,10 +46,7 @@ type ServerConf struct {
 	GithubAppWebhookSecret string `env:"GITHUB_APP_WEBHOOK_SECRET"`
 	GithubAppID            string `env:"GITHUB_APP_ID"`
 	GithubAppSecretPath    string `env:"GITHUB_APP_SECRET_PATH"`
-	// GithubAppSecretBase64 is a base64 encoded version of the GithubAppSecret. This can be used instead of GithubAppSecretPath to pass in a key, allowing for support in systems where mounting the secret is not possible.
-	// If GithubAppSecretBase64 is set, it will check for a file at GithubAppSecretPath. If a file is found, the file will NOT be overwritten. If no file it found, then GithubAppSecretBase64 will be decoded and written to GithubAppSecretPath.
-	GithubAppSecretBase64 string `env:"GITHUB_APP_SECRET_BASE64"`
-	GithubAppSecret       []byte
+	GithubAppSecret        []byte
 
 	GoogleClientID         string `env:"GOOGLE_CLIENT_ID"`
 	GoogleClientSecret     string `env:"GOOGLE_CLIENT_SECRET"`

+ 8 - 39
api/server/shared/config/loader/loader.go

@@ -1,10 +1,8 @@
 package loader
 
 import (
-	"encoding/base64"
 	"errors"
 	"fmt"
-	"io/ioutil"
 	"net/http"
 	"os"
 	"path/filepath"
@@ -186,51 +184,22 @@ func (e *EnvConfigLoader) LoadConfig() (res *config.Config, err error) {
 		res.Logger.Info().Msg("Created Github client")
 	}
 
-	if sc.GithubAppSecretBase64 != "" {
-		if sc.GithubAppSecretPath == "" {
-			sc.GithubAppSecretPath = "github-app-secret-key"
-		}
-		_, err := os.Stat(sc.GithubAppSecretPath)
-		if err != nil {
-			if !errors.Is(err, os.ErrNotExist) {
-				return nil, fmt.Errorf("GITHUB_APP_SECRET_BASE64 provided, but error checking if GITHUB_APP_SECRET_PATH exists: %w", err)
-			}
-			secret, err := base64.StdEncoding.DecodeString(sc.GithubAppSecretBase64)
-			if err != nil {
-				return nil, fmt.Errorf("GITHUB_APP_SECRET_BASE64 provided, but error decoding: %w", err)
-			}
-			_, err = createDirectoryRecursively(sc.GithubAppSecretPath)
-			if err != nil {
-				return nil, fmt.Errorf("GITHUB_APP_SECRET_BASE64 provided, but error creating directory for GITHUB_APP_SECRET_PATH: %w", err)
-			}
-			err = os.WriteFile(sc.GithubAppSecretPath, secret, os.ModePerm)
-			if err != nil {
-				return nil, fmt.Errorf("GITHUB_APP_SECRET_BASE64 provided, but error writing to GITHUB_APP_SECRET_PATH: %w", err)
-			}
-		}
-	}
-
 	if sc.GithubAppClientID != "" &&
 		sc.GithubAppClientSecret != "" &&
 		sc.GithubAppName != "" &&
 		sc.GithubAppWebhookSecret != "" &&
 		sc.GithubAppSecretPath != "" &&
 		sc.GithubAppID != "" {
-		if AppID, err := strconv.ParseInt(sc.GithubAppID, 10, 64); err == nil {
-			res.GithubAppConf = oauth.NewGithubAppClient(&oauth.Config{
-				ClientID:     sc.GithubAppClientID,
-				ClientSecret: sc.GithubAppClientSecret,
-				Scopes:       []string{"read:user"},
-				BaseURL:      sc.ServerURL,
-			}, sc.GithubAppName, sc.GithubAppWebhookSecret, sc.GithubAppSecretPath, AppID)
-		}
-
-		secret, err := ioutil.ReadFile(sc.GithubAppSecretPath)
+		AppID, err := strconv.Atoi(sc.GithubAppID)
 		if err != nil {
-			return nil, fmt.Errorf("could not read github app secret: %s", err)
+			return nil, fmt.Errorf("could not read github App ID: %s", err)
 		}
-
-		sc.GithubAppSecret = append(sc.GithubAppSecret, secret...)
+		res.GithubAppConf = oauth.NewGithubAppClient(&oauth.Config{
+			ClientID:     sc.GithubAppClientID,
+			ClientSecret: sc.GithubAppClientSecret,
+			Scopes:       []string{"read:user"},
+			BaseURL:      sc.ServerURL,
+		}, sc.GithubAppName, sc.GithubAppWebhookSecret, sc.GithubAppSecretPath, int64(AppID))
 	}
 
 	if sc.SlackClientID != "" && sc.SlackClientSecret != "" {

+ 1 - 5
dashboard/src/main/home/cluster-dashboard/env-groups/EnvGroupArray.tsx

@@ -153,11 +153,7 @@ const EnvGroupArray = ({
                   {!disabled && (
                     <DeleteButton
                       onClick={() => {
-                        let _values = values;
-                        _values = _values.filter(
-                          (val) => val.key !== entry.key
-                        );
-                        setValues(_values);
+                        setValues(values.filter((val, index) => index !== i));
                       }}
                     >
                       <i className="material-icons">cancel</i>