@@ -21,6 +21,7 @@ const homeAccountIDParts = 2
2121var (
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
2627type 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.
113140func (c * ClientSet ) GetTenantID (ctx context.Context ) (string , error ) {
0 commit comments