public async Task Configure(string connectionString, string image, string hostname) { Console.WriteLine($"Setting up iotedged with container registry '{this.credentials.Match(c => c.Address, () => "<none>")}'"); const string YamlPath = "/etc/iotedge/config.yaml"; Task <string> text = File.ReadAllTextAsync(YamlPath); var doc = new YamlDocument(await text); doc.Replace("provisioning.device_connection_string", connectionString); doc.Replace("agent.config.image", image); doc.Replace("hostname", hostname); foreach (RegistryCredentials c in this.credentials) { doc.Replace("agent.config.auth.serveraddress", c.Address); doc.Replace("agent.config.auth.username", c.User); doc.Replace("agent.config.auth.password", c.Password); } string result = doc.ToString(); FileAttributes attr = 0; if (File.Exists(YamlPath)) { attr = File.GetAttributes(YamlPath); File.SetAttributes(YamlPath, attr & ~FileAttributes.ReadOnly); } await File.WriteAllTextAsync(YamlPath, result); if (attr != 0) { File.SetAttributes(YamlPath, attr); } }
public async Task Configure(string connectionString, string image, string hostname) { Console.WriteLine($"Setting up iotedged with agent image '{image}'"); const string YamlPath = "/etc/iotedge/config.yaml"; Task <string> text = File.ReadAllTextAsync(YamlPath); var doc = new YamlDocument(await text); doc.Replace("provisioning.device_connection_string", connectionString); doc.Replace("agent.config.image", image); doc.Replace("hostname", hostname); foreach (RegistryCredentials c in this.credentials) { doc.Replace("agent.config.auth.serveraddress", c.Address); doc.Replace("agent.config.auth.username", c.User); doc.Replace("agent.config.auth.password", c.Password); } if (this.httpUris.HasValue) { HttpUris uris = this.httpUris.OrDefault(); doc.Replace("connect.management_uri", uris.ConnectManagement); doc.Replace("connect.workload_uri", uris.ConnectWorkload); doc.Replace("listen.management_uri", uris.ListenManagement); doc.Replace("listen.workload_uri", uris.ListenWorkload); } else { doc.Replace("connect.management_uri", "unix:///var/run/iotedge/mgmt.sock"); doc.Replace("connect.workload_uri", "unix:///var/run/iotedge/workload.sock"); doc.Replace("listen.management_uri", "fd://iotedge.mgmt.socket"); doc.Replace("listen.workload_uri", "fd://iotedge.socket"); } string result = doc.ToString(); FileAttributes attr = 0; if (File.Exists(YamlPath)) { attr = File.GetAttributes(YamlPath); File.SetAttributes(YamlPath, attr & ~FileAttributes.ReadOnly); } await File.WriteAllTextAsync(YamlPath, result); if (attr != 0) { File.SetAttributes(YamlPath, attr); } }