1+ # --------------------------------------------------------------------------------------------
2+ # Copyright (c) Microsoft Corporation. All rights reserved.
3+ # Licensed under the MIT License. See License.txt in the project root for license information.
4+ # --------------------------------------------------------------------------------------------
5+ # pylint: disable=no-self-use, line-too-long, protected-access, too-few-public-methods, unused-argument
6+ from knack .log import get_logger
7+
8+ from azure .cli .core .aaz import register_command , AAZListArg , AAZStrArg
9+ from azure .cli .core .azclierror import CLIError
10+ from ..aaz .latest .sig .share import Update as _SigShareUpdate
11+ from ..aaz .latest .sig import Wait as _SigWait
12+
13+ logger = get_logger (__name__ )
14+
15+
16+ @register_command (
17+ "sig shared add" ,
18+ )
19+ class SigShareAdd (_SigShareUpdate ):
20+ """Share gallery with subscriptions and tenants.
21+
22+ :example: Share entire gallery with all members of a subscription and/or tenant.
23+ az sig share add --resource-group MyResourceGroup --gallery-name MyGallery \\
24+ --subscription-ids subId1 subId2 --tenant-ids tenantId1 tenantId2
25+ """
26+
27+ @classmethod
28+ def _build_arguments_schema (cls , * args , ** kwargs ):
29+ args_schema = super ()._build_arguments_schema (* args , ** kwargs )
30+ args_schema .subscription_ids = AAZListArg (
31+ options = ["--subscription-ids" ],
32+ help = "A list of subscription ids to share the gallery with." ,
33+ )
34+ subscription_ids = args_schema .subscription_ids
35+ subscription_ids .Element = AAZStrArg ()
36+
37+ args_schema .tenant_ids = AAZListArg (
38+ options = ["--tenant-ids" ],
39+ help = "A list of tenant ids to share the gallery with." ,
40+ )
41+ tenant_ids = args_schema .tenant_ids
42+ tenant_ids .Element = AAZStrArg ()
43+
44+ args_schema .operation_type ._required = False
45+ args_schema .operation_type ._registered = False
46+ args_schema .groups ._required = False
47+ args_schema .groups ._registered = False
48+
49+ return args_schema
50+
51+ def pre_operations (self ):
52+ args = self .ctx .args
53+ if not args .subscription_ids and not args .tenant_ids :
54+ raise CLIError ('At least one of subscription ids or tenant ids must be provided.' )
55+
56+ args .operation_type = 'Add'
57+ args .groups = []
58+ if args .subscription_ids :
59+ args .groups .append ({
60+ 'type' : 'Subscriptions' ,
61+ 'ids' : args .subscription_ids
62+ })
63+ if args .tenant_ids :
64+ args .groups .append ({
65+ 'type' : 'AADTenants' ,
66+ 'ids' : args .tenant_ids
67+ })
68+
69+
70+ @register_command (
71+ "sig shared remove" ,
72+ )
73+ class SigShareRemove (_SigShareUpdate ):
74+ """Stop sharing gallery with a subscription or tenant.
75+
76+ :example: Stop sharing with a subscription or tenant ID
77+ az sig share remove --resource-group MyResourceGroup --gallery-name MyGallery \\
78+ --subscription-ids subId1 subId2 --tenant-ids tenantId1 tenantId2
79+ """
80+
81+ @classmethod
82+ def _build_arguments_schema (cls , * args , ** kwargs ):
83+ args_schema = super ()._build_arguments_schema (* args , ** kwargs )
84+ args_schema .subscription_ids = AAZListArg (
85+ options = ["--subscription-ids" ],
86+ help = "A list of subscription ids to share the gallery with." ,
87+ )
88+ subscription_ids = args_schema .subscription_ids
89+ subscription_ids .Element = AAZStrArg ()
90+
91+ args_schema .tenant_ids = AAZListArg (
92+ options = ["--tenant-ids" ],
93+ help = "A list of tenant ids to share the gallery with." ,
94+ )
95+ tenant_ids = args_schema .tenant_ids
96+ tenant_ids .Element = AAZStrArg ()
97+
98+ args_schema .operation_type ._required = False
99+ args_schema .operation_type ._registered = False
100+ args_schema .groups ._required = False
101+ args_schema .groups ._registered = False
102+
103+ return args_schema
104+
105+ def pre_operations (self ):
106+ args = self .ctx .args
107+
108+ if not args .subscription_ids and not args .tenant_ids :
109+ raise CLIError ('At least one of subscription ids or tenant ids must be provided.' )
110+ args .operation_type = 'Remove'
111+ args .groups = []
112+ if args .subscription_ids :
113+ args .groups .append ({
114+ 'type' : 'Subscriptions' ,
115+ 'ids' : args .subscription_ids
116+ })
117+ if args .tenant_ids :
118+ args .groups .append ({
119+ 'type' : 'AADTenants' ,
120+ 'ids' : args .tenant_ids
121+ })
122+
123+
124+ @register_command (
125+ "sig shared reset" ,
126+ )
127+ class SigShareReset (_SigShareUpdate ):
128+ """Disable gallery from being shared with subscription or tenant.
129+
130+ :example: Reset sharing profile of a gallery.
131+ az sig share reset --resource-group MyResourceGroup --gallery-name MyGallery
132+ """
133+
134+ @classmethod
135+ def _build_arguments_schema (cls , * args , ** kwargs ):
136+ args_schema = super ()._build_arguments_schema (* args , ** kwargs )
137+ args_schema .operation_type ._required = False
138+ args_schema .operation_type ._registered = False
139+ args_schema .operation_type ._default = 'Reset'
140+ args_schema .groups ._required = False
141+ args_schema .groups ._registered = False
142+
143+ return args_schema
144+
145+
146+ @register_command (
147+ "sig shared enable-community"
148+ )
149+ class SigShareEnableCommunity (_SigShareUpdate ):
150+ """Allow to share gallery to the community.
151+
152+ :example: Allow to share gallery to the community
153+ az sig share enable-community --resource-group MyResourceGroup --gallery-name MyGallery
154+ """
155+
156+ @classmethod
157+ def _build_arguments_schema (cls , * args , ** kwargs ):
158+ args_schema = super ()._build_arguments_schema (* args , ** kwargs )
159+ args_schema .operation_type ._required = False
160+ args_schema .operation_type ._registered = False
161+ args_schema .operation_type ._default = 'EnableCommunity'
162+ args_schema .groups ._required = False
163+ args_schema .groups ._registered = False
164+
165+ return args_schema
166+
167+
168+ @register_command (
169+ "sig shared wait2"
170+ )
171+ class SigShareWait (_SigWait ):
172+ """Place the CLI in a waiting state until a condition of a shared gallery is met.
173+
174+ :example: Place the CLI in a waiting state until the gallery sharing object is updated.
175+ az sig share wait --updated --resource-group MyResourceGroup --gallery-name Gallery
176+ """
177+
178+ @classmethod
179+ def _build_arguments_schema (cls , * args , ** kwargs ):
180+ args_schema = super ()._build_arguments_schema (* args , ** kwargs )
181+ args_schema .gallery_name ._help ['short-summary' ] = 'Gallery name.'
182+ args_schema .expand ._registered = False
183+ args_schema .select ._registered = False
184+
185+ return args_schema
0 commit comments