Skip to content

Commit a7ff09e

Browse files
committed
allowed piping in armclient token
1 parent 1670561 commit a7ff09e

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

ConverterLibrary/Converter.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Net.Http.Headers;
1414
using System.Text;
1515
using System.Threading.Tasks;
16+
using System.Windows.Forms;
1617

1718
namespace ConverterLibrary
1819
{
@@ -36,10 +37,15 @@ public class Converter : PSCmdlet
3637
public string SubscriptionId;
3738
[Parameter(
3839
Mandatory = false,
39-
HelpMessage = "Authorization Bearer Token",
40-
ValueFromPipeline = true
40+
HelpMessage = "Authorization Bearer Token"
4141
)]
4242
public string Token = "";
43+
[Parameter(
44+
Mandatory =false,
45+
HelpMessage = "Piped input from armclient",
46+
ValueFromPipeline = true
47+
)]
48+
public string ClaimsDump;
4349
private DeploymentTemplate template;
4450
private JObject workflowTemplateReference;
4551

@@ -56,16 +62,31 @@ public Converter(string token) : this()
5662

5763
protected override void ProcessRecord()
5864
{
59-
if (String.IsNullOrEmpty(Token))
65+
if(ClaimsDump == null)
6066
{
61-
AuthenticationContext ac = new AuthenticationContext(Constants.AuthString, true);
62-
var ar = ac.AcquireToken(Constants.ResourceUrl, Constants.ClientId, new Uri(Constants.RedirectUrl), PromptBehavior.Always);
67+
WriteVerbose("No armclient token piped through. Attempting to authenticate");
68+
if (String.IsNullOrEmpty(Token))
69+
{
70+
AuthenticationContext ac = new AuthenticationContext(Constants.AuthString, true);
71+
var ar = ac.AcquireToken(Constants.ResourceUrl, Constants.ClientId, new Uri(Constants.RedirectUrl), PromptBehavior.Always);
6372

6473

65-
Token = ar.AccessToken;
74+
Token = ar.AccessToken;
6675

67-
WriteVerbose("Retrieved Token: " + Token);
76+
WriteVerbose("Retrieved Token: " + Token);
77+
}
6878
}
79+
else if(ClaimsDump.Contains("Token copied"))
80+
{
81+
Token = Clipboard.GetText().Replace("Bearer ", "");
82+
WriteVerbose("Got token from armclient: " + Token);
83+
}
84+
else
85+
{
86+
return;
87+
}
88+
89+
6990
var result = ConvertWithToken(SubscriptionId, ResourceGroup, LogicApp, Token).Result;
7091
WriteObject(result.ToString());
7192
}

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Open PowerShell and Import the module:
1010

1111
`Import-Module C:\{pathToSolution}\LogicAppTemplateCreator\ConverterLibrary\bin\Debug\ConverterLibrary.dll`
1212

13-
Run the PowerShell command `Get-LogicAppTemplate`. You can pipe the output as needed:
13+
Run the PowerShell command `Get-LogicAppTemplate`. You can pipe the output as needed, and recommended you pipe in a token from `armclient`
1414

15-
`Get-LogicAppTemplate -LogicApp MyApp -ResourceGroup Integrate2016 -SubscriptionId 80d4fe69-xxxx-4dd2-a938-9250f1c8ab03 -Verbose | Out-File C:\template.json`
15+
`armclient token 80d4fe69-xxxx-4dd2-a938-9250f1c8ab03 | Get-LogicAppTemplate -LogicApp MyApp -ResourceGroup Integrate2016 -SubscriptionId 80d4fe69-xxxx-4dd2-a938-9250f1c8ab03 -Verbose | Out-File C:\template.json`
16+
17+
### Specifications
18+
19+
| Parameter | Description | Required |
20+
| --------- | ---------- | -------|
21+
| LogicApp | The name of the Logic App | true |
22+
| ResourceGroup | The name of the Resource Group | true |
23+
| SubscriptionId | The subscription Id for the resource | true |
24+
| Token | An AAD Token to access the resources - should not include `Bearer`, only the token | false |
25+
| ClaimsDump | A dump of claims piped in from `armclient` - should not be manually set | false |

0 commit comments

Comments
 (0)