示例#1
0
// AssignCredentials locks the global state and copy over roles data.
func AssignCredentials(rf *roles_files.RolesFiles) error {
	accessKey, secret, token, get_err := rf.Get()
	if get_err != nil {
		e := fmt.Sprintf("conf_iam.ReadIAM:cannot get a role file:%s",
			get_err.Error())
		return errors.New(e)
	}
	conf.Vals.ConfLock.Lock()
	conf.Vals.IAM.Credentials.AccessKey = accessKey
	conf.Vals.IAM.Credentials.Secret = secret
	conf.Vals.IAM.Credentials.Token = token
	conf.Vals.ConfLock.Unlock()
	e := fmt.Sprintf("IAM credentials assigned at %v", time.Now())
	slog.SLog(syslog.LOG_NOTICE, e, true)
	return nil
}
示例#2
0
// AssignCredentialsToConf will safely copy the credentials data from rf to the conf c.
func AssignCredentialsToConf(rf *roles_files.RolesFiles, c *conf.AWS_Conf) error {
	if rf == nil || c == nil {
		return errors.New("conf_iam.AssignCredentialsToConf: rf or c is nil")
	}
	accessKey, secret, token, get_err := rf.Get()
	if get_err != nil {
		e := fmt.Sprintf("conf_iam.AssignCredentialsToConf:cannot get a role file:%s",
			get_err.Error())
		return errors.New(e)
	}
	c.ConfLock.Lock()
	c.IAM.Credentials.AccessKey = accessKey
	c.IAM.Credentials.Secret = secret
	c.IAM.Credentials.Token = token
	c.ConfLock.Unlock()
	e := fmt.Sprintf("IAM credentials assigned at %v", time.Now())
	log.Printf(e)
	return nil
}