func UpdatePolicy(ctx context.Context, clientsEndpoint string, clientID string, policy KeycloakPolicy, protectionAPIToken string) error {
	b, err := json.Marshal(policy)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"policy": policy,
			"err":    err.Error(),
		}, "Unable to marshal keyclaok policy struct")
		return errors.NewInternalError("unable to marshal keyclaok policy struct " + err.Error())
	}

	req, err := http.NewRequest("PUT", clientsEndpoint+"/"+clientID+"/authz/resource-server/policy/"+*policy.ID, 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 "+protectionAPIToken)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"client_id": clientID,
			"policy":    policy,
			"err":       err.Error(),
		}, "Unable to update the Keycloak policy")
		return errors.NewInternalError("unable to update the Keycloak policy " + err.Error())
	}
	if res.StatusCode != http.StatusCreated {
		log.Error(ctx, map[string]interface{}{
			"client_id":       clientID,
			"policy":          policy,
			"response_status": res.Status,
			"response_body":   rest.ReadBody(res.Body),
		}, "Unable to update the Keycloak policy")
		return errors.NewInternalError("unable to update the Keycloak policy. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}

	return nil
}
// UpdatePolicy updates the Keycloak policy
UpdatePolicy updates the Keycloak policy
// UpdatePolicy updates the Keycloak policy
func UpdatePolicy(ctx context.Context, clientsEndpoint string, clientID string, policy KeycloakPolicy, protectionAPIToken string) error {
	b, err := json.Marshal(policy)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"policy": policy,
			"err":    err.Error(),
		}, "Unable to marshal keyclaok policy struct")
		return errors.NewInternalError("unable to marshal keyclaok policy struct " + err.Error())
	}
	req, err := http.NewRequest("PUT", clientsEndpoint+"/"+clientID+"/authz/resource-server/policy/"+*policy.ID, 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 "+protectionAPIToken)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"client_id": clientID,
			"policy":    policy,
			"err":       err.Error(),
		}, "Unable to update the Keycloak policy")
		return errors.NewInternalError("unable to update the Keycloak policy " + err.Error())
	}
	if res.StatusCode != http.StatusCreated {
		log.Error(ctx, map[string]interface{}{
			"client_id":       clientID,
			"policy":          policy,
			"response_status": res.Status,
			"response_body":   rest.ReadBody(res.Body),
		}, "Unable to update the Keycloak policy")
		return errors.NewInternalError("unable to update the Keycloak policy. Response status: " + res.Status + ". Responce body: " + rest.ReadBody(res.Body))
	}
	return nil
}
func UpdatePolicy ( ctx context . Context , clientsEndpoint string , clientID string , policy KeycloakPolicy , protectionAPIToken string ) error { b , err := json . Marshal ( policy ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : policy , " " : err . Error ( ) , } , " " ) return errors . NewInternalError ( " " + err . Error ( ) ) } req , err := http . NewRequest ( " " , clientsEndpoint + " " + clientID + " " + * policy . ID , 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 ( " " , " " + protectionAPIToken ) res , err := http . DefaultClient . Do ( req ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : clientID , " " : policy , " " : err . Error ( ) , } , " " ) return errors . NewInternalError ( " " + err . Error ( ) ) } if res . StatusCode != http . StatusCreated { log . Error ( ctx , map [ string ] interface { } { " " : clientID , " " : policy , " " : res . Status , " " : rest . ReadBody ( res . Body ) , } , " " ) return errors . NewInternalError ( " " + res . Status + " " + rest . ReadBody ( res . Body ) ) } return nil }
UpdatePolicy updates the Keycloak policy
UpdatePolicy updates the Keycloak policy