Skip to content

Commit caedeb4

Browse files
committed
Add Contract and License to New/Set Api cmdlets
1 parent 2930582 commit caedeb4

File tree

6 files changed

+246
-9
lines changed

6 files changed

+246
-9
lines changed

src/ApiManagement/ApiManagement.ServiceManagement/ApiManagementClient.cs

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,36 @@ private static void ConfigureMappings()
164164
src => src.AuthenticationSettings != null && src.AuthenticationSettings.Openid != null && src.AuthenticationSettings.Openid.BearerTokenSendingMethods != null &&
165165
src.AuthenticationSettings.Openid.BearerTokenSendingMethods.Any()
166166
? src.AuthenticationSettings.Openid.BearerTokenSendingMethods.ToArray()
167+
: null))
168+
.ForMember(
169+
dest => dest.ContactEmail,
170+
opt => opt.MapFrom(
171+
src => src.Contact != null
172+
? src.Contact.Email
173+
: null))
174+
.ForMember(
175+
dest => dest.ContactName,
176+
opt => opt.MapFrom(
177+
src => src.Contact != null
178+
? src.Contact.Name
179+
: null))
180+
.ForMember(
181+
dest => dest.ContactUrl,
182+
opt => opt.MapFrom(
183+
src => src.Contact != null
184+
? src.Contact.Url
185+
: null))
186+
.ForMember(
187+
dest => dest.LicenseName,
188+
opt => opt.MapFrom(
189+
src => src.License != null
190+
? src.License.Name
191+
: null))
192+
.ForMember(
193+
dest => dest.LicenseUrl,
194+
opt => opt.MapFrom(
195+
src => src.License != null
196+
? src.License.Url
167197
: null));
168198

169199
cfg
@@ -184,7 +214,11 @@ private static void ConfigureMappings()
184214
.AfterMap((src, dest) =>
185215
dest.AuthenticationSettings = Utils.ToAuthenticationSettings(src))
186216
.AfterMap((src, dest) =>
187-
dest.SubscriptionKeyParameterNames = Utils.ToSubscriptionKeyParameterNamesContract(src));
217+
dest.SubscriptionKeyParameterNames = Utils.ToSubscriptionKeyParameterNamesContract(src))
218+
.AfterMap((src, dest) =>
219+
dest.Contact = Utils.ToContactInformation(src))
220+
.AfterMap((src, dest) =>
221+
dest.License = Utils.ToLicenseInformation(src));
188222

189223
cfg
190224
.CreateMap<PsApiManagementApi, ApiCreateOrUpdateParameter>()
@@ -202,7 +236,11 @@ private static void ConfigureMappings()
202236
.AfterMap((src, dest) =>
203237
dest.AuthenticationSettings = Utils.ToAuthenticationSettings(src))
204238
.AfterMap((src, dest) =>
205-
dest.SubscriptionKeyParameterNames = Utils.ToSubscriptionKeyParameterNamesContract(src));
239+
dest.SubscriptionKeyParameterNames = Utils.ToSubscriptionKeyParameterNamesContract(src))
240+
.AfterMap((src, dest) =>
241+
dest.Contact = Utils.ToContactInformation(src))
242+
.AfterMap((src, dest) =>
243+
dest.License = Utils.ToLicenseInformation(src));
206244

207245
cfg.CreateMap<ApiContract, ApiCreateOrUpdateParameter>();
208246

@@ -798,7 +836,13 @@ public PsApiManagementApi ApiCreate(
798836
string subscriptionKeyHeaderName,
799837
string subscriptionKeyQueryParamName,
800838
string openIdProviderId,
801-
string[] bearerTokenSendingMethods)
839+
string[] bearerTokenSendingMethods,
840+
string termsOfServiceUrl,
841+
string contactName,
842+
string contactUrl,
843+
string contactEmail,
844+
string licenseName,
845+
string licenseUrl)
802846
{
803847
var api = new ApiCreateOrUpdateParameter
804848
{
@@ -904,7 +948,14 @@ public PsApiManagementApi ApiSet(
904948
string subscriptionKeyQueryParamName,
905949
string openIdProviderId,
906950
string[] bearerTokenSendingMethods,
907-
PsApiManagementApi apiObject)
951+
PsApiManagementApi apiObject,
952+
string apiType,
953+
string termsOfServiceUrl,
954+
string contactName,
955+
string contactUrl,
956+
string contactEmail,
957+
string licenseName,
958+
string licenseUrl)
908959
{
909960
ApiCreateOrUpdateParameter api;
910961
if (apiObject == null)
@@ -989,6 +1040,30 @@ public PsApiManagementApi ApiSet(
9891040
};
9901041
}
9911042

1043+
if (!string.IsNullOrEmpty(apiType))
1044+
{
1045+
api.ApiType = apiType;
1046+
}
1047+
1048+
if (!string.IsNullOrWhiteSpace(contactEmail) || !string.IsNullOrWhiteSpace(contactName) || !string.IsNullOrWhiteSpace(contactUrl))
1049+
{
1050+
api.Contact = new ApiContactInformation
1051+
{
1052+
Email = contactEmail,
1053+
Name = contactName,
1054+
Url = contactUrl
1055+
};
1056+
}
1057+
1058+
if (!string.IsNullOrWhiteSpace(licenseName) || !string.IsNullOrWhiteSpace(licenseUrl))
1059+
{
1060+
api.License = new ApiLicenseInformation
1061+
{
1062+
Name = licenseName,
1063+
Url = licenseUrl
1064+
};
1065+
}
1066+
9921067
var updatedApiContract = Client.Api.CreateOrUpdate(
9931068
resourceGroupName,
9941069
servicename,

src/ApiManagement/ApiManagement.ServiceManagement/Commands/NewAzureApiManagementApi.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,42 @@ public class NewAzureApiManagementApi : AzureApiManagementCmdletBase
161161
HelpMessage = "Type of API to create. This parameter is optional.")]
162162
public String ApiType { get; set; }
163163

