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
46 lines
1.3 KiB
Go
46 lines
1.3 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 Elements struct {
|
|
permitBaseApi
|
|
}
|
|
|
|
func NewElementsApi(client *openapi.APIClient, config *config.PermitConfig) *Elements {
|
|
return &Elements{
|
|
permitBaseApi{
|
|
client: client,
|
|
config: config,
|
|
logger: config.Logger,
|
|
},
|
|
}
|
|
}
|
|
|
|
// LoginAs login as a given user.
|
|
// Usage Example:
|
|
// ```
|
|
// userLogin := models.NewUserLoginRequestInput("user-id", "tenant-id")
|
|
// embeddedLoginRequestOutput, err := PermitClient.Api.Elements.LoginAs(ctx, userLogin)
|
|
// ```
|
|
func (e *Elements) LoginAs(ctx context.Context, userLogin models.UserLoginRequestInput) (*models.EmbeddedLoginRequestOutput, error) {
|
|
err := e.lazyLoadPermitContext(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
embeddedLoginRequestOutput, httpRes, err := e.client.AuthenticationApi.ElementsLoginAs(ctx).UserLoginRequestInput(userLogin).Execute()
|
|
err = errors.HttpErrorHandle(err, httpRes)
|
|
if err != nil {
|
|
e.logger.Error("error login as: "+userLogin.GetUserId()+"in tenant: "+userLogin.GetTenantId(), zap.Error(err))
|
|
return nil, err
|
|
}
|
|
return embeddedLoginRequestOutput, nil
|
|
|
|
}
|