Exemplo n.º 1
0
        protected VmInstanceConnectionSettings ApplyDefaults(ZoneConnectionSettings zoneSettings)
        {
            var prototype = new VmInstanceConnectionSettings(this.ProjectId, this.InstanceName);

            ApplyOverlay(prototype, zoneSettings, this);
            return(prototype);
        }
Exemplo n.º 2
0
        public VmInstanceConnectionSettings OverlayBy(VmInstanceConnectionSettings instanceSettings)
        {
            var result = VmInstanceConnectionSettings.CreateNew(
                instanceSettings.ProjectId,
                instanceSettings.InstanceName);

            ApplyOverlay(result, this, instanceSettings);
            return(result);
        }
Exemplo n.º 3
0
 public void SetVmInstanceSettings(VmInstanceConnectionSettings settings)
 {
     using (var key = this.projectRepository.OpenRegistryKey(
                settings.ProjectId,
                VmPrefix + settings.InstanceName,
                true))
     {
         settings.Save(key);
     }
 }
Exemplo n.º 4
0
        //-------------------------------------------------------------------------
        // Create.
        //-------------------------------------------------------------------------

        public static VmInstanceConnectionSettings FromKey(
            string projectId,
            string instanceName,
            RegistryKey registryKey)
        {
            var settings = new VmInstanceConnectionSettings(projectId, instanceName);

            settings.InitializeFromKey(registryKey);
            return(settings);
        }
Exemplo n.º 5
0
        //---------------------------------------------------------------------
        // Virtual Machines.
        //---------------------------------------------------------------------

        public VmInstanceConnectionSettings GetVmInstanceSettings(string projectId, string instanceName)
        {
            using (var key = this.projectRepository.OpenRegistryKey(
                       projectId,
                       VmPrefix + instanceName,
                       true))
            {
                return(VmInstanceConnectionSettings.FromKey(
                           projectId,
                           instanceName,
                           key));
            }
        }
Exemplo n.º 6
0
        private async Task ConnectInstanceAsync(
            InstanceLocator instanceRef,
            VmInstanceConnectionSettings settings)
        {
            var tunnel = await this.jobService.RunInBackground(
                new JobDescription(
                    $"Opening Cloud IAP tunnel to {instanceRef.Name}...",
                    JobUserFeedbackType.BackgroundFeedback),
                async token =>
            {
                try
                {
                    var destination = new TunnelDestination(
                        instanceRef,
                        (ushort)settings.RdpPort.IntValue);

                    // Give IAP the same timeout for probing as RDP itself.
                    // Note that the timeouts are not additive.
                    var timeout = TimeSpan.FromSeconds(settings.ConnectionTimeout.IntValue);

                    return(await this.tunnelBrokerService.ConnectAsync(
                               destination,
                               new SameProcessRelayPolicy(),
                               timeout)
                           .ConfigureAwait(false));
                }
                catch (NetworkStreamClosedException e)
                {
                    throw new IapRdpConnectionFailedException(
                        "Connecting to the instance failed. Make sure that you have " +
                        "configured your firewall rules to permit Cloud IAP access " +
                        $"to {instanceRef.Name}",
                        HelpTopics.CreateIapFirewallRule,
                        e);
                }
                catch (UnauthorizedException)
                {
                    throw new IapRdpConnectionFailedException(
                        "You are not authorized to connect to this VM instance.\n\n" +
                        $"Verify that the Cloud IAP API is enabled in the project {instanceRef.ProjectId} " +
                        "and that your user has the 'IAP-secured Tunnel User' role.",
                        HelpTopics.IapAccess);
                }
            }).ConfigureAwait(true);

            this.remoteDesktopService.Connect(
                instanceRef,
                "localhost",
                (ushort)tunnel.LocalPort,
                settings);
        }
Exemplo n.º 7
0
        public async Task ActivateOrConnectInstanceAsync(IapRdpUrl url)
        {
            if (this.remoteDesktopService.TryActivate(url.Instance))
            {
                // RDP session was active, nothing left to do.
                return;
            }

            VmInstanceConnectionSettings settings;

            if (this.projectExplorer.TryFindNode(url.Instance)
                is IProjectExplorerVmInstanceNode vmNode)
            {
                // We have a full set of settings for this VM, so use that as basis
                settings = (VmInstanceConnectionSettings)
                           this.settingsService.GetConnectionSettings(vmNode);

                // Apply parameters from URL on top.
                settings.ApplyUrlQuery(url.Parameters);
            }
            else
            {
                settings = VmInstanceConnectionSettings.FromUrl(url);
            }

            await this.credentialPrompt.ShowCredentialsPromptAsync(
                this.window,
                url.Instance,
                settings,
                false)
            .ConfigureAwait(true);

            await ConnectInstanceAsync(
                url.Instance,
                settings)
            .ConfigureAwait(true);
        }