3
3
4
4
using System . Diagnostics ;
5
5
using System . Diagnostics . Tracing ;
6
- using System . Dynamic ;
7
6
using System . Net . Http . Json ;
8
7
using System . Text . Json ;
9
8
using Azure . Core ;
@@ -36,15 +35,17 @@ internal class ApiCenterProductionVersionPluginConfiguration
36
35
public string ResourceGroupName { get ; set ; } = "" ;
37
36
public string ServiceName { get ; set ; } = "" ;
38
37
public string WorkspaceName { get ; set ; } = "default" ;
39
- public bool UseDevCredentials { get ; set ; } = true ;
40
- public bool UseProdCredentials { get ; set ; } = false ;
41
38
}
42
39
43
40
public class ApiCenterProductionVersionPlugin : BaseProxyPlugin
44
41
{
45
42
private ApiCenterProductionVersionPluginConfiguration _configuration = new ( ) ;
46
43
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
+ } ) ;
48
49
private HttpClient ? _httpClient ;
49
50
private JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions
50
51
{
@@ -78,16 +79,6 @@ public override void Register(IPluginEvents pluginEvents,
78
79
_logger ? . LogError ( "Specify ServiceName in the ApiCenterProductionVersionPlugin configuration. The ApiCenterProductionVersionPlugin will not be used." ) ;
79
80
return ;
80
81
}
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
- }
91
82
92
83
// load configuration from env vars
93
84
if ( _configuration . SubscriptionId . StartsWith ( '@' ) )
@@ -107,36 +98,6 @@ public override void Register(IPluginEvents pluginEvents,
107
98
_configuration . WorkspaceName = Environment . GetEnvironmentVariable ( _configuration . WorkspaceName . Substring ( 1 ) ) ?? _configuration . WorkspaceName ;
108
99
}
109
100
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
-
140
101
if ( _logger ? . LogLevel == LogLevel . Debug )
141
102
{
142
103
var consoleListener = AzureEventSourceListener . CreateConsoleLogger ( EventLevel . Verbose ) ;
0 commit comments