Commit 8878ab9 1 parent fd56265 commit 8878ab9 Copy full SHA for 8878ab9
File tree 4 files changed +69
-3
lines changed
4 files changed +69
-3
lines changed Original file line number Diff line number Diff line change @@ -51,11 +51,29 @@ public override async Task RunAsync()
51
51
throw new CliException ( "Log stream is not currently supported in Linux Consumption Apps. " +
52
52
"Please use --browser to open Azure Application Insights Live Stream in the Azure portal." ) ;
53
53
}
54
- var basicHeaderValue = Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( $ "{ functionApp . PublishingUserName } :{ functionApp . PublishingPassword } ") ) ;
55
-
54
+
56
55
using ( var client = new HttpClient ( ) )
57
56
{
58
- client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" , basicHeaderValue ) ;
57
+ var isBasicAuthAllowed = true ;
58
+ try
59
+ {
60
+ isBasicAuthAllowed = await AzureHelper . IsBasicAuthAllowedForSCM ( functionApp , AccessToken , ManagementURL ) ;
61
+ }
62
+ catch ( Exception )
63
+ {
64
+ // ignore: We don't want to fail the command on basic auth check. There is extremely low likelihood of getting the exception here.
65
+ }
66
+
67
+ if ( isBasicAuthAllowed )
68
+ {
69
+ var basicHeaderValue = Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( $ "{ functionApp . PublishingUserName } :{ functionApp . PublishingPassword } ") ) ;
70
+ client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" , basicHeaderValue ) ;
71
+ }
72
+ else
73
+ {
74
+ client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , AccessToken ) ;
75
+ }
76
+
59
77
client . DefaultRequestHeaders . Add ( "User-Agent" , Constants . CliUserAgent ) ;
60
78
var response = await client . GetStreamAsync ( new Uri ( $ "https://{ functionApp . ScmUri } /api/logstream/application") ) ;
61
79
using ( var reader = new StreamReader ( response ) )
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ internal static class ArmUriTemplates
10
10
public const string WebsitesApiVersion = "2015-08-01" ;
11
11
public const string SyncTriggersApiVersion = "2016-08-01" ;
12
12
public const string ArgApiVersion = "2019-04-01" ;
13
+ public const string BasicAuthCheckApiVersion = "2022-03-01" ;
13
14
14
15
public const string ArgUri = "providers/Microsoft.ResourceGraph/resources" ;
15
16
Original file line number Diff line number Diff line change
1
+ using Newtonsoft . Json ;
2
+ using System ;
3
+ using System . Collections . Generic ;
4
+ using System . Linq ;
5
+ using System . Text ;
6
+ using System . Threading . Tasks ;
7
+ using static NuGet . Client . ManagedCodeConventions ;
8
+
9
+ namespace Azure . Functions . Cli . Arm . Models
10
+ {
11
+ class BasicAuthCheckResponse
12
+ {
13
+ [ JsonProperty ( PropertyName = "id" ) ]
14
+ public string Id { get ; set ; }
15
+
16
+ [ JsonProperty ( PropertyName = "name" ) ]
17
+ public string ResourceName { get ; set ; }
18
+
19
+ [ JsonProperty ( PropertyName = "type" ) ]
20
+ public string ResourceType { get ; set ; }
21
+
22
+ [ JsonProperty ( PropertyName = "location" ) ]
23
+ public string Location { get ; set ; }
24
+
25
+ [ JsonProperty ( PropertyName = "properties" ) ]
26
+ public BasicAuthCheckResponseProperties Properties { get ; set ; }
27
+ }
28
+
29
+ class BasicAuthCheckResponseProperties
30
+ {
31
+ [ JsonProperty ( PropertyName = "allow" ) ]
32
+ public bool Allow { get ; set ; }
33
+ }
34
+ }
Original file line number Diff line number Diff line change @@ -106,6 +106,19 @@ internal static async Task<string> GetResourceIDFromArg(IEnumerable<string> subI
106
106
?? throw new CliException ( "Error finding the Azure Resource information." ) ;
107
107
}
108
108
109
+ internal static async Task < bool > IsBasicAuthAllowedForSCM ( Site functionApp , string accessToken , string managementURL )
110
+ {
111
+ var url = new Uri ( $ "{ managementURL } { functionApp . SiteId } /basicPublishingCredentialsPolicies/scm?api-version={ ArmUriTemplates . BasicAuthCheckApiVersion } ") ;
112
+
113
+ var response = await ArmClient . HttpInvoke ( HttpMethod . Get , url , accessToken ) ;
114
+ response . EnsureSuccessStatusCode ( ) ;
115
+
116
+ var result = await response . Content . ReadAsStringAsync ( ) ;
117
+ var basicAuthResponse = JsonConvert . DeserializeObject < BasicAuthCheckResponse > ( result ) ;
118
+
119
+ return basicAuthResponse . Properties . Allow ;
120
+ }
121
+
109
122
internal static ArmResourceId ParseResourceId ( string resourceId )
110
123
{
111
124
if ( string . IsNullOrEmpty ( resourceId ) )
You can’t perform that action at this time.
0 commit comments