daf4d4b94b
draft pr for the test demo harness for permit.io * harness working for permit.io demo * user is const * aws profile * permit import code for research * cleanup * create user tool poc * Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/permit-io-demo * tests for user creation * add audit logs and dry-run * add tests sanity check the requested roles * update docs for delete * disable/enable users and test * more tests and make user name required only for create operations * clean up * add docs * aws tag tests * audit -> slog * attempt build fix devbox * edit * just devbox * remove lock change for merge * Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/permit-io-demo
115 lines
2.7 KiB
Go
115 lines
2.7 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"github.com/permitio/permit-golang/pkg/config"
|
|
"github.com/permitio/permit-golang/pkg/errors"
|
|
"github.com/permitio/permit-golang/pkg/models"
|
|
"github.com/permitio/permit-golang/pkg/openapi"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type ImplicitGrants struct {
|
|
permitBaseApi
|
|
}
|
|
|
|
func NewImplicitGrantsApi(client *openapi.APIClient, config *config.PermitConfig) *ImplicitGrants {
|
|
return &ImplicitGrants{
|
|
permitBaseApi{
|
|
client: client,
|
|
config: config,
|
|
logger: config.Logger,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (r *ImplicitGrants) Create(
|
|
ctx context.Context,
|
|
resourceId string,
|
|
roleId string,
|
|
derivedRuleCreate models.DerivedRoleRuleCreate,
|
|
) (*models.DerivedRoleRuleRead, error) {
|
|
err := r.lazyLoadPermitContext(ctx)
|
|
|
|
if err != nil {
|
|
r.logger.Error("", zap.Error(err))
|
|
return nil, err
|
|
}
|
|
|
|
derivedRoleRead, httpRes, err := r.client.ImplicitGrantsApi.CreateImplicitGrant(ctx,
|
|
r.config.Context.GetProject(),
|
|
r.config.Context.GetEnvironment(),
|
|
resourceId,
|
|
roleId,
|
|
).DerivedRoleRuleCreate(derivedRuleCreate).Execute()
|
|
|
|
err = errors.HttpErrorHandle(err, httpRes)
|
|
|
|
if err != nil {
|
|
r.logger.Error("error creating derived role", zap.Error(err))
|
|
return nil, err
|
|
}
|
|
|
|
return derivedRoleRead, nil
|
|
}
|
|
|
|
func (r *ImplicitGrants) Delete(
|
|
ctx context.Context,
|
|
roleId string,
|
|
resourceId string,
|
|
derivedRoleRuleDelete models.DerivedRoleRuleDelete,
|
|
) error {
|
|
err := r.lazyLoadPermitContext(ctx)
|
|
|
|
if err != nil {
|
|
r.logger.Error("", zap.Error(err))
|
|
return err
|
|
}
|
|
|
|
httpRes, err := r.client.ImplicitGrantsApi.DeleteImplicitGrant(ctx,
|
|
r.config.Context.GetProject(),
|
|
r.config.Context.GetEnvironment(),
|
|
resourceId,
|
|
roleId,
|
|
).DerivedRoleRuleDelete(derivedRoleRuleDelete).Execute()
|
|
|
|
err = errors.HttpErrorHandle(err, httpRes)
|
|
|
|
if err != nil {
|
|
r.logger.Error("error deleting derived role", zap.Error(err))
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (r *ImplicitGrants) UpdateConditions(
|
|
ctx context.Context,
|
|
resourceId string,
|
|
roleId string,
|
|
roleDerivationSettings models.PermitBackendSchemasSchemaDerivedRoleRuleDerivationSettings,
|
|
) (*models.PermitBackendSchemasSchemaDerivedRoleRuleDerivationSettings, error) {
|
|
err := r.lazyLoadPermitContext(ctx)
|
|
|
|
if err != nil {
|
|
r.logger.Error("", zap.Error(err))
|
|
return nil, err
|
|
}
|
|
|
|
updatedSettings, httpRes, err := r.client.ImplicitGrantsApi.UpdateImplicitGrantsConditions(ctx,
|
|
r.config.Context.GetProject(),
|
|
r.config.Context.GetEnvironment(),
|
|
resourceId,
|
|
roleId,
|
|
).PermitBackendSchemasSchemaDerivedRoleRuleDerivationSettings(roleDerivationSettings).Execute()
|
|
|
|
err = errors.HttpErrorHandle(err, httpRes)
|
|
|
|
if err != nil {
|
|
r.logger.Error("error updating derived role", zap.Error(err))
|
|
return nil, err
|
|
}
|
|
|
|
return updatedSettings, nil
|
|
}
|