agent/handlers/v1/credentials_handler.go
func processCredentialsRequest(credentialsManager credentials.Manager, r *http.Request, credentialsID string, errPrefix string) ([]byte, string, string, *handlersutils.ErrorMessage, error) {
	if credentialsID == "" {
		errText := errPrefix + "No ID in the request"
		seelog.Infof("%s. Request IP Address: %s", errText, r.RemoteAddr)
		msg := &handlersutils.ErrorMessage{
			Code:          ErrNoIDInRequest,
			Message:       errText,
			HTTPErrorCode: http.StatusBadRequest,
		}
		return nil, "", "", msg, errors.New(errText)
	}

	credentials, ok := credentialsManager.GetTaskCredentials(credentialsID)
	if !ok {
		errText := errPrefix + "ID not found"
		seelog.Infof("%s. Request IP Address: %s", errText, r.RemoteAddr)
		msg := &handlersutils.ErrorMessage{
			Code:          ErrInvalidIDInRequest,
			Message:       errText,
			HTTPErrorCode: http.StatusBadRequest,
		}
		return nil, "", "", msg, errors.New(errText)
	}

	if utils.ZeroOrNil(credentials.ARN) && utils.ZeroOrNil(credentials.IAMRoleCredentials) {
		// This can happen when the agent is restarted and is reconciling its state.
		errText := errPrefix + "Credentials uninitialized for ID"
		seelog.Infof("%s. Request IP Address: %s", errText, r.RemoteAddr)
		msg := &handlersutils.ErrorMessage{
			Code:          ErrCredentialsUninitialized,
			Message:       errText,
			HTTPErrorCode: http.StatusServiceUnavailable,
		}
		return nil, "", "", msg, errors.New(errText)
	}

	credentialsJSON, err := json.Marshal(credentials.IAMRoleCredentials)
	if err != nil {
		errText := errPrefix + "Error marshaling credentials"
		seelog.Errorf("%s. Request IP Address: %s", errText, r.RemoteAddr)
		msg := &handlersutils.ErrorMessage{
			Code:          ErrInternalServer,
			Message:       "Internal server error",
			HTTPErrorCode: http.StatusInternalServerError,
		}
		return nil, "", "", msg, errors.New(errText)
	}

	// Success
	return credentialsJSON, credentials.ARN, credentials.IAMRoleCredentials.RoleType, nil, nil
}
func processCredentialsRequest(credentialsManager credentials.Manager, r *http.Request, credentialsID string, errPrefix string) ([]byte, string, string, *handlersutils.ErrorMessage, error) {
	if credentialsID == "" {
		errText := errPrefix + "No ID in the request"
		seelog.Infof("%s. Request IP Address: %s", errText, r.RemoteAddr)
		msg := &handlersutils.ErrorMessage{
			Code:          ErrNoIDInRequest,
			Message:       errText,
			HTTPErrorCode: http.StatusBadRequest,
		}
		return nil, "", "", msg, errors.New(errText)
	}

	credentials, ok := credentialsManager.GetTaskCredentials(credentialsID)
	if !ok {
		errText := errPrefix + "ID not found"
		seelog.Infof("%s. Request IP Address: %s", errText, r.RemoteAddr)
		msg := &handlersutils.ErrorMessage{
			Code:          ErrInvalidIDInRequest,
			Message:       errText,
			HTTPErrorCode: http.StatusBadRequest,
		}
		return nil, "", "", msg, errors.New(errText)
	}

	if utils.ZeroOrNil(credentials.ARN) && utils.ZeroOrNil(credentials.IAMRoleCredentials) {
		// This can happen when the agent is restarted and is reconciling its state.
		errText := errPrefix + "Credentials uninitialized for ID"
		seelog.Infof("%s. Request IP Address: %s", errText, r.RemoteAddr)
		msg := &handlersutils.ErrorMessage{
			Code:          ErrCredentialsUninitialized,
			Message:       errText,
			HTTPErrorCode: http.StatusServiceUnavailable,
		}
		return nil, "", "", msg, errors.New(errText)
	}

	credentialsJSON, err := json.Marshal(credentials.IAMRoleCredentials)
	if err != nil {
		errText := errPrefix + "Error marshaling credentials"
		seelog.Errorf("%s. Request IP Address: %s", errText, r.RemoteAddr)
		msg := &handlersutils.ErrorMessage{
			Code:          ErrInternalServer,
			Message:       "Internal server error",
			HTTPErrorCode: http.StatusInternalServerError,
		}
		return nil, "", "", msg, errors.New(errText)
	}

	// Success
	return credentialsJSON, credentials.ARN, credentials.IAMRoleCredentials.RoleType, nil, nil
}
// processCredentialsRequest returns the response json containing credentials for the credentials id in the request