Skip to content

Commit 7a22ca4

Browse files
committed
chore: add feature gate
1 parent f74e7f6 commit 7a22ca4

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

pkg/clientset/clientset.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const homeAccountIDParts = 2
2121
var (
2222
errNotAuthenticatedPreHook = errors.New("you need to sign in before executing this operation")
2323
errInvalidHomeAccountID = errors.New("invalid HomeAccountID format")
24+
errFeatureNotAvailable = errors.New("this feature is not available for your tenant")
2425
)
2526

2627
type Authenticator interface {
@@ -108,6 +109,32 @@ func fqcn(cmd *cobra.Command) string {
108109
return name
109110
}
110111

112+
// EnsureAITenantPreHook is a pre-run hook that checks if the current tenant
113+
// has access to AI features. It composes EnsureSignedIn so auth is checked first.
114+
func (c *ClientSet) EnsureAITenantPreHook(cmd *cobra.Command, args []string) error {
115+
return c.PreHooks(c.EnsureSignedIn, c.ensureAITenant)(cmd, args)
116+
}
117+
118+
func (c *ClientSet) ensureAITenant(cmd *cobra.Command, _ []string) error {
119+
allowedTenants := map[string]bool{
120+
"9b5ff18e-53c0-45a2-8bc2-9c0c8f60b2c6": true, // intility
121+
"f0a51c83-6cc9-4830-9d01-d4d18c068e32": true, // skoglab
122+
}
123+
124+
tenantID, err := c.GetTenantID(cmd.Context())
125+
if err != nil {
126+
return fmt.Errorf("could not determine tenant: %w", err)
127+
}
128+
129+
if !allowedTenants[tenantID] {
130+
cmd.SilenceUsage = true
131+
132+
return errFeatureNotAvailable
133+
}
134+
135+
return nil
136+
}
137+
111138
// GetTenantID extracts the tenant ID from the current account's HomeAccountID.
112139
// The HomeAccountID format is "<oid>.<tid>" where tid is the tenant ID.
113140
func (c *ClientSet) GetTenantID(ctx context.Context) (string, error) {

pkg/rootcommand/rootcommand.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ func getUserCommand(set clientset.ClientSet) *cobra.Command {
155155

156156
func getAICommand(set clientset.ClientSet) *cobra.Command {
157157
cmd := &cobra.Command{
158-
Use: "ai",
159-
Short: "Manage Intility Developer Platform AI Deployments",
160-
Long: "Manage Intility Developer Platform AI Deployments",
161-
Run: showHelp,
158+
Use: "ai",
159+
Short: "Manage Intility Developer Platform AI Deployments",
160+
Long: "Manage Intility Developer Platform AI Deployments",
161+
Hidden: true,
162+
PersistentPreRunE: set.EnsureAITenantPreHook,
163+
Run: showHelp,
162164
}
163165

164166
cmd.AddCommand(getAIModelCommand(set))

0 commit comments

Comments
 (0)