164+
[Parameter(
165+
ValueFromPipelineByPropertyName = true,
166+
Mandatory = false,
167+
HelpMessage = "A URL to the Terms of Service for the API. This parameter is optional.")]
168+
public String TermsOfServiceUrl { get; set; }
169+
170+
[Parameter(
171+
ValueFromPipelineByPropertyName = true,
172+
Mandatory = false,
173+
HelpMessage = "The identifying name of the contact person/organization. This parameter is optional.")]
174+
public String ContactName { get; set; }
175+
176+
[Parameter(
177+
ValueFromPipelineByPropertyName = true,
178+
Mandatory = false,
179+
HelpMessage = "The URL pointing to the contact information. MUST be in the format of a URL. This parameter is optional.")]
180+
public String ContactUrl { get; set; }
181+
182+
[Parameter(
183+
ValueFromPipelineByPropertyName = true,
184+
Mandatory = false,
185+
HelpMessage = "The email address of the contact person/organization. MUST be in the format of an email address. This parameter is optional.")]
186+
public String ContactEmail { get; set; }
187+
188+
[Parameter(
189+
ValueFromPipelineByPropertyName = true,
190+
Mandatory = false,
191+
HelpMessage = "The license name used for the API. This parameter is optional.")]
192+
public String LicenseName { get; set; }
193+
194+
[Parameter(
195+
ValueFromPipelineByPropertyName = true,
196+
Mandatory = false,
197+
HelpMessage = "A URL to the Terms of Service for the API. This parameter is optional.")]
198+
public String LicenseUrl { get; set; }
199+
164200
public override void ExecuteApiManagementCmdlet()
165201
{
166202
string id = ApiId ?? Guid.NewGuid().ToString("N");
@@ -185,7 +221,14 @@ public override void ExecuteApiManagementCmdlet()
185221
SubscriptionKeyHeaderName,
186222
SubscriptionKeyQueryParamName,
187223
OpenIdProviderId,
188-
BearerTokenSendingMethod);
224+
BearerTokenSendingMethod,
225+
TermsOfServiceUrl,
226+
ContactName,
227+
ContactUrl,
228+
ContactEmail,
229+
LicenseName,
230+
LicenseUrl
231+
);
189232

190233
if (ProductIds != null && ProductIds.Any())
191234
{

src/ApiManagement/ApiManagement.ServiceManagement/Commands/SetAzureApiManagementApi.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,48 @@ public class SetAzureApiManagementApi : AzureApiManagementCmdletBase
145145
"representing the set API.")]
146146
public SwitchParameter PassThru { get; set; }
147147

148+
[Parameter(
149+
ValueFromPipelineByPropertyName = true,
150+
Mandatory = false,
151+
HelpMessage = "Type of API to create. This parameter is optional.")]
152+
public String ApiType { get; set; }
153+
154+
[Parameter(
155+
ValueFromPipelineByPropertyName = true,
156+
Mandatory = false,
157+
HelpMessage = "A URL to the Terms of Service for the API. This parameter is optional.")]
158+
public String TermsOfServiceUrl { get; set; }
159+
160+
[Parameter(
161+
ValueFromPipelineByPropertyName = true,
162+
Mandatory = false,
163+
HelpMessage = "The identifying name of the contact person/organization. This parameter is optional.")]
164+
public String ContactName { get; set; }
165+
166+
[Parameter(
167+
ValueFromPipelineByPropertyName = true,
168+
Mandatory = false,
169+
HelpMessage = "The URL pointing to the contact information. MUST be in the format of a URL. This parameter is optional.")]
170+
public String ContactUrl { get; set; }
171+
172+
[Parameter(
173+
ValueFromPipelineByPropertyName = true,
174+
Mandatory = false,
175+
HelpMessage = "The email address of the contact person/organization. MUST be in the format of an email address. This parameter is optional.")]
176+
public String ContactEmail { get; set; }
177+
178+
[Parameter(
179+
ValueFromPipelineByPropertyName = true,
180+
Mandatory = false,
181+
HelpMessage = "The license name used for the API. This parameter is optional.")]
182+
public String LicenseName { get; set; }
183+
184+
[Parameter(
185+
ValueFromPipelineByPropertyName = true,
186+
Mandatory = false,
187+
HelpMessage = "A URL to the Terms of Service for the API. This parameter is optional.")]
188+
public String LicenseUrl { get; set; }
189+
148190
public override void ExecuteApiManagementCmdlet()
149191
{
150192
string resourcegroupName;
@@ -180,7 +222,14 @@ public override void ExecuteApiManagementCmdlet()
180222
SubscriptionKeyQueryParamName,
181223
OpenIdProviderId,
182224
BearerTokenSendingMethod,
183-
InputObject);
225+
InputObject,
226+
ApiType,
227+
TermsOfServiceUrl,
228+
ContactName,
229+
ContactUrl,
230+
ContactEmail,
231+
LicenseName,
232+
LicenseUrl);
184233

