Files
zitadel/backend/v3/domain/instance_get.go
T
b339a3e696 feat: instance domain APIs with relational tables (#11051)
# Which Problems Are Solved

This PR implements the endpoints listed in
https://github.com/zitadel/zitadel/issues/10444 .

# How the Problems Are Solved

The implementation follows the same pattern as the Instance one. The
`Add` and `Remove` are implementing the `Commander` interface, while
`List` Domains endpoints are implementing the `Querier` interace.

The PR adds also some forgotten calls to the relational logic for the
Instance API. The commits are identifiable by the label `instance:`
prepended to them. This is the complete list: bafce01b0 , 6fe7257ab ,
e27bc9c34 , 8133ede73 , fde667953 , a3e1135ed , ee1a6f9c1

# Additional Context

- Closes #10444

---------

Co-authored-by: Elio Bischof <[email protected]>
Co-authored-by: Lebogang Phoshoko <[email protected]>
Co-authored-by: Wim Van Laer <[email protected]>
Co-authored-by: Max Peintner <[email protected]>
Co-authored-by: Gayathri Vijayan <[email protected]>
2025-12-17 12:01:09 +01:00

66 lines
1.8 KiB
Go

package domain
import (
"context"
"errors"
"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 {
if errors.Is(err, &database.NoRowFoundError{}) {
return zerrors.ThrowNotFound(err, "DOM-QVrUwc", "Errors.Instance.NotFound")
}
return zerrors.ThrowInternal(err, "DOM-lvsRce", "Errors.Instance.Get")
}
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", "Errors.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", "Errors.PermissionDenied")
}
return nil
}
var _ Querier[*Instance] = (*GetInstanceQuery)(nil)