Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions pkg/clientset/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const homeAccountIDParts = 2
var (
errNotAuthenticatedPreHook = errors.New("you need to sign in before executing this operation")
errInvalidHomeAccountID = errors.New("invalid HomeAccountID format")
errFeatureNotAvailable = errors.New("this feature is not available for your tenant")
)

type Authenticator interface {
Expand Down Expand Up @@ -109,32 +108,6 @@ func fqcn(cmd *cobra.Command) string {
return name
}

// EnsureAITenantPreHook is a pre-run hook that checks if the current tenant
// has access to AI features. It composes EnsureSignedIn so auth is checked first.
func (c *ClientSet) EnsureAITenantPreHook(cmd *cobra.Command, args []string) error {
return c.PreHooks(c.EnsureSignedIn, c.ensureAITenant)(cmd, args)
}

func (c *ClientSet) ensureAITenant(cmd *cobra.Command, _ []string) error {
allowedTenants := map[string]bool{
"9b5ff18e-53c0-45a2-8bc2-9c0c8f60b2c6": true, // intility
"f0a51c83-6cc9-4830-9d01-d4d18c068e32": true, // skoglab
}

tenantID, err := c.GetTenantID(cmd.Context())
if err != nil {
return fmt.Errorf("could not determine tenant: %w", err)
}

if !allowedTenants[tenantID] {
cmd.SilenceUsage = true

return errFeatureNotAvailable
}

return nil
}

// GetTenantID extracts the tenant ID from the current account's HomeAccountID.
// The HomeAccountID format is "<oid>.<tid>" where tid is the tenant ID.
func (c *ClientSet) GetTenantID(ctx context.Context) (string, error) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/rootcommand/rootcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ func getAICommand(set clientset.ClientSet) *cobra.Command {
Use: "ai",
Short: "Manage Intility Developer Platform AI Deployments",
Long: "Manage Intility Developer Platform AI Deployments",
Hidden: true,
PersistentPreRunE: set.EnsureAITenantPreHook,
PersistentPreRunE: set.EnsureSignedInPreHook,
Run: showHelp,
}

Expand Down