Skip to content

Commit

Permalink
Adds new flag which ignores backup
Browse files Browse the repository at this point in the history
* adds new flag --do_backup which is true by default and disables backup
  functionality if set to false
  • Loading branch information
azak-azkaran committed Sep 7, 2023
1 parent c20880d commit 77bbd2e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
8 changes: 8 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Configuration struct {
RoleID string
SecretID string
useLogin bool
backup bool
}

type AgentConfig struct {
Expand Down Expand Up @@ -344,6 +345,12 @@ func ParseConfiguration(confi *Configuration) {
} else {
confi.useLogin = false
}

if viper.IsSet(MAIN_BACKUP) {
confi.backup = viper.GetBool(MAIN_BACKUP)
} else {
confi.backup = true
}

Sugar.Warn("Agent initalzing on: ", confi.Hostname)
Sugar.Info("Agent Configuration:",
Expand All @@ -356,5 +363,6 @@ func ParseConfiguration(confi *Configuration) {
"\nMount AllowOther: ", confi.MountAllow,
"\nRoleID: ", confi.RoleID,
"\nSecretID: ", confi.SecretID,
"\nBackup: ", confi.backup,
)
}
18 changes: 14 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func bindEnviorment() error {
return err
}

err = viper.BindEnv(MAIN_BACKUP)
if err != nil {
return err
}

return nil
}

Expand All @@ -78,6 +83,7 @@ func Init(vaultConfig *vault.Config, args []string) error {
addressCommend.String(MAIN_VAULT_ADDRESS, "https://localhost:8200", "The address to the vault server")
addressCommend.String(MAIN_VAULT_ROLE_ID, "", "Role ID for AppRole login into Vault")
addressCommend.String(MAIN_VAULT_SECRET_ID, "", "Secret ID for AppRole login into Vault")
addressCommend.String(MAIN_BACKUP, "true", "Do backup yes = true")

err := bindEnviorment()
if err != nil {
Expand Down Expand Up @@ -275,10 +281,14 @@ func Start() {
Sugar.Warn("Waking from Sleep")
mountFolders()
GitCheckout()
backup()
CheckBackupRepository()

Sugar.Warn("Going to Sleep")
if AgentConfiguration.backup {
backup()
CheckBackupRepository()
Sugar.Warn("Going to Sleep")
} else{
Sugar.Warn("Exiting since backup is disabled")
os.Exit(0)
}
}

func unsealVault(seal *vault.SealStatusResponse) {
Expand Down
1 change: 1 addition & 0 deletions statics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
MAIN_VAULT_ADDRESS = "vault_address"
MAIN_VAULT_SECRET_ID = "vault_secret_id"
MAIN_VAULT_ROLE_ID = "vault_role_id"
MAIN_BACKUP = "do_backup"

MAIN_MESSAGE_NOT_ENOUGH_KEYS = "Not enough vault keys in storage"
MAIN_MESSAGE_START_UNSEAL = "Starting to unseal Vault"
Expand Down

0 comments on commit 77bbd2e

Please sign in to comment.