@@ -13,43 +13,40 @@ namespace Microsoft.Azure.Devices.Edge.Test.Common
13
13
14
14
public class DaemonConfiguration
15
15
{
16
- struct Config
17
- {
18
- public string ConfigPath ;
19
- public TomlDocument Document ;
20
- }
21
-
22
16
const string GlobalEndPoint = "https://global.azure-devices-provisioning.net" ;
23
- Config config ;
17
+ TomlDocument document ;
18
+ string path ;
24
19
25
20
public DaemonConfiguration ( string superTomlPath )
26
21
{
27
22
Directory . CreateDirectory ( Directory . GetParent ( superTomlPath ) . FullName ) ;
28
23
string contents = File . Exists ( superTomlPath ) ? File . ReadAllText ( superTomlPath ) : string . Empty ;
29
- this . config = new Config
30
- {
31
- ConfigPath = superTomlPath ,
32
- Document = new TomlDocument ( contents )
33
- } ;
24
+ this . document = new TomlDocument ( contents ) ;
25
+ this . path = superTomlPath ;
34
26
}
35
27
36
28
public void AddHttpsProxy ( Uri proxy )
37
29
{
38
- this . config . Document . ReplaceOrAdd ( "agent.env.https_proxy" , proxy . ToString ( ) ) ;
30
+ this . document . ReplaceOrAdd ( "agent.env.https_proxy" , proxy . ToString ( ) ) ;
39
31
// The config file is configured during test suite initialization, before we know which
40
32
// protocol a given test will use. Always use AmqpWs, and when each test deploys a
41
33
// configuration, it can update the config to use whatever it wants.
42
- this . config . Document . ReplaceOrAdd ( "agent.env.UpstreamProtocol" , "AmqpWs" ) ;
34
+ this . document . ReplaceOrAdd ( "agent.env.UpstreamProtocol" , "AmqpWs" ) ;
35
+ }
36
+
37
+ public void AddAgentUserId ( string uid )
38
+ {
39
+ this . document . ReplaceOrAdd ( "agent.env.EDGEAGENTUSER_ID" , uid ) ;
43
40
}
44
41
45
42
void SetBasicDpsParam ( string idScope )
46
43
{
47
- this . config . Document . ReplaceOrAdd ( "auto_reprovisioning_mode" , "AlwaysOnStartup" ) ;
44
+ this . document . ReplaceOrAdd ( "auto_reprovisioning_mode" , "AlwaysOnStartup" ) ;
48
45
49
- this . config . Document . RemoveIfExists ( "provisioning" ) ;
50
- this . config . Document . ReplaceOrAdd ( "provisioning.source" , "dps" ) ;
51
- this . config . Document . ReplaceOrAdd ( "provisioning.global_endpoint" , GlobalEndPoint ) ;
52
- this . config . Document . ReplaceOrAdd ( "provisioning.id_scope" , idScope ) ;
46
+ this . document . RemoveIfExists ( "provisioning" ) ;
47
+ this . document . ReplaceOrAdd ( "provisioning.source" , "dps" ) ;
48
+ this . document . ReplaceOrAdd ( "provisioning.global_endpoint" , GlobalEndPoint ) ;
49
+ this . document . ReplaceOrAdd ( "provisioning.id_scope" , idScope ) ;
53
50
}
54
51
55
52
public void SetManualSasProvisioning (
@@ -58,24 +55,24 @@ public void SetManualSasProvisioning(
58
55
string deviceId ,
59
56
string key )
60
57
{
61
- this . config . Document . ReplaceOrAdd ( "auto_reprovisioning_mode" , "AlwaysOnStartup" ) ;
58
+ this . document . ReplaceOrAdd ( "auto_reprovisioning_mode" , "AlwaysOnStartup" ) ;
62
59
parentHostname . ForEach ( parent_hostame => this . SetParentHostname ( parent_hostame ) ) ;
63
60
64
- this . config . Document . RemoveIfExists ( "provisioning" ) ;
65
- this . config . Document . ReplaceOrAdd ( "provisioning.source" , "manual" ) ;
66
- this . config . Document . ReplaceOrAdd ( "provisioning.iothub_hostname" , hubHostname ) ;
67
- this . config . Document . ReplaceOrAdd ( "provisioning.device_id" , deviceId ) ;
68
- this . config . Document . ReplaceOrAdd ( "provisioning.authentication.method" , "sas" ) ;
69
- this . config . Document . ReplaceOrAdd ( "provisioning.authentication.device_id_pk.value" , key ) ;
61
+ this . document . RemoveIfExists ( "provisioning" ) ;
62
+ this . document . ReplaceOrAdd ( "provisioning.source" , "manual" ) ;
63
+ this . document . ReplaceOrAdd ( "provisioning.iothub_hostname" , hubHostname ) ;
64
+ this . document . ReplaceOrAdd ( "provisioning.device_id" , deviceId ) ;
65
+ this . document . ReplaceOrAdd ( "provisioning.authentication.method" , "sas" ) ;
66
+ this . document . ReplaceOrAdd ( "provisioning.authentication.device_id_pk.value" , key ) ;
70
67
}
71
68
72
69
public void SetImageGarbageCollection ( int minutesUntilCleanup )
73
70
{
74
- this . config . Document . ReplaceOrAdd ( "image_garbage_collection.enabled" , true ) ;
75
- this . config . Document . ReplaceOrAdd ( "image_garbage_collection.cleanup_recurrence" , "1d" ) ;
76
- this . config . Document . ReplaceOrAdd ( "image_garbage_collection.image_age_cleanup_threshold" , "10s" ) ;
71
+ this . document . ReplaceOrAdd ( "image_garbage_collection.enabled" , true ) ;
72
+ this . document . ReplaceOrAdd ( "image_garbage_collection.cleanup_recurrence" , "1d" ) ;
73
+ this . document . ReplaceOrAdd ( "image_garbage_collection.image_age_cleanup_threshold" , "10s" ) ;
77
74
string cleanupTime = DateTime . Now . Add ( new TimeSpan ( 0 , 0 , minutesUntilCleanup , 0 ) ) . ToString ( "HH:mm" ) ;
78
- this . config . Document . ReplaceOrAdd ( "image_garbage_collection.cleanup_time" , cleanupTime ) ;
75
+ this . document . ReplaceOrAdd ( "image_garbage_collection.cleanup_time" , cleanupTime ) ;
79
76
}
80
77
81
78
public void SetDeviceManualX509 (
@@ -95,24 +92,24 @@ public void SetDeviceManualX509(
95
92
throw new InvalidOperationException ( $ "{ identityPkPath } does not exist") ;
96
93
}
97
94
98
- this . config . Document . ReplaceOrAdd ( "auto_reprovisioning_mode" , "AlwaysOnStartup" ) ;
95
+ this . document . ReplaceOrAdd ( "auto_reprovisioning_mode" , "AlwaysOnStartup" ) ;
99
96
parentHostname . ForEach ( parent_hostame => this . SetParentHostname ( parent_hostame ) ) ;
100
97
101
- this . config . Document . RemoveIfExists ( "provisioning" ) ;
102
- this . config . Document . ReplaceOrAdd ( "provisioning.source" , "manual" ) ;
103
- this . config . Document . ReplaceOrAdd ( "provisioning.iothub_hostname" , hubhostname ) ;
104
- this . config . Document . ReplaceOrAdd ( "provisioning.device_id" , deviceId ) ;
105
- this . config . Document . ReplaceOrAdd ( "provisioning.authentication.method" , "x509" ) ;
106
- this . config . Document . ReplaceOrAdd ( "provisioning.authentication.identity_cert" , "file://" + identityCertPath ) ;
107
- this . config . Document . ReplaceOrAdd ( "provisioning.authentication.identity_pk" , "file://" + identityPkPath ) ;
98
+ this . document . RemoveIfExists ( "provisioning" ) ;
99
+ this . document . ReplaceOrAdd ( "provisioning.source" , "manual" ) ;
100
+ this . document . ReplaceOrAdd ( "provisioning.iothub_hostname" , hubhostname ) ;
101
+ this . document . ReplaceOrAdd ( "provisioning.device_id" , deviceId ) ;
102
+ this . document . ReplaceOrAdd ( "provisioning.authentication.method" , "x509" ) ;
103
+ this . document . ReplaceOrAdd ( "provisioning.authentication.identity_cert" , "file://" + identityCertPath ) ;
104
+ this . document . ReplaceOrAdd ( "provisioning.authentication.identity_pk" , "file://" + identityPkPath ) ;
108
105
}
109
106
110
107
public void SetDpsSymmetricKey ( string idScope , string registrationId , string deviceKey )
111
108
{
112
109
this . SetBasicDpsParam ( idScope ) ;
113
- this . config . Document . ReplaceOrAdd ( "provisioning.attestation.method" , "symmetric_key" ) ;
114
- this . config . Document . ReplaceOrAdd ( "provisioning.attestation.registration_id" , registrationId ) ;
115
- this . config . Document . ReplaceOrAdd ( "provisioning.attestation.symmetric_key.value" , deviceKey ) ;
110
+ this . document . ReplaceOrAdd ( "provisioning.attestation.method" , "symmetric_key" ) ;
111
+ this . document . ReplaceOrAdd ( "provisioning.attestation.registration_id" , registrationId ) ;
112
+ this . document . ReplaceOrAdd ( "provisioning.attestation.symmetric_key.value" , deviceKey ) ;
116
113
}
117
114
118
115
public void SetDpsX509 ( string idScope , string identityCertPath , string identityPkPath )
@@ -128,16 +125,16 @@ public void SetDpsX509(string idScope, string identityCertPath, string identityP
128
125
}
129
126
130
127
this . SetBasicDpsParam ( idScope ) ;
131
- this . config . Document . ReplaceOrAdd ( "provisioning.attestation.method" , "x509" ) ;
132
- this . config . Document . ReplaceOrAdd ( "provisioning.attestation.identity_cert" , "file://" + identityCertPath ) ;
133
- this . config . Document . ReplaceOrAdd ( "provisioning.attestation.identity_pk" , "file://" + identityPkPath ) ;
128
+ this . document . ReplaceOrAdd ( "provisioning.attestation.method" , "x509" ) ;
129
+ this . document . ReplaceOrAdd ( "provisioning.attestation.identity_cert" , "file://" + identityCertPath ) ;
130
+ this . document . ReplaceOrAdd ( "provisioning.attestation.identity_pk" , "file://" + identityPkPath ) ;
134
131
}
135
132
136
133
public void SetEdgeAgentImage ( string value , IEnumerable < Registry > registries )
137
134
{
138
- this . config . Document . ReplaceOrAdd ( "agent.name" , "edgeAgent" ) ;
139
- this . config . Document . ReplaceOrAdd ( "agent.type" , "docker" ) ;
140
- this . config . Document . ReplaceOrAdd ( "agent.config.image" , value ) ;
135
+ this . document . ReplaceOrAdd ( "agent.name" , "edgeAgent" ) ;
136
+ this . document . ReplaceOrAdd ( "agent.type" , "docker" ) ;
137
+ this . document . ReplaceOrAdd ( "agent.config.image" , value ) ;
141
138
142
139
// Currently, the only place for registries is [agent.config.auth]
143
140
// So only one registry is supported.
@@ -148,60 +145,55 @@ public void SetEdgeAgentImage(string value, IEnumerable<Registry> registries)
148
145
149
146
foreach ( Registry registry in registries )
150
147
{
151
- this . config . Document . ReplaceOrAdd ( "agent.config.auth.serveraddress" , registry . Address ) ;
152
- this . config . Document . ReplaceOrAdd ( "agent.config.auth.username" , registry . Username ) ;
153
- this . config . Document . ReplaceOrAdd ( "agent.config.auth.password" , registry . Password ) ;
148
+ this . document . ReplaceOrAdd ( "agent.config.auth.serveraddress" , registry . Address ) ;
149
+ this . document . ReplaceOrAdd ( "agent.config.auth.username" , registry . Username ) ;
150
+ this . document . ReplaceOrAdd ( "agent.config.auth.password" , registry . Password ) ;
154
151
}
155
152
}
156
153
157
154
public void SetDeviceHostname ( string value )
158
155
{
159
- this . config . Document . ReplaceOrAdd ( "hostname" , value ) ;
156
+ this . document . ReplaceOrAdd ( "hostname" , value ) ;
157
+ }
158
+
159
+ public void SetDeviceHomedir ( string value )
160
+ {
161
+ this . document . ReplaceOrAdd ( "homedir" , value ) ;
160
162
}
161
163
162
164
public void SetParentHostname ( string value )
163
165
{
164
- this . config . Document . ReplaceOrAdd ( "parent_hostname" , value ) ;
166
+ this . document . ReplaceOrAdd ( "parent_hostname" , value ) ;
167
+ }
168
+
169
+ public void SetMobyRuntimeUri ( string value )
170
+ {
171
+ this . document . ReplaceOrAdd ( "moby_runtime.uri" , value ) ;
172
+ this . document . ReplaceOrAdd ( "moby_runtime.network" , "azure-iot-edge" ) ;
165
173
}
166
174
167
175
public void SetConnectSockets ( string workloadUri , string managementUri )
168
176
{
169
- this . config . Document . ReplaceOrAdd ( "connect.workload_uri" , workloadUri ) ;
170
- this . config . Document . ReplaceOrAdd ( "connect.management_uri" , managementUri ) ;
177
+ this . document . ReplaceOrAdd ( "connect.workload_uri" , workloadUri ) ;
178
+ this . document . ReplaceOrAdd ( "connect.management_uri" , managementUri ) ;
171
179
}
172
180
173
181
public void SetListenSockets ( string workloadUri , string managementUri )
174
182
{
175
- this . config . Document . ReplaceOrAdd ( "listen.workload_uri" , workloadUri ) ;
176
- this . config . Document . ReplaceOrAdd ( "listen.management_uri" , managementUri ) ;
183
+ this . document . ReplaceOrAdd ( "listen.workload_uri" , workloadUri ) ;
184
+ this . document . ReplaceOrAdd ( "listen.management_uri" , managementUri ) ;
177
185
}
178
186
179
187
public void SetCertificates ( CaCertificates certs )
180
188
{
181
- if ( ! File . Exists ( certs . CertificatePath ) )
182
- {
183
- throw new InvalidOperationException ( $ "{ certs . CertificatePath } does not exist") ;
184
- }
185
-
186
- if ( ! File . Exists ( certs . KeyPath ) )
187
- {
188
- throw new InvalidOperationException ( $ "{ certs . KeyPath } does not exist") ;
189
- }
190
-
191
- if ( ! File . Exists ( certs . TrustedCertificatesPath ) )
192
- {
193
- throw new InvalidOperationException ( $ "{ certs . TrustedCertificatesPath } does not exist") ;
194
- }
195
-
196
- this . config . Document . ReplaceOrAdd ( "edge_ca.cert" , "file://" + certs . CertificatePath ) ;
197
- this . config . Document . ReplaceOrAdd ( "edge_ca.pk" , "file://" + certs . KeyPath ) ;
198
- this . config . Document . ReplaceOrAdd ( "trust_bundle_cert" , "file://" + certs . TrustedCertificatesPath ) ;
189
+ this . document . ReplaceOrAdd ( "edge_ca.cert" , "file://" + certs . CertificatePath ) ;
190
+ this . document . ReplaceOrAdd ( "edge_ca.pk" , "file://" + certs . KeyPath ) ;
191
+ this . document . ReplaceOrAdd ( "trust_bundle_cert" , "file://" + certs . TrustedCertificatesPath ) ;
199
192
}
200
193
201
194
public async Task UpdateAsync ( CancellationToken token )
202
195
{
203
- await File . WriteAllTextAsync ( this . config . ConfigPath , this . config . Document . ToString ( ) ) ;
204
- // Serilog.Log.Information(await File.ReadAllTextAsync(path));
196
+ await File . WriteAllTextAsync ( this . path , this . document . ToString ( ) ) ;
205
197
}
206
198
}
207
199
}
0 commit comments