33
44using System . Diagnostics ;
55using System . Diagnostics . Tracing ;
6- using System . Dynamic ;
76using System . Net . Http . Json ;
87using System . Text . Json ;
98using Azure . Core ;
@@ -36,15 +35,17 @@ internal class ApiCenterProductionVersionPluginConfiguration
3635 public string ResourceGroupName { get ; set ; } = "" ;
3736 public string ServiceName { get ; set ; } = "" ;
3837 public string WorkspaceName { get ; set ; } = "default" ;
39- public bool UseDevCredentials { get ; set ; } = true ;
40- public bool UseProdCredentials { get ; set ; } = false ;
4138}
4239
4340public class ApiCenterProductionVersionPlugin : BaseProxyPlugin
4441{
4542 private ApiCenterProductionVersionPluginConfiguration _configuration = new ( ) ;
4643 private readonly string [ ] _scopes = [ "https://management.azure.com/.default" ] ;
47- private TokenCredential _credential = new DefaultAzureCredential ( ) ;
44+ private TokenCredential _credential = new DefaultAzureCredential ( new DefaultAzureCredentialOptions ( ) {
45+ ExcludeInteractiveBrowserCredential = true ,
46+ // fails on Ubuntu
47+ ExcludeSharedTokenCacheCredential = true
48+ } ) ;
4849 private HttpClient ? _httpClient ;
4950 private JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions
5051 {
@@ -78,16 +79,6 @@ public override void Register(IPluginEvents pluginEvents,
7879 _logger ? . LogError ( "Specify ServiceName in the ApiCenterProductionVersionPlugin configuration. The ApiCenterProductionVersionPlugin will not be used." ) ;
7980 return ;
8081 }
81- if ( ! _configuration . UseDevCredentials && ! _configuration . UseProdCredentials )
82- {
83- _logger ? . LogError (
84- "Both {useDev} and {useProd} are set to false. You need to use at least one set of credentials The {plugin} will not be used." ,
85- nameof ( ApiCenterProductionVersionPluginConfiguration . UseDevCredentials ) ,
86- nameof ( ApiCenterProductionVersionPluginConfiguration . UseProdCredentials ) ,
87- Name
88- ) ;
89- return ;
90- }
9182
9283 // load configuration from env vars
9384 if ( _configuration . SubscriptionId . StartsWith ( '@' ) )
@@ -107,36 +98,6 @@ public override void Register(IPluginEvents pluginEvents,
10798 _configuration . WorkspaceName = Environment . GetEnvironmentVariable ( _configuration . WorkspaceName . Substring ( 1 ) ) ?? _configuration . WorkspaceName ;
10899 }
109100
110- var credentials = new List < TokenCredential > ( ) ;
111- // as defined in DefaultAzureCredential
112- var tokenCredentialOptions = new TokenCredentialOptions
113- {
114- Retry =
115- {
116- NetworkTimeout = TimeSpan . FromSeconds ( 1 )
117- }
118- } ;
119- if ( _configuration . UseDevCredentials )
120- {
121- credentials . AddRange ( [
122- new SharedTokenCacheCredential ( ) ,
123- new VisualStudioCredential ( ) ,
124- new VisualStudioCodeCredential ( ) ,
125- new AzureCliCredential ( ) ,
126- new AzurePowerShellCredential ( ) ,
127- new AzureDeveloperCliCredential ( ) ,
128- ] ) ;
129- }
130- if ( _configuration . UseProdCredentials )
131- {
132- credentials . AddRange ( [
133- new EnvironmentCredential ( ) ,
134- new WorkloadIdentityCredential ( ) ,
135- new ManagedIdentityCredential ( options : tokenCredentialOptions )
136- ] ) ;
137- }
138- _credential = new ChainedTokenCredential ( credentials . ToArray ( ) ) ;
139-
140101 if ( _logger ? . LogLevel == LogLevel . Debug )
141102 {
142103 var consoleListener = AzureEventSourceListener . CreateConsoleLogger ( EventLevel . Verbose ) ;
0 commit comments