Skip to content

Commit

Permalink
refactor(be): add method to config
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Jan 26, 2022
1 parent 4d00ee8 commit a68c64c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
12 changes: 2 additions & 10 deletions db/AccessKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@ func (key *AccessKey) SerializeSecret() error {
return nil
}

encryptionString := os.Getenv("SEMAPHORE_ACCESS_KEY_ENCRYPTION")

if encryptionString == "" {
encryptionString = util.Config.AccessKeyEncryption
}
encryptionString := util.Config.GetAccessKeyEncryption()

if encryptionString == "" {
secret := base64.StdEncoding.EncodeToString(plaintext)
Expand Down Expand Up @@ -289,11 +285,7 @@ func (key *AccessKey) DeserializeSecret() error {
return err
}

encryptionString := os.Getenv("SEMAPHORE_ACCESS_KEY_ENCRYPTION")

if encryptionString == "" {
encryptionString = util.Config.AccessKeyEncryption
}
encryptionString := util.Config.GetAccessKeyEncryption()

if encryptionString == "" {
err = key.unmarshalAppropriateField(ciphertext)
Expand Down
17 changes: 15 additions & 2 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ type ConfigType struct {
TmpPath string `json:"tmp_path"`

// cookie hashing & encryption
CookieHash string `json:"cookie_hash"`
CookieEncryption string `json:"cookie_encryption"`
CookieHash string `json:"cookie_hash"`
CookieEncryption string `json:"cookie_encryption"`
// AccessKeyEncryption is BASE64 encoded byte array used
// for encrypting and decrypting access keys stored in database.
// Do not use it! Use method GetAccessKeyEncryption instead of it.
AccessKeyEncryption string `json:"access_key_encryption"`

// email alerting
Expand Down Expand Up @@ -122,6 +125,16 @@ func (conf *ConfigType) ToJSON() ([]byte, error) {
return json.MarshalIndent(&conf, " ", "\t")
}

func (conf *ConfigType) GetAccessKeyEncryption() string {
ret := os.Getenv("SEMAPHORE_ACCESS_KEY_ENCRYPTION")

if ret == "" {
ret = conf.AccessKeyEncryption
}

return ret
}

// ConfigInit reads in cli flags, and switches actions appropriately on them
func ConfigInit(configPath string) {
loadConfig(configPath)
Expand Down

0 comments on commit a68c64c

Please sign in to comment.