func configureAccountsE(cmd *cobra.Command, args []string) error {
	var accountsJSON map[string][]string

	accountsEnv := os.Getenv("VAULT_UTIL_ACCOUNTS")

	if accountsEnv == "" {
		return nil
	}

	lock, err := fslock.GetLock(ciutils.LockPath("configure-accounts"))
	if err != nil {
		return err
	}

	retryErr := retry.Do(
		func() error {
			_, lockErr := lock.TryLock()
			if lockErr != nil {
				return lockErr
			}

			jsonErr := json.Unmarshal([]byte(accountsEnv), &accountsJSON)
			if jsonErr != nil {
				return errors.Wrap(jsonErr, "failed to unmarshal accounts JSON")
			}

			configErr := configureAccounts(accountsJSON)
			if configErr != nil {
				return errors.Wrap(configErr, "failed to configure accounts")
			}

			unlockErr := lock.Unlock()
			if unlockErr != nil {
				return errors.Wrap(unlockErr, "failed to release account configuration lock")
			}

			return nil
		},
		retry.Attempts(fslock.GetRetryAttempts()),
		retry.Delay(fslock.GetRetryDelay()),
		retry.DelayType(fslock.GetRetryDelayType()),
		retry.RetryIf(func(err error) bool {
			return errors.Cause(err) == filesystem.ErrLocked
		}),
		retry.OnRetry(func(n uint, err error) {
			if errors.Cause(err) == filesystem.ErrLocked {
				cmd.Printf("another account configuration already in progress -- waiting (%d/%d)\n", n, fslock.GetRetryAttempts())
			}
		}),
	)

	return retryErr
}
// Some utilities do not like it when you try and configure accounts at the same time.
// If we're able to get the first lock on the instance, proceed.
// Otherwise, we'll loop and wait for the update to finish (lock is released).
Some utilities do not like it when you try and configure accounts at the same time.
If we're able to get the first lock on the instance, proceed.
Otherwise, we'll loop and wait for the update to finish (lock is released).
// Some utilities do not like it when you try and configure accounts at the same time . // If we ' re able to get the first lock on the instance proceed . // Otherwise we ' ll loop and wait for the update to finish ( lock is released ) .
func configureAccountsE(cmd *cobra.Command, args []string) error {
	var accountsJSON map[string][]string
	accountsEnv := os.Getenv("VAULT_UTIL_ACCOUNTS")
	if accountsEnv == "" {
		return nil
	}
	lock, err := fslock.GetLock(ciutils.LockPath("configure-accounts"))
	if err != nil {
		return err
	}
	retryErr := retry.Do(
		func() error {
			_, lockErr := lock.TryLock()
			if lockErr != nil {
				return lockErr
			}
			jsonErr := json.Unmarshal([]byte(accountsEnv), &accountsJSON)
			if jsonErr != nil {
				return errors.Wrap(jsonErr, "failed to unmarshal accounts JSON")
			}
			configErr := configureAccounts(accountsJSON)
			if configErr != nil {
				return errors.Wrap(configErr, "failed to configure accounts")
			}
			unlockErr := lock.Unlock()
			if unlockErr != nil {
				return errors.Wrap(unlockErr, "failed to release account configuration lock")
			}
			return nil
		},
		retry.Attempts(fslock.GetRetryAttempts()),
		retry.Delay(fslock.GetRetryDelay()),
		retry.DelayType(fslock.GetRetryDelayType()),
		retry.RetryIf(func(err error) bool {
			return errors.Cause(err) == filesystem.ErrLocked
		}),
		retry.OnRetry(func(n uint, err error) {
			if errors.Cause(err) == filesystem.ErrLocked {
				cmd.Printf("another account configuration already in progress -- waiting (%d/%d)\n", n, fslock.GetRetryAttempts())
			}
		}),
	)
	return retryErr
}
func configureAccountsE ( cmd * cobra . Command , args [ ] string ) error { var accountsJSON map [ string ] [ ] string accountsEnv := os . Getenv ( " " ) if accountsEnv == " " { return nil } lock , err := fslock . GetLock ( ciutils . LockPath ( " " ) ) if err != nil { return err } retryErr := retry . Do ( func ( ) error { _ , lockErr := lock . TryLock ( ) if lockErr != nil { return lockErr } jsonErr := json . Unmarshal ( [ ] byte ( accountsEnv ) , & accountsJSON ) if jsonErr != nil { return errors . Wrap ( jsonErr , " " ) } configErr := configureAccounts ( accountsJSON ) if configErr != nil { return errors . Wrap ( configErr , " " ) } unlockErr := lock . Unlock ( ) if unlockErr != nil { return errors . Wrap ( unlockErr , " " ) } return nil } , retry . Attempts ( fslock . GetRetryAttempts ( ) ) , retry . Delay ( fslock . GetRetryDelay ( ) ) , retry . DelayType ( fslock . GetRetryDelayType ( ) ) , retry . RetryIf ( func ( err error ) bool { return errors . Cause ( err ) == filesystem . ErrLocked } ) , retry . OnRetry ( func ( n uint , err error ) { if errors . Cause ( err ) == filesystem . ErrLocked { cmd . Printf ( " \n " , n , fslock . GetRetryAttempts ( ) ) } } ) , ) return retryErr }
Some utilities do not like it when you try and configure accounts at the same time.
Some utilities do not like it when you try and configure accounts at the same time .