async Task OnExecuteAsync()

in smoke/IotEdgeQuickstart/Program.cs [196:346]


        async Task<int> OnExecuteAsync()
        {
            try
            {
                string address = this.RegistryAddress;
                string user = this.RegistryUser;
                string password = this.RegistryPassword;

                if (address != null && user == null && password == null)
                {
                    (user, password) = await this.RegistryArgsFromSecret(address);
                }

                Option<RegistryCredentials> credentials = address != null && user != null && password != null
                    ? Option.Some(new RegistryCredentials(address, user, password))
                    : Option.None<RegistryCredentials>();

                (bool useProxy, string proxyUrl) = this.Proxy;
                Option<string> proxy = useProxy
                    ? Option.Some(proxyUrl)
                    : Option.Maybe(Environment.GetEnvironmentVariable("https_proxy"));

                (bool overrideUpstreamProtocol, UpstreamProtocolType upstreamProtocol) = this.UpstreamProtocol;
                Option<UpstreamProtocolType> upstreamProtocolOption = overrideUpstreamProtocol
                    ? Option.Some(upstreamProtocol)
                    : Option.None<UpstreamProtocolType>();

                IBootstrapper bootstrapper;
                switch (this.BootstrapperType)
                {
                    case BootstrapperType.Iotedged:
                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                        {
                            throw new NotImplementedException("Windows support is not available");
                        }
                        else
                        {
                            (bool useHttp, string hostname) = this.UseHttp;
                            Option<HttpUris> uris = useHttp
                                ? Option.Some(string.IsNullOrEmpty(hostname) ? new HttpUris() : new HttpUris(hostname))
                                : Option.None<HttpUris>();

                            UriSocks socks = new UriSocks(this.ConnectManagementUri, this.ConnectWorkloadUri, this.ListenManagementUri, this.ListenWorkloadUri);
                            ILinuxPackageInstall installMethod;
                            if (!this.BypassEdgeInstallation)
                            {
                                if (!string.IsNullOrEmpty(this.PackageType) && this.PackageType.ToLower().Equals("rpm"))
                                {
                                    installMethod = new LinuxPackageInstallRPM(this.BootstrapperArchivePath);
                                }
                                else
                                {
                                    installMethod = new LinuxPackageInstallDep(this.BootstrapperArchivePath);
                                }
                            }
                            else
                            {
                                installMethod = new LinuxPackageNonInstall();
                            }

                            bootstrapper = new IotedgedLinux(credentials, uris, socks, proxy, upstreamProtocolOption, this.OverwritePackages, installMethod);
                        }

                        break;
                    default:
                        throw new ArgumentException("Unknown BootstrapperType");
                }

                string connectionString = this.IotHubConnectionString ??
                                          await SecretsHelper.GetSecretFromConfigKey("iotHubConnStrKey");

                Option<DPSAttestation> dpsAttestation = Option.None<DPSAttestation>();
                if (!string.IsNullOrEmpty(this.DPSScopeId))
                {
                    if (string.IsNullOrEmpty(this.DPSEndpoint))
                    {
                        throw new ArgumentException("DPS Endpoint cannot be null or empty if a DPS is being used");
                    }

                    if (string.IsNullOrEmpty(this.DPSMasterSymmetricKey))
                    {
                        if (string.IsNullOrEmpty(this.DeviceIdentityCert) || !File.Exists(this.DeviceIdentityCert))
                        {
                            throw new ArgumentException("Device identity certificate path is invalid");
                        }

                        if (string.IsNullOrEmpty(this.DeviceIdentityPk) || !File.Exists(this.DeviceIdentityPk))
                        {
                            throw new ArgumentException("Device identity private key is invalid");
                        }

                        dpsAttestation = Option.Some(new DPSAttestation(this.DPSEndpoint, this.DPSScopeId, Option.None<string>(), this.DeviceIdentityCert, this.DeviceIdentityPk));
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.DeviceIdentityCert) || !string.IsNullOrEmpty(this.DeviceIdentityPk))
                        {
                            throw new ArgumentException("Both device identity certificate and DPS symmetric key cannot be set");
                        }

                        string deviceKey = this.ComputeDerivedSymmetricKey(Convert.FromBase64String(this.DPSMasterSymmetricKey), this.DPSRegistrationId);
                        dpsAttestation = Option.Some(new DPSAttestation(this.DPSEndpoint, this.DPSScopeId, this.DPSRegistrationId, deviceKey));
                    }
                }

                string endpoint = this.EventHubCompatibleEndpointWithEntityPath ??
                                  await SecretsHelper.GetSecretFromConfigKey("eventHubConnStrKey");

                Option<string> deployment = this.DeploymentFileName != null ? Option.Some(this.DeploymentFileName) : Option.None<string>();

                Option<string> twinTest = this.TwinTestFileName != null ? Option.Some(this.TwinTestFileName) : Option.None<string>();

                string tag = this.ImageTag ?? "1.0";

                var test = new Quickstart(
                    bootstrapper,
                    credentials,
                    connectionString,
                    endpoint,
                    this.UpstreamProtocol.Item2,
                    proxy,
                    tag,
                    this.DeviceId,
                    this.EdgeHostname,
                    string.IsNullOrWhiteSpace(this.ParentHostname) ? Option.None<string>() : Option.Some(this.ParentHostname),
                    string.IsNullOrWhiteSpace(this.ParentEdgeDevice) ? Option.None<string>() : Option.Some(this.ParentEdgeDevice),
                    this.LeaveRunning,
                    this.NoVerify,
                    this.BypassEdgeInstallation,
                    this.VerifyDataFromModule,
                    deployment,
                    twinTest,
                    this.DeviceCaCert,
                    this.DeviceCaPk,
                    this.DeviceCaCerts,
                    this.OptimizeForPerformance,
                    this.InitializeWithAgentArtifact,
                    this.RuntimeLogLevel,
                    this.CleanUpExistingDeviceOnSuccess,
                    dpsAttestation);
                await test.RunAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return 1;
            }

            Console.WriteLine("Success!");
            return 0;
        }