@@ -10,57 +10,51 @@ public enum LogDestination {
1010
1111
1212public interface IServiceConfig {
13- public LogDestination [ ] LogDestinations { get ; set ; }
14-
13+ #region Parameters for logging & application insights
14+ public LogDestination [ ] LogDestinations { get ; }
1515 public ApplicationInsights . DataContracts . SeverityLevel LogSeverityLevel { get ; }
16-
1716 public string ? ApplicationInsightsAppId { get ; }
1817 public string ? ApplicationInsightsInstrumentationKey { get ; }
18+ #endregion
19+
20+ #region Parameters for feature flags
1921 public string ? AppConfigurationEndpoint { get ; }
2022 public string ? AppConfigurationConnectionString { get ; }
21- public string ? AzureSignalRConnectionString { get ; }
22- public string ? AzureSignalRServiceTransportType { get ; }
23-
24- public string ? AzureWebJobDisableHomePage { get ; }
25- public string ? AzureWebJobStorage { get ; }
23+ #endregion
2624
27- public string ? DiagnosticsAzureBlobContainerSasUrl { get ; }
28- public string ? DiagnosticsAzureBlobRetentionDays { get ; }
25+ #region Auth parameters for CLI app
2926 public string ? CliAppId { get ; }
3027 public string ? Authority { get ; }
3128 public string ? TenantDomain { get ; }
3229 public string ? MultiTenantDomain { get ; }
33- public ResourceIdentifier ? OneFuzzDataStorage { get ; }
34- public ResourceIdentifier ? OneFuzzFuncStorage { get ; }
35- public string ? OneFuzzInstance { get ; }
36- public string ? OneFuzzInstanceName { get ; }
37- public string ? OneFuzzEndpoint { get ; }
38- public string ? OneFuzzKeyvault { get ; }
39-
30+ #endregion
31+
32+ public ResourceIdentifier OneFuzzResourceGroup { get ; }
33+ public ResourceIdentifier OneFuzzDataStorage { get ; }
34+ public ResourceIdentifier OneFuzzFuncStorage { get ; }
35+ public Uri OneFuzzInstance { get ; }
36+ public string OneFuzzInstanceName { get ; }
37+ public Uri ? OneFuzzEndpoint { get ; }
38+ public string OneFuzzKeyvault { get ; }
4039 public string ? OneFuzzMonitor { get ; }
4140 public string ? OneFuzzOwner { get ; }
42-
43- public string ? OneFuzzResourceGroup { get ; }
4441 public string ? OneFuzzTelemetry { get ; }
45-
4642 public string OneFuzzVersion { get ; }
47-
4843 public string ? OneFuzzAllowOutdatedAgent { get ; }
4944
5045 // Prefix to add to the name of any tables & containers created. This allows
5146 // multiple instances to run against the same storage account, which
5247 // is useful for things like integration testing.
5348 public string OneFuzzStoragePrefix { get ; }
54-
55- public Uri OneFuzzBaseAddress { get ; }
5649}
5750
5851public class ServiceConfiguration : IServiceConfig {
5952
6053 // Version is baked into the assembly by the build process:
61- private static readonly string ? _oneFuzzVersion =
54+ private static readonly string _oneFuzzVersion =
6255 Assembly . GetExecutingAssembly ( )
63- . GetCustomAttribute < AssemblyInformationalVersionAttribute > ( ) ? . InformationalVersion ;
56+ . GetCustomAttribute < AssemblyInformationalVersionAttribute > ( ) ? . InformationalVersion
57+ ?? throw new InvalidOperationException ( "Unable to read OneFuzz version from assembly" ) ;
6458
6559 public ServiceConfiguration ( ) {
6660#if DEBUG
@@ -72,78 +66,57 @@ public ServiceConfiguration() {
7266
7367 private static string ? GetEnv ( string name ) {
7468 var v = Environment . GetEnvironmentVariable ( name ) ;
75- if ( String . IsNullOrEmpty ( v ) )
76- return null ;
77-
78- return v ;
69+ return string . IsNullOrEmpty ( v ) ? null : v ;
7970 }
8071
72+ private static string MustGetEnv ( string name )
73+ => GetEnv ( name ) ?? throw new InvalidOperationException ( $ "Environment variable { name } is required to be set") ;
74+
8175 //TODO: Add environment variable to control where to write logs to
82- public LogDestination [ ] LogDestinations { get ; set ; }
76+ public LogDestination [ ] LogDestinations { get ; private set ; }
8377
8478 //TODO: Get this from Environment variable
8579 public ApplicationInsights . DataContracts . SeverityLevel LogSeverityLevel => ApplicationInsights . DataContracts . SeverityLevel . Verbose ;
8680
87- public string ? ApplicationInsightsAppId => GetEnv ( "APPINSIGHTS_APPID" ) ;
88- public string ? ApplicationInsightsInstrumentationKey => GetEnv ( "APPINSIGHTS_INSTRUMENTATIONKEY" ) ;
81+ public string ? ApplicationInsightsAppId { get ; } = GetEnv ( "APPINSIGHTS_APPID" ) ;
8982
90- public string ? AppConfigurationEndpoint => GetEnv ( "APPCONFIGURATION_ENDPOINT " ) ;
83+ public string ? ApplicationInsightsInstrumentationKey { get ; } = GetEnv ( "APPINSIGHTS_INSTRUMENTATIONKEY " ) ;
9184
92- public string ? AppConfigurationConnectionString => GetEnv ( "APPCONFIGURATION_CONNECTION_STRING " ) ;
85+ public string ? AppConfigurationEndpoint { get ; } = GetEnv ( "APPCONFIGURATION_ENDPOINT " ) ;
9386
94- public string ? AzureSignalRConnectionString => GetEnv ( "AzureSignalRConnectionString" ) ;
95- public string ? AzureSignalRServiceTransportType => GetEnv ( "AzureSignalRServiceTransportType" ) ;
87+ public string ? AppConfigurationConnectionString { get ; } = GetEnv ( "APPCONFIGURATION_CONNECTION_STRING" ) ;
9688
97- public string ? AzureWebJobDisableHomePage { get => GetEnv ( "AzureWebJobsDisableHomepage" ) ; }
98- public string ? AzureWebJobStorage { get => GetEnv ( "AzureWebJobsStorage" ) ; }
89+ public string ? CliAppId { get ; } = GetEnv ( "CLI_APP_ID" ) ;
9990
100- public string ? DiagnosticsAzureBlobContainerSasUrl { get => GetEnv ( "DIAGNOSTICS_AZUREBLOBCONTAINERSASURL" ) ; }
101- public string ? DiagnosticsAzureBlobRetentionDays { get => GetEnv ( "DIAGNOSTICS_AZUREBLOBRETENTIONINDAYS" ) ; }
102- public string ? CliAppId { get => GetEnv ( "CLI_APP_ID" ) ; }
103- public string ? Authority { get => GetEnv ( "AUTHORITY" ) ; }
104- public string ? TenantDomain { get => GetEnv ( "TENANT_DOMAIN" ) ; }
105- public string ? MultiTenantDomain { get => GetEnv ( "MULTI_TENANT_DOMAIN" ) ; }
91+ public string ? Authority { get ; } = GetEnv ( "AUTHORITY" ) ;
10692
107- public ResourceIdentifier ? OneFuzzDataStorage {
108- get {
109- var env = GetEnv ( "ONEFUZZ_DATA_STORAGE" ) ;
110- return env is null ? null : new ResourceIdentifier ( env ) ;
111- }
112- }
93+ public string ? TenantDomain { get ; } = GetEnv ( "TENANT_DOMAIN" ) ;
11394
114- public ResourceIdentifier ? OneFuzzFuncStorage {
115- get {
116- var env = GetEnv ( "ONEFUZZ_FUNC_STORAGE" ) ;
117- return env is null ? null : new ResourceIdentifier ( env ) ;
118- }
119- }
95+ public string ? MultiTenantDomain { get ; } = GetEnv ( "MULTI_TENANT_DOMAIN" ) ;
12096
121- public string ? OneFuzzInstance { get => GetEnv ( "ONEFUZZ_INSTANCE" ) ; }
122- public string ? OneFuzzInstanceName { get => GetEnv ( "ONEFUZZ_INSTANCE_NAME" ) ; }
123- public string ? OneFuzzEndpoint { get => GetEnv ( "ONEFUZZ_ENDPOINT" ) ; }
124- public string ? OneFuzzKeyvault { get => GetEnv ( "ONEFUZZ_KEYVAULT" ) ; }
125- public string ? OneFuzzMonitor { get => GetEnv ( "ONEFUZZ_MONITOR" ) ; }
126- public string ? OneFuzzOwner { get => GetEnv ( "ONEFUZZ_OWNER" ) ; }
127- public string ? OneFuzzResourceGroup { get => GetEnv ( "ONEFUZZ_RESOURCE_GROUP" ) ; }
128- public string ? OneFuzzTelemetry { get => GetEnv ( "ONEFUZZ_TELEMETRY" ) ; }
129-
130- public string OneFuzzVersion {
131- get {
132- // version can be overridden by config:
133- return GetEnv ( "ONEFUZZ_VERSION" )
134- ?? _oneFuzzVersion
135- ?? throw new InvalidOperationException ( "Unable to read OneFuzz version from assembly" ) ;
136- }
137- }
97+ public ResourceIdentifier OneFuzzDataStorage { get ; } = new ( MustGetEnv ( "ONEFUZZ_DATA_STORAGE" ) ) ;
13898
139- public string ? OneFuzzAllowOutdatedAgent => GetEnv ( "ONEFUZZ_ALLOW_OUTDATED_AGENT" ) ;
140- public string OneFuzzStoragePrefix => "" ; // in production we never prefix the tables
99+ public ResourceIdentifier OneFuzzFuncStorage { get ; } = new ( MustGetEnv ( "ONEFUZZ_FUNC_STORAGE" ) ) ;
141100
142- public Uri OneFuzzBaseAddress {
143- get {
144- var hostName = Environment . GetEnvironmentVariable ( "WEBSITE_HOSTNAME" ) ;
145- var scheme = Environment . GetEnvironmentVariable ( "HTTPS" ) != null ? "https" : "http" ;
146- return new Uri ( $ "{ scheme } ://{ hostName } ") ;
147- }
148- }
101+ public Uri OneFuzzInstance { get ; } = new Uri ( MustGetEnv ( "ONEFUZZ_INSTANCE" ) ) ;
102+
103+ public string OneFuzzInstanceName { get ; } = MustGetEnv ( "ONEFUZZ_INSTANCE_NAME" ) ;
104+
105+ public Uri ? OneFuzzEndpoint { get ; } = GetEnv ( "ONEFUZZ_ENDPOINT" ) is string value ? new Uri ( value ) : null ;
106+
107+ public string OneFuzzKeyvault { get ; } = MustGetEnv ( "ONEFUZZ_KEYVAULT" ) ;
108+
109+ public string ? OneFuzzMonitor { get ; } = GetEnv ( "ONEFUZZ_MONITOR" ) ;
110+
111+ public string ? OneFuzzOwner { get ; } = GetEnv ( "ONEFUZZ_OWNER" ) ;
112+
113+ public ResourceIdentifier OneFuzzResourceGroup { get ; } = new ( MustGetEnv ( "ONEFUZZ_RESOURCE_GROUP" ) ) ;
114+
115+ public string ? OneFuzzTelemetry { get ; } = GetEnv ( "ONEFUZZ_TELEMETRY" ) ;
116+
117+ public string OneFuzzVersion { get ; } = GetEnv ( "ONEFUZZ_VERSION" ) ?? _oneFuzzVersion ;
118+
119+ public string ? OneFuzzAllowOutdatedAgent { get ; } = GetEnv ( "ONEFUZZ_ALLOW_OUTDATED_AGENT" ) ;
120+
121+ public string OneFuzzStoragePrefix => "" ; // in production we never prefix the tables
149122}
0 commit comments