func GetPolicy(ctx context.Context, clientsEndpoint string, clientID string, policyID string, protectionAPIToken string) (*KeycloakPolicy, error) {
	req, err := http.NewRequest("GET", clientsEndpoint+"/"+clientID+"/authz/resource-server/policy/"+policyID, nil)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err.Error(),
		}, "Unable to crete http request")
		return nil, errors.NewInternalError("unable to crete http request " + err.Error())
	}
	req.Header.Add("Authorization", "Bearer "+protectionAPIToken)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"client_id": clientID,
			"policy_id": policyID,
			"err":       err.Error(),
		}, "Unable to obtain a Keycloak policy")
		return nil, errors.NewInternalError("Unable to obtain a Keycloak policy " + err.Error())
	}
	switch res.StatusCode {
	case http.StatusOK:
		// OK
	case http.StatusNotFound:
		log.Error(ctx, map[string]interface{}{
			"client_id": clientID,
			"policy_id": policyID,
		}, "Keycloak policy is not found")
		return nil, errors.NewNotFoundError("policy", policyID)
	default:
		log.Error(ctx, map[string]interface{}{
			"client_id":       clientID,
			"policy_id":       policyID,
			"response_status": res.Status,
			"response_body":   rest.ReadBody(res.Body),
		}, "Unable to obtain a Keycloak policy")
		return nil, errors.NewInternalError("Unable to obtain a Keycloak policy. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}
	jsonString := rest.ReadBody(res.Body)

	var r KeycloakPolicy
	err = json.Unmarshal([]byte(jsonString), &r)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"client_id":   clientID,
			"policy_id":   policyID,
			"json_string": jsonString,
		}, "Unable to unmarshal json with the get keycloak policy request result")
		return nil, errors.NewInternalError(fmt.Sprintf("error when unmarshal json with get the keycloak policy request result %s ", jsonString) + err.Error())
	}

	return &r, nil
}
// GetPolicy obtains a policy from Keycloak
GetPolicy obtains a policy from Keycloak
// GetPolicy obtains a policy from Keycloak
func GetPolicy(ctx context.Context, clientsEndpoint string, clientID string, policyID string, protectionAPIToken string) (*KeycloakPolicy, error) {
	req, err := http.NewRequest("GET", clientsEndpoint+"/"+clientID+"/authz/resource-server/policy/"+policyID, nil)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err.Error(),
		}, "Unable to crete http request")
		return nil, errors.NewInternalError("unable to crete http request " + err.Error())
	}
	req.Header.Add("Authorization", "Bearer "+protectionAPIToken)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"client_id": clientID,
			"policy_id": policyID,
			"err":       err.Error(),
		}, "Unable to obtain a Keycloak policy")
		return nil, errors.NewInternalError("Unable to obtain a Keycloak policy " + err.Error())
	}
	switch res.StatusCode {
	case http.StatusOK:
	case http.StatusNotFound:
		log.Error(ctx, map[string]interface{}{
			"client_id": clientID,
			"policy_id": policyID,
		}, "Keycloak policy is not found")
		return nil, errors.NewNotFoundError("policy", policyID)
	default:
		log.Error(ctx, map[string]interface{}{
			"client_id":       clientID,
			"policy_id":       policyID,
			"response_status": res.Status,
			"response_body":   rest.ReadBody(res.Body),
		}, "Unable to obtain a Keycloak policy")
		return nil, errors.NewInternalError("Unable to obtain a Keycloak policy. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}
	jsonString := rest.ReadBody(res.Body)
	var r KeycloakPolicy
	err = json.Unmarshal([]byte(jsonString), &r)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"client_id":   clientID,
			"policy_id":   policyID,
			"json_string": jsonString,
		}, "Unable to unmarshal json with the get keycloak policy request result")
		return nil, errors.NewInternalError(fmt.Sprintf("error when unmarshal json with get the keycloak policy request result %s ", jsonString) + err.Error())
	}
	return &r, nil
}
func GetPolicy ( ctx context . Context , clientsEndpoint string , clientID string , policyID string , protectionAPIToken string ) ( * KeycloakPolicy , error ) { req , err := http . NewRequest ( " " , clientsEndpoint + " " + clientID + " " + policyID , nil ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : err . Error ( ) , } , " " ) return nil , errors . NewInternalError ( " " + err . Error ( ) ) } req . Header . Add ( " " , " " + protectionAPIToken ) res , err := http . DefaultClient . Do ( req ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : clientID , " " : policyID , " " : err . Error ( ) , } , " " ) return nil , errors . NewInternalError ( " " + err . Error ( ) ) } switch res . StatusCode { case http . StatusOK : case http . StatusNotFound : log . Error ( ctx , map [ string ] interface { } { " " : clientID , " " : policyID , } , " " ) return nil , errors . NewNotFoundError ( " " , policyID ) default : log . Error ( ctx , map [ string ] interface { } { " " : clientID , " " : policyID , " " : res . Status , " " : rest . ReadBody ( res . Body ) , } , " " ) return nil , errors . NewInternalError ( " " + res . Status + " " + rest . ReadBody ( res . Body ) ) } jsonString := rest . ReadBody ( res . Body ) var r KeycloakPolicy err = json . Unmarshal ( [ ] byte ( jsonString ) , & r ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : clientID , " " : policyID , " " : jsonString , } , " " ) return nil , errors . NewInternalError ( fmt . Sprintf ( " " , jsonString ) + err . Error ( ) ) } return & r , nil }
GetPolicy obtains a policy from Keycloak
GetPolicy obtains a policy from Keycloak
// OK