185234
if (PassThru.IsPresent)
186235
{

src/ApiManagement/ApiManagement.ServiceManagement/Commands/SetAzureApiManagementApiRevision.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2424
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ApiManagementApiRevision", DefaultParameterSetName = ExpandedParameterSet, SupportsShouldProcess = true)]
2525
[OutputType(typeof(PsApiManagementApi), ParameterSetName = new[] { ExpandedParameterSet, ByInputObjectParameterSet })]
2626
public class SetAzureApiManagementApiRevision : SetAzureApiManagementApi
27-
{
27+
{
2828
[Parameter(
2929
ParameterSetName = ExpandedParameterSet,
3030
ValueFromPipelineByPropertyName = true,
@@ -77,10 +77,17 @@ public override void ExecuteApiManagementCmdlet()
7777
SubscriptionKeyQueryParamName,
7878
OpenIdProviderId,
7979
BearerTokenSendingMethod,
80-
InputObject);
80+
InputObject,
81+
ApiType,
82+
TermsOfServiceUrl,
83+
ContactName,
84+
ContactUrl,
85+
ContactEmail,
86+
LicenseName,
87+
LicenseUrl);
8188

8289
if (PassThru.IsPresent)
83-
{
90+
{
8491
WriteObject(updatedApiRevision);
8592
}
8693
}

src/ApiManagement/ApiManagement.ServiceManagement/Helpers/Utils.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,44 @@ public static SubscriptionKeyParameterNamesContract ToSubscriptionKeyParameterNa
292292
return subscriptionKeyParameters;
293293
}
294294

295+
public static ApiLicenseInformation ToLicenseInformation(PsApiManagementApi psApiManagementApi)
296+
{
297+
if (psApiManagementApi == null ||
298+
(string.IsNullOrWhiteSpace(psApiManagementApi.LicenseUrl) &&
299+
string.IsNullOrEmpty(psApiManagementApi.LicenseName)))
300+
{
301+
return null;
302+
}
303+
304+
var licenseParameters = new ApiLicenseInformation()
305+
{
306+
Name = psApiManagementApi.LicenseName,
307+
Url = psApiManagementApi.LicenseUrl
308+
};
309+
310+
return licenseParameters;
311+
}
312+
313+
public static ApiContactInformation ToContactInformation(PsApiManagementApi psApiManagementApi)
314+
{
315+
if (psApiManagementApi == null ||
316+
(string.IsNullOrWhiteSpace(psApiManagementApi.ContactEmail) &&
317+
string.IsNullOrWhiteSpace(psApiManagementApi.ContactName) &&
318+
string.IsNullOrEmpty(psApiManagementApi.ContactUrl)))
319+
{
320+
return null;
321+
}
322+
323+
var contactParameters = new ApiContactInformation()
324+
{
325+
Email = psApiManagementApi.ContactEmail,
326+
Name = psApiManagementApi.ContactName,
327+
Url = psApiManagementApi.ContactUrl
328+
};
329+
330+
return contactParameters;
331+
}
332+
295333
public static string TrimApiResourceIdentifier(string armApiId)
296334
{
297335
if (string.IsNullOrEmpty(armApiId))

src/ApiManagement/ApiManagement.ServiceManagement/Models/PsApiManagementApi.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,30 @@ public class PsApiManagementApi : PsApiManagementArmResource
110110
/// Gets or sets a resource identifier for the related ApiVersionSet.
111111
/// </summary>
112112
public string ApiVersionSetId { get; set; }
113+
114+
/// <summary>
115+
/// Gets or sets the email address of the contact person/organization.
116+
/// </summary>
117+
public string ContactEmail { get; set; }
118+
119+
/// <summary>
120+
/// Gets or sets the identifying name of the contact person/organization.
121+
/// </summary>
122+
public string ContactName { get; set; }
123+
124+
/// <summary>
125+
/// Gets or sets the URL pointing to the contact information.
126+
/// </summary>
127+
public string ContactUrl { get; set; }
128+
129+
/// <summary>
130+
/// Gets or sets the license name used for the API.
131+
/// </summary>
132+
public string LicenseName { get; set; }
133+
134+
/// <summary>
135+
/// Gets or sets a URL to the Terms of Service for the API.
136+
/// </summary>
137+
public string LicenseUrl { get; set; }
113138
}
114139
}

0 commit comments

Comments
 (0)