snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
183
server/system/rest/auth_client.go
Normal file
183
server/system/rest/auth_client.go
Normal file
@@ -0,0 +1,183 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/api"
|
||||
"github.com/cortezaproject/corteza/server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza/server/pkg/options"
|
||||
"github.com/cortezaproject/corteza/server/system/rest/request"
|
||||
"github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
AuthClient struct {
|
||||
authClient authClientService
|
||||
ac authClientAccessController
|
||||
opt options.AuthOpt
|
||||
}
|
||||
|
||||
authClientService interface {
|
||||
LookupByID(ctx context.Context, ID uint64) (app *types.AuthClient, err error)
|
||||
Search(ctx context.Context, filter types.AuthClientFilter) (aa types.AuthClientSet, f types.AuthClientFilter, err error)
|
||||
Create(ctx context.Context, new *types.AuthClient) (app *types.AuthClient, err error)
|
||||
Update(ctx context.Context, upd *types.AuthClient) (app *types.AuthClient, err error)
|
||||
Delete(ctx context.Context, ID uint64) (err error)
|
||||
Undelete(ctx context.Context, ID uint64) (err error)
|
||||
ExposeSecret(ctx context.Context, ID uint64) (secret string, err error)
|
||||
RegenerateSecret(ctx context.Context, ID uint64) (secret string, err error)
|
||||
IsDefaultClient(c *types.AuthClient) bool
|
||||
}
|
||||
|
||||
authClientAccessController interface {
|
||||
CanGrant(context.Context) bool
|
||||
|
||||
CanUpdateAuthClient(context.Context, *types.AuthClient) bool
|
||||
CanDeleteAuthClient(context.Context, *types.AuthClient) bool
|
||||
}
|
||||
|
||||
authClientPayload struct {
|
||||
*types.AuthClient
|
||||
|
||||
IsDefault bool `json:"isDefault"`
|
||||
|
||||
CanGrant bool `json:"canGrant"`
|
||||
CanUpdateAuthClient bool `json:"canUpdateAuthClient"`
|
||||
CanDeleteAuthClient bool `json:"canDeleteAuthClient"`
|
||||
}
|
||||
|
||||
authClientSetPayload struct {
|
||||
Filter types.AuthClientFilter `json:"filter"`
|
||||
Set []*authClientPayload `json:"set"`
|
||||
}
|
||||
)
|
||||
|
||||
func (AuthClient) New() *AuthClient {
|
||||
return &AuthClient{
|
||||
authClient: service.DefaultAuthClient,
|
||||
ac: service.DefaultAccessControl,
|
||||
}
|
||||
}
|
||||
|
||||
func (ctrl *AuthClient) List(ctx context.Context, r *request.AuthClientList) (interface{}, error) {
|
||||
var (
|
||||
err error
|
||||
f = types.AuthClientFilter{
|
||||
Handle: r.Handle,
|
||||
Labels: r.Labels,
|
||||
Deleted: filter.State(r.Deleted),
|
||||
}
|
||||
)
|
||||
|
||||
if f.Paging, err = filter.NewPaging(r.Limit, r.PageCursor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.IncTotal = r.IncTotal
|
||||
|
||||
if f.Sorting, err = filter.NewSorting(r.Sort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
set, filter, err := ctrl.authClient.Search(ctx, f)
|
||||
return ctrl.makeFilterPayload(ctx, set, filter, err)
|
||||
}
|
||||
|
||||
func (ctrl *AuthClient) Create(ctx context.Context, r *request.AuthClientCreate) (interface{}, error) {
|
||||
var (
|
||||
err error
|
||||
app = &types.AuthClient{
|
||||
Handle: r.Handle,
|
||||
Meta: r.Meta,
|
||||
ValidGrant: r.ValidGrant,
|
||||
RedirectURI: r.RedirectURI,
|
||||
Scope: r.Scope,
|
||||
Trusted: r.Trusted,
|
||||
Enabled: r.Enabled,
|
||||
ValidFrom: r.ValidFrom,
|
||||
ExpiresAt: r.ExpiresAt,
|
||||
Security: r.Security,
|
||||
Labels: r.Labels,
|
||||
}
|
||||
)
|
||||
|
||||
app, err = ctrl.authClient.Create(ctx, app)
|
||||
return ctrl.makePayload(ctx, app, err)
|
||||
}
|
||||
|
||||
func (ctrl *AuthClient) Update(ctx context.Context, r *request.AuthClientUpdate) (interface{}, error) {
|
||||
var (
|
||||
err error
|
||||
app = &types.AuthClient{
|
||||
ID: r.ClientID,
|
||||
Handle: r.Handle,
|
||||
Meta: r.Meta,
|
||||
ValidGrant: r.ValidGrant,
|
||||
RedirectURI: r.RedirectURI,
|
||||
Scope: r.Scope,
|
||||
Trusted: r.Trusted,
|
||||
Enabled: r.Enabled,
|
||||
ValidFrom: r.ValidFrom,
|
||||
ExpiresAt: r.ExpiresAt,
|
||||
Security: r.Security,
|
||||
Labels: r.Labels,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
}
|
||||
)
|
||||
|
||||
app, err = ctrl.authClient.Update(ctx, app)
|
||||
return ctrl.makePayload(ctx, app, err)
|
||||
}
|
||||
|
||||
func (ctrl *AuthClient) Read(ctx context.Context, r *request.AuthClientRead) (interface{}, error) {
|
||||
app, err := ctrl.authClient.LookupByID(ctx, r.ClientID)
|
||||
return ctrl.makePayload(ctx, app, err)
|
||||
}
|
||||
|
||||
func (ctrl *AuthClient) ExposeSecret(ctx context.Context, r *request.AuthClientExposeSecret) (interface{}, error) {
|
||||
return ctrl.authClient.ExposeSecret(ctx, r.ClientID)
|
||||
}
|
||||
|
||||
func (ctrl *AuthClient) RegenerateSecret(ctx context.Context, r *request.AuthClientRegenerateSecret) (interface{}, error) {
|
||||
return ctrl.authClient.RegenerateSecret(ctx, r.ClientID)
|
||||
}
|
||||
|
||||
func (ctrl *AuthClient) Delete(ctx context.Context, r *request.AuthClientDelete) (interface{}, error) {
|
||||
return api.OK(), ctrl.authClient.Delete(ctx, r.ClientID)
|
||||
}
|
||||
|
||||
func (ctrl *AuthClient) Undelete(ctx context.Context, r *request.AuthClientUndelete) (interface{}, error) {
|
||||
return api.OK(), ctrl.authClient.Undelete(ctx, r.ClientID)
|
||||
}
|
||||
|
||||
func (ctrl AuthClient) makePayload(ctx context.Context, m *types.AuthClient, err error) (*authClientPayload, error) {
|
||||
if err != nil || m == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &authClientPayload{
|
||||
AuthClient: m,
|
||||
|
||||
IsDefault: ctrl.authClient.IsDefaultClient(m),
|
||||
|
||||
CanGrant: ctrl.ac.CanGrant(ctx),
|
||||
|
||||
CanUpdateAuthClient: ctrl.ac.CanUpdateAuthClient(ctx, m),
|
||||
CanDeleteAuthClient: ctrl.ac.CanDeleteAuthClient(ctx, m),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (ctrl AuthClient) makeFilterPayload(ctx context.Context, nn types.AuthClientSet, f types.AuthClientFilter, err error) (*authClientSetPayload, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
msp := &authClientSetPayload{Filter: f, Set: make([]*authClientPayload, len(nn))}
|
||||
|
||||
for i := range nn {
|
||||
msp.Set[i], _ = ctrl.makePayload(ctx, nn[i], nil)
|
||||
}
|
||||
|
||||
return msp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user