agent/acs/handler/refresh_credentials_handler.go
func (refreshHandler *refreshCredentialsHandler) handleSingleMessage(message *ecsacs.IAMRoleCredentialsMessage) error {
	// Validate fields in the message
	err := validateIAMRoleCredentialsMessage(message)
	if err != nil {
		seelog.Errorf("Error validating credentials message: %v", err)
		return err
	}
	taskArn := aws.StringValue(message.TaskArn)
	messageId := aws.StringValue(message.MessageId)
	task, ok := refreshHandler.taskEngine.GetTaskByArn(taskArn)
	if !ok {
		seelog.Errorf("Task not found in the engine for the arn in credentials message, arn: %s, messageId: %s", taskArn, messageId)
		return fmt.Errorf("task not found in the engine for the arn in credentials message, arn: %s", taskArn)
	}

	roleType := aws.StringValue(message.RoleType)
	if !validRoleType(roleType) {
		seelog.Errorf("Unknown RoleType for task in credentials message, roleType: %s arn: %s, messageId: %s", roleType, taskArn, messageId)
	} else {
		err = refreshHandler.credentialsManager.SetTaskCredentials(
			&(credentials.TaskIAMRoleCredentials{
				ARN:                taskArn,
				IAMRoleCredentials: credentials.IAMRoleCredentialsFromACS(message.RoleCredentials, roleType),
			}))
		if err != nil {
			seelog.Errorf("Unable to update credentials for task, err: %v messageId: %s", err, messageId)
			return fmt.Errorf("unable to update credentials %v", err)
		}

		if roleType == credentials.ApplicationRoleType {
			task.SetCredentialsID(aws.StringValue(message.RoleCredentials.CredentialsId))
		}
		if roleType == credentials.ExecutionRoleType {
			task.SetExecutionRoleCredentialsID(aws.StringValue(message.RoleCredentials.CredentialsId))
		}
	}

	go func() {
		response := &ecsacs.IAMRoleCredentialsAckRequest{
			Expiration:    message.RoleCredentials.Expiration,
			MessageId:     message.MessageId,
			CredentialsId: message.RoleCredentials.CredentialsId,
		}
		refreshHandler.ackRequest <- response
	}()
	return nil
}
func (refreshHandler *refreshCredentialsHandler) handleSingleMessage(message *ecsacs.IAMRoleCredentialsMessage) error {
	// Validate fields in the message
	err := validateIAMRoleCredentialsMessage(message)
	if err != nil {
		seelog.Errorf("Error validating credentials message: %v", err)
		return err
	}
	taskArn := aws.StringValue(message.TaskArn)
	messageId := aws.StringValue(message.MessageId)
	task, ok := refreshHandler.taskEngine.GetTaskByArn(taskArn)
	if !ok {
		seelog.Errorf("Task not found in the engine for the arn in credentials message, arn: %s, messageId: %s", taskArn, messageId)
		return fmt.Errorf("task not found in the engine for the arn in credentials message, arn: %s", taskArn)
	}

	roleType := aws.StringValue(message.RoleType)
	if !validRoleType(roleType) {
		seelog.Errorf("Unknown RoleType for task in credentials message, roleType: %s arn: %s, messageId: %s", roleType, taskArn, messageId)
	} else {
		err = refreshHandler.credentialsManager.SetTaskCredentials(
			&(credentials.TaskIAMRoleCredentials{
				ARN:                taskArn,
				IAMRoleCredentials: credentials.IAMRoleCredentialsFromACS(message.RoleCredentials, roleType),
			}))
		if err != nil {
			seelog.Errorf("Unable to update credentials for task, err: %v messageId: %s", err, messageId)
			return fmt.Errorf("unable to update credentials %v", err)
		}

		if roleType == credentials.ApplicationRoleType {
			task.SetCredentialsID(aws.StringValue(message.RoleCredentials.CredentialsId))
		}
		if roleType == credentials.ExecutionRoleType {
			task.SetExecutionRoleCredentialsID(aws.StringValue(message.RoleCredentials.CredentialsId))
		}
	}

	go func() {
		response := &ecsacs.IAMRoleCredentialsAckRequest{
			Expiration:    message.RoleCredentials.Expiration,
			MessageId:     message.MessageId,
			CredentialsId: message.RoleCredentials.CredentialsId,
		}
		refreshHandler.ackRequest <- response
	}()
	return nil
}
func ( refreshHandler * refreshCredentialsHandler ) handleSingleMessage ( message * ecsacs . IAMRoleCredentialsMessage ) error { // Validate fields in the message err := validateIAMRoleCredentialsMessage ( message ) if err != nil { seelog . Errorf ( " " , err ) return err } taskArn := aws . StringValue ( message . TaskArn ) messageId := aws . StringValue ( message . MessageId ) task , ok := refreshHandler . taskEngine . GetTaskByArn ( taskArn ) if ! ok { seelog . Errorf ( " " , taskArn , messageId ) return fmt . Errorf ( " " , taskArn ) } roleType := aws . StringValue ( message . RoleType ) if ! validRoleType ( roleType ) { seelog . Errorf ( " " , roleType , taskArn , messageId ) } else { err = refreshHandler . credentialsManager . SetTaskCredentials ( & ( credentials . TaskIAMRoleCredentials { ARN : taskArn , IAMRoleCredentials : credentials . IAMRoleCredentialsFromACS ( message . RoleCredentials , roleType ) , } ) ) if err != nil { seelog . Errorf ( " " , err , messageId ) return fmt . Errorf ( " " , err ) } if roleType == credentials . ApplicationRoleType { task . SetCredentialsID ( aws . StringValue ( message . RoleCredentials . CredentialsId ) ) } if roleType == credentials . ExecutionRoleType { task . SetExecutionRoleCredentialsID ( aws . StringValue ( message . RoleCredentials . CredentialsId ) ) } } go func ( ) { response := & ecsacs . IAMRoleCredentialsAckRequest { Expiration : message . RoleCredentials . Expiration , MessageId : message . MessageId , CredentialsId : message . RoleCredentials . CredentialsId , } refreshHandler . ackRequest <- response } ( ) return nil }
// handleSingleMessage processes a single refresh credentials message.
handleSingleMessage processes a single refresh credentials message .