func GetEntitlement(ctx context.Context, entitlementEndpoint string, entitlementResource EntitlementResource, userAccesToken string) (string, error) {
	b, err := json.Marshal(entitlementResource)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"entitlement_resource": entitlementResource,
			"err": err.Error(),
		}, "Unable to marshal keyclaok entitlement resource struct")
		return "", errors.NewInternalError("Unable to marshal keyclaok entitlement resource struct " + err.Error())
	}

	req, err := http.NewRequest("POST", entitlementEndpoint, strings.NewReader(string(b)))
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err.Error(),
		}, "Unable to crete http request")
		return "", errors.NewInternalError("unable to crete http request " + err.Error())
	}
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", "Bearer "+userAccesToken)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"entitlement_resource": entitlementResource,
			"err": err.Error(),
		}, "Unable to obtain entitlement resource")
		return "", errors.NewInternalError("unable to obtain entitlement resource " + err.Error())
	}
	switch res.StatusCode {
	case http.StatusOK:
		// OK
	case http.StatusForbidden:
		return "", errors.NewUnauthorizedError("not authorized")
	default:
		log.Error(ctx, map[string]interface{}{
			"entitlement_resource": entitlementResource,
			"response_status":      res.Status,
			"response_body":        rest.ReadBody(res.Body),
		}, "Unable to update the Keycloak permission")
		return "", errors.NewInternalError("unable to obtain entitlement resource. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}
	jsonString := rest.ReadBody(res.Body)

	var r entitlementResult
	err = json.Unmarshal([]byte(jsonString), &r)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"entitlement_resource": entitlementResource,
			"json_string":          jsonString,
		}, "Unable to unmarshal json with the obtain entitlement request result")
		return "", errors.NewInternalError(fmt.Sprintf("error when unmarshal json with the obtain entitlement request result %s ", jsonString) + err.Error())
	}

	return r.Rpt, nil
}
// GetEntitlement obtains Entitlement for specific resource
GetEntitlement obtains Entitlement for specific resource
// GetEntitlement obtains Entitlement for specific resource
func GetEntitlement(ctx context.Context, entitlementEndpoint string, entitlementResource EntitlementResource, userAccesToken string) (string, error) {
	b, err := json.Marshal(entitlementResource)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"entitlement_resource": entitlementResource,
			"err": err.Error(),
		}, "Unable to marshal keyclaok entitlement resource struct")
		return "", errors.NewInternalError("Unable to marshal keyclaok entitlement resource struct " + err.Error())
	}
	req, err := http.NewRequest("POST", entitlementEndpoint, strings.NewReader(string(b)))
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err.Error(),
		}, "Unable to crete http request")
		return "", errors.NewInternalError("unable to crete http request " + err.Error())
	}
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", "Bearer "+userAccesToken)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"entitlement_resource": entitlementResource,
			"err": err.Error(),
		}, "Unable to obtain entitlement resource")
		return "", errors.NewInternalError("unable to obtain entitlement resource " + err.Error())
	}
	switch res.StatusCode {
	case http.StatusOK:
	case http.StatusForbidden:
		return "", errors.NewUnauthorizedError("not authorized")
	default:
		log.Error(ctx, map[string]interface{}{
			"entitlement_resource": entitlementResource,
			"response_status":      res.Status,
			"response_body":        rest.ReadBody(res.Body),
		}, "Unable to update the Keycloak permission")
		return "", errors.NewInternalError("unable to obtain entitlement resource. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}
	jsonString := rest.ReadBody(res.Body)
	var r entitlementResult
	err = json.Unmarshal([]byte(jsonString), &r)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"entitlement_resource": entitlementResource,
			"json_string":          jsonString,
		}, "Unable to unmarshal json with the obtain entitlement request result")
		return "", errors.NewInternalError(fmt.Sprintf("error when unmarshal json with the obtain entitlement request result %s ", jsonString) + err.Error())
	}
	return r.Rpt, nil
}
func GetEntitlement ( ctx context . Context , entitlementEndpoint string , entitlementResource EntitlementResource , userAccesToken string ) ( string , error ) { b , err := json . Marshal ( entitlementResource ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : entitlementResource , " " : err . Error ( ) , } , " " ) return " " , errors . NewInternalError ( " " + err . Error ( ) ) } req , err := http . NewRequest ( " " , entitlementEndpoint , strings . NewReader ( string ( b ) ) ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : err . Error ( ) , } , " " ) return " " , errors . NewInternalError ( " " + err . Error ( ) ) } req . Header . Add ( " " , " " ) req . Header . Add ( " " , " " + userAccesToken ) res , err := http . DefaultClient . Do ( req ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : entitlementResource , " " : err . Error ( ) , } , " " ) return " " , errors . NewInternalError ( " " + err . Error ( ) ) } switch res . StatusCode { case http . StatusOK : case http . StatusForbidden : return " " , errors . NewUnauthorizedError ( " " ) default : log . Error ( ctx , map [ string ] interface { } { " " : entitlementResource , " " : res . Status , " " : rest . ReadBody ( res . Body ) , } , " " ) return " " , errors . NewInternalError ( " " + res . Status + " " + rest . ReadBody ( res . Body ) ) } jsonString := rest . ReadBody ( res . Body ) var r entitlementResult err = json . Unmarshal ( [ ] byte ( jsonString ) , & r ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : entitlementResource , " " : jsonString , } , " " ) return " " , errors . NewInternalError ( fmt . Sprintf ( " " , jsonString ) + err . Error ( ) ) } return r . Rpt , nil }
GetEntitlement obtains Entitlement for specific resource
GetEntitlement obtains Entitlement for specific resource
// OK