mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-22 23:42:16 +00:00
# Which Problems Are Solved This PR implements the endpoints listed in https://github.com/zitadel/zitadel/issues/10443 . # How the Problems Are Solved The implementation follows the same pattern as the Organization one. There are no peculiarities to this PR. The `Update`, `Delete` are implementing the `Commander` interface, while `Get` and `List` instance(s) endpoints are implementing the `Querier` interace. # Additional Context - Closes #10443 - Depends on #10445
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package domain
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
type GetInstanceQuery struct {
|
|
ID string `json:"id"`
|
|
returnedInstance *Instance
|
|
}
|
|
|
|
// Result implements [Querier].
|
|
func (g *GetInstanceQuery) Result() *Instance {
|
|
return g.returnedInstance
|
|
}
|
|
|
|
func NewGetInstanceCommand(instanceID string) *GetInstanceQuery {
|
|
return &GetInstanceQuery{ID: instanceID}
|
|
}
|
|
|
|
// Execute implements [Executor].
|
|
func (g *GetInstanceQuery) Execute(ctx context.Context, opts *InvokeOpts) (err error) {
|
|
instanceRepo := opts.instanceRepo.LoadDomains()
|
|
|
|
instance, err := instanceRepo.Get(ctx, opts.DB(), database.WithCondition(instanceRepo.IDCondition(g.ID)))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
g.returnedInstance = instance
|
|
return nil
|
|
}
|
|
|
|
// String implements [Executor].
|
|
func (g *GetInstanceQuery) String() string {
|
|
return "GetInstanceCommand"
|
|
}
|
|
|
|
// Validate implements [Validator].
|
|
func (g *GetInstanceQuery) Validate(ctx context.Context, opts *InvokeOpts) (err error) {
|
|
g.ID = strings.TrimSpace(g.ID)
|
|
if g.ID == "" {
|
|
return zerrors.ThrowInvalidArgument(nil, "DOM-32a0o2", "invalid instance ID")
|
|
}
|
|
if g.ID != authz.GetInstance(ctx).InstanceID() {
|
|
return zerrors.ThrowPermissionDenied(nil, "DOM-n0SvVB", "input instance ID doesn't match context instance")
|
|
}
|
|
|
|
if authZErr := opts.Permissions.CheckInstancePermission(ctx, InstanceReadPermission); authZErr != nil {
|
|
return zerrors.ThrowPermissionDenied(authZErr, "DOM-Uq6b00", "permission denied")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var _ Querier[*Instance] = (*GetInstanceQuery)(nil)
|