public static async Task <Agent> Create(IConfigSource configSource, IPlanner planner, IPlanRunner planRunner, IReporter reporter, IModuleIdentityLifecycleManager moduleIdentityLifecycleManager, IEnvironmentProvider environmentProvider, IEntityStore <string, string> configStore, ISerde <DeploymentConfigInfo> deploymentConfigInfoSerde, IEncryptionProvider encryptionProvider) { Preconditions.CheckNotNull(deploymentConfigInfoSerde, nameof(deploymentConfigInfoSerde)); Preconditions.CheckNotNull(configStore, nameof(configStore)); Option <DeploymentConfigInfo> deploymentConfigInfo = Option.None <DeploymentConfigInfo>(); try { Option <string> deploymentConfigInfoJson = await Preconditions.CheckNotNull(configStore, nameof(configStore)).Get(StoreConfigKey); await deploymentConfigInfoJson.ForEachAsync(async json => { string decryptedJson = await encryptionProvider.DecryptAsync(json); deploymentConfigInfo = Option.Some(deploymentConfigInfoSerde.Deserialize(decryptedJson)); }); } catch (Exception ex) when(!ex.IsFatal()) { Events.ErrorDeserializingConfig(ex); } var agent = new Agent(configSource, environmentProvider, planner, planRunner, reporter, moduleIdentityLifecycleManager, configStore, deploymentConfigInfo.GetOrElse(DeploymentConfigInfo.Empty), deploymentConfigInfoSerde, encryptionProvider); return(agent); }
static async Task <DeploymentConfigInfo> ReadFromDisk(string path, ISerde <DeploymentConfigInfo> serde) { string json = await DiskFile.ReadAllAsync(path); DeploymentConfigInfo deploymentConfig = serde.Deserialize(json); return(deploymentConfig); }