Skip to content

Commit

Permalink
Add managed identity option (#56)
Browse files Browse the repository at this point in the history
* update package versions

* update DevCenterCredentialsHandler to use managed identity, add IsValidCredentials check

* update authconfig for file use

* update program, add additional creds options

* spelling and formatting
  • Loading branch information
Ben-Carpenter committed Jul 30, 2024
1 parent 3753f3d commit e796eb1
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 38 deletions.
60 changes: 29 additions & 31 deletions SurfaceDevCenterManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{ "h|help", "Show this message and exit", v => show_help = v != null },
{ "w|wait", "Wait for submission id to be done", v => WaitOption = true },
{ "waitmetadata", "Wait for metadata to be done as well in a submission", v => WaitForMetaData = true },
{ "createmetadata", "Requeset metadata creation for older submissions", v => CreateMetaData = true },
{ "createmetadata", "Request metadata creation for older submissions", v => CreateMetaData = true },
{ "a|audience", "List Audiences", v => AudienceOption = true },
{ "server=", "Specify target DevCenter server from CredSelect enum", v => { OverrideServer = int.Parse(v); OverrideServerPresent = true; } },
{ "creds=", "Option to specify app credentials. Options: ENVOnly, FileOnly, AADOnly, AADThenFile (Default)", v => CredentialsOption = v },
{ "creds=", "Option to specify app credentials. Options: ENVOnly, ClientCredentials, ManagedIdentity, MiThenFile, FileOnly, AADOnly, AADThenFile (Default)", v => CredentialsOption = v },
{ "aad=", "Option to specify AAD auth behavior. Options: Never (Default), Prompt, Always, RefreshSession, SelectAccount", v => AADAuthenticationOption = v },
{ "t|timeout=", $"Adjust the timeout for HTTP requests to specified seconds. Default:{DEFAULT_TIMEOUT} seconds", v => TimeoutOption = v },
{ "translate", "Translate the given publisherid, productid and submissionid from a partner to the values visible in your HDC account", v => TranslateOption = true},
Expand Down Expand Up @@ -231,7 +231,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(CreateOption) } { nameof(api.NewProduct) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(CreateOption)} {nameof(api.NewProduct)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand All @@ -250,7 +250,6 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
LogExceptionToConsole(ex, nameof(CreateOption), nameof(api.NewProduct));
return ErrorCodes.PARTNER_CENTER_HTTP_EXCEPTION;
}

}
else if (DevCenterHWSubmissionType.Submission == createInput.CreateType)
{
Expand All @@ -271,7 +270,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(CreateOption) } { nameof(api.NewSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(CreateOption)} {nameof(api.NewSubmission)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -320,7 +319,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (retSubmission.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(CreateOption) } { nameof(api.GetSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(CreateOption)} {nameof(api.GetSubmission)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -390,7 +389,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(CreateOption) } { nameof(api.NewShippingLabel) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(CreateOption)} {nameof(api.NewShippingLabel)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -443,12 +442,12 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(CommitOption) } { nameof(api.CommitSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(CommitOption)} {nameof(api.CommitSubmission)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
if (ret.Error.Code == ErrorCodeConstants.RequestInvalidForCurrentState && ret.Error.Message == ErrorMessageConstants.OnlyPendingSubmissionsCanBeCommitted)
{
Console.WriteLine($"{ nameof(CommitOption) } { nameof(api.CommitSubmission) } request invalid for currentState, { ErrorMessageConstants.OnlyPendingSubmissionsCanBeCommitted }");
Console.WriteLine($"{nameof(CommitOption)} {nameof(api.CommitSubmission)} request invalid for currentState, {ErrorMessageConstants.OnlyPendingSubmissionsCanBeCommitted}");
DevCenterErrorDetailsDump(ret.Error);
return ErrorCodes.COMMIT_REQUEST_INVALID_FOR_CURRENT_STATE;
}
Expand All @@ -469,7 +468,6 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
Console.WriteLine("> Commit OK");
}

}
}
catch (Exception ex)
Expand All @@ -496,7 +494,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(ListOption) } { nameof(api.GetProducts) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(ListOption)} {nameof(api.GetProducts)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand All @@ -523,12 +521,12 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(ListOption) } { nameof(api.GetSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(ListOption)} {nameof(api.GetSubmission)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
if (ret.Error.Code == ErrorCodeConstants.EntityNotFound)
{
Console.WriteLine($"{ nameof(ListOption) } { nameof(api.GetSubmission) } entity not found, try translate option.");
Console.WriteLine($"{nameof(ListOption)} {nameof(api.GetSubmission)} entity not found, try translate option.");
DevCenterErrorDetailsDump(ret.Error);
return ErrorCodes.SUBMISSION_ENTITY_NOT_FOUND;
}
Expand Down Expand Up @@ -556,7 +554,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(ListOption) } { nameof(api.GetShippingLabels) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(ListOption)} {nameof(api.GetShippingLabels)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand All @@ -583,7 +581,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(ListOption) } { nameof(api.GetPartnerSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(ListOption)} {nameof(api.GetPartnerSubmission)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -655,7 +653,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(DownloadOption) } { nameof(api.GetSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(DownloadOption)} {nameof(api.GetSubmission)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -709,7 +707,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(MetadataOption) } { nameof(api.GetSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(MetadataOption)} {nameof(api.GetSubmission)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -770,7 +768,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(SubmissionPackagePath) } { nameof(api.GetSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(SubmissionPackagePath)} {nameof(api.GetSubmission)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -832,7 +830,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(WaitOption) } { nameof(api.GetSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(WaitOption)} {nameof(api.GetSubmission)} experienced a HTTP 429 Too Many Requests response.");
await Task.Delay(5000);
continue;
}
Expand All @@ -851,7 +849,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (sub.WorkflowStatus == null)
{
Console.WriteLine($"{ nameof(WaitOption) } { sub.Name } { nameof(WorkflowStatus) } was NULL. Will continue to wait...");
Console.WriteLine($"{nameof(WaitOption)} {sub.Name} {nameof(WorkflowStatus)} was NULL. Will continue to wait...");
continue;
}

Expand Down Expand Up @@ -930,7 +928,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(WaitOption) } { nameof(api.GetShippingLabels) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(WaitOption)} {nameof(api.GetShippingLabels)} experienced a HTTP 429 Too Many Requests response.");
await Task.Delay(5000);
continue;
}
Expand Down Expand Up @@ -995,7 +993,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(AudienceOption) } { nameof(api.GetAudiences) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(AudienceOption)} {nameof(api.GetAudiences)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -1045,7 +1043,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(CreateMetaData) } { nameof(api.CreateMetaData) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(CreateMetaData)} {nameof(api.CreateMetaData)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -1106,7 +1104,7 @@ private static async Task<ErrorCodes> MainAsync(string[] args)
{
if (ret.Error.HttpErrorCode == 429)
{
Console.WriteLine($"{ nameof(TranslateOption) } { nameof(api.GetPartnerSubmission) } experienced a HTTP 429 Too Many Requests response.");
Console.WriteLine($"{nameof(TranslateOption)} {nameof(api.GetPartnerSubmission)} experienced a HTTP 429 Too Many Requests response.");
return ErrorCodes.HTTP_429_RATE_LIMIT_EXCEEDED;
}
else
Expand Down Expand Up @@ -1193,7 +1191,7 @@ private static void DevCenterErrorDetailsDump(DevCenterErrorDetails error)
if (error.Trace != null)
{
Console.WriteLine("Request Id: {0}", error.Trace.RequestId ?? "");
Console.WriteLine("Method: {0}", error.Trace.Method ?? "" );
Console.WriteLine("Method: {0}", error.Trace.Method ?? "");
Console.WriteLine("Url: {0}", error.Trace.Url ?? "");
Console.WriteLine("Content: {0}", error.Trace.Content ?? "");
}
Expand All @@ -1211,12 +1209,12 @@ private static void LogExceptionToConsole(Exception ex, string option, string se
Console.WriteLine("");
Console.WriteLine("============================================================");
Console.WriteLine("\tSurfaceDevCenterManager Exception Log");
Console.WriteLine($"Option: { option ?? "" }");
Console.WriteLine($"Section: { section ?? "" }");
Console.WriteLine($"Type: { ex.GetType() ?? null }");
Console.WriteLine($"Message: { ex.Message ?? "" }");
Console.WriteLine($"Inner Exception: { ex.InnerException?.Message ?? "" }");
Console.WriteLine($"Correlation Id: { CorrelationId }");
Console.WriteLine($"Option: {option ?? ""}");
Console.WriteLine($"Section: {section ?? ""}");
Console.WriteLine($"Type: {ex.GetType() ?? null}");
Console.WriteLine($"Message: {ex.Message ?? ""}");
Console.WriteLine($"Inner Exception: {ex.InnerException?.Message ?? ""}");
Console.WriteLine($"Correlation Id: {CorrelationId}");
Console.WriteLine("============================================================");
Console.WriteLine("");
}
Expand Down
4 changes: 2 additions & 2 deletions SurfaceDevCenterManager/SurfaceDevCenterManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<Version>5.8.5</Version>
</PackageReference>
<PackageReference Include="Microsoft.Devices.HardwareDevCenterManager">
<Version>2.2.13</Version>
<Version>3.0.12</Version>
</PackageReference>
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory">
<Version>5.3.0</Version>
Expand All @@ -110,7 +110,7 @@
<Version>6.12.0.148</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.2</Version>
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="System.ComponentModel.EventBasedAsync">
<Version>4.3.0</Version>
Expand Down
Loading

0 comments on commit e796eb1

Please sign in to comment.