Пример #1
0
        public override void ExecuteCmdlet()
        {
            if (!SharedTokenCacheProvider.SupportCachePersistence(out string message))
            {
                WriteWarning(Resources.TokenCacheEncryptionNotSupportedWithFallback);
            }

            if (MyInvocation.BoundParameters.ContainsKey(nameof(Scope)) && Scope == ContextModificationScope.Process)
            {
                ConfirmAction("Autosave the context in the current session", "Current session", () =>
                {
                    ContextAutosaveSettings settings = null;
                    AzureSession.Modify((session) => EnableAutosave(session, false, out settings));
                    ProtectedProfileProvider.InitializeResourceManagerProfile(true);
                    WriteObject(settings);
                });
            }
            else
            {
                ConfirmAction("Always autosave the context for the current user", "Current user",
                              () =>
                {
                    ContextAutosaveSettings settings = null;
                    AzureSession.Modify((session) => EnableAutosave(session, true, out settings));
                    ProtectedProfileProvider.InitializeResourceManagerProfile(true);
                    WriteObject(settings);
                });
            }
        }
Пример #2
0
        /// <summary>
        /// Initialize the profile provider based on the autosave setting
        /// </summary>
        internal void InitializeProfileProvider(bool useAutoSaveProfile = false)
        {
#if DEBUG
            if (!TestMockSupport.RunningMocked)
            {
#endif
            if (useAutoSaveProfile)
            {
                ProtectedProfileProvider.InitializeResourceManagerProfile();
            }
            else
            {
                switch (GetContextModificationScope())
                {
                case ContextModificationScope.Process:
                    ResourceManagerProfileProvider.InitializeResourceManagerProfile();
                    break;

                case ContextModificationScope.CurrentUser:
                    ProtectedProfileProvider.InitializeResourceManagerProfile();
                    break;
                }
            }
#if DEBUG
        }

        else
        {
            ResourceManagerProfileProvider.InitializeResourceManagerProfile();
        }
#endif
        }
        /// <summary>
        /// Initialize the profile provider based on the autosave setting
        /// </summary>
        internal bool InitializeProfileProvider(bool useAutoSaveProfile = false)
        {
#if DEBUG
            if (!TestMockSupport.RunningMocked)
            {
#endif
            if (useAutoSaveProfile)
            {
                try
                {
                    ProtectedProfileProvider.InitializeResourceManagerProfile();
                }
                catch (SystemException e)
                {
                    if (!(e is IOException) && !(e is UnauthorizedAccessException))
                    {
                        throw e;
                    }
                    WriteInitializationWarnings(string.Format(Resources.ProfileFileNotAccessible, e.Message));
                    ResourceManagerProfileProvider.InitializeResourceManagerProfile(true);
                }
            }

            if (null == AzureRmProfileProvider.Instance)
            {
                switch (GetContextModificationScope())
                {
                case ContextModificationScope.Process:
                    ResourceManagerProfileProvider.InitializeResourceManagerProfile();
                    break;

                case ContextModificationScope.CurrentUser:
                    ProtectedProfileProvider.InitializeResourceManagerProfile();
                    break;
                }
            }
#if DEBUG
        }

        else
        {
            ResourceManagerProfileProvider.InitializeResourceManagerProfile();
        }
#endif
            return(AzureRmProfileProvider.Instance is ProtectedProfileProvider);
        }
        /// <summary>
        /// Initialize the profile provider based on the autosave setting
        /// </summary>
        internal bool InitializeProfileProvider(bool useAutoSaveProfile = false)
        {
#if DEBUG
            if (!TestMockSupport.RunningMocked)
            {
#endif
            if (useAutoSaveProfile)
            {
                try
                {
                    ProtectedProfileProvider.InitializeResourceManagerProfile();
                }
                catch (Exception e)
                {
                    //Likely the exception is related to IO or permission, fallback to Process save mode
                    WriteInitializationWarnings(string.Format(Resources.ProfileFileNotAccessible, e.Message));
                    ResourceManagerProfileProvider.InitializeResourceManagerProfile(true);
                }
            }

            if (null == AzureRmProfileProvider.Instance)
            {
                switch (GetContextModificationScope())
                {
                case ContextModificationScope.Process:
                    ResourceManagerProfileProvider.InitializeResourceManagerProfile();
                    break;

                case ContextModificationScope.CurrentUser:
                    ProtectedProfileProvider.InitializeResourceManagerProfile();
                    break;
                }
            }
#if DEBUG
        }

        else
        {
            ResourceManagerProfileProvider.InitializeResourceManagerProfile();
        }
#endif
            return(AzureRmProfileProvider.Instance is ProtectedProfileProvider);
        }
Пример #5
0
        public LoginTests()
        {
            AzureSessionInitializer.InitializeAzureSession();
            ProtectedProfileProvider.InitializeResourceManagerProfile();

            ContextAutosaveSettings settings = null;

            AzureSession.Modify((session) => EnableAutosave(session, true, out settings));
            ProtectedProfileProvider.InitializeResourceManagerProfile(true);

            _cmdlet                       = new ConnectAccount();
            _cmdlet.TenantId              = _tenantId;
            _cmdlet.SubscriptionId        = _subscriptionId;
            _cmdlet.SubscriptionName      = _subscriptionName;
            _cmdlet.UserName              = _userName;
            _cmdlet.Password              = _password;
            _cmdlet.ApplicationId         = _applicationId;
            _cmdlet.CertificateThumbprint = _certificateThumbprint;
            _cmdlet.CommandRuntime        = new MockCommandRuntime();
        }
Пример #6
0
        public LoginTests()
        {
            AzureSessionInitializer.InitializeAzureSession();
            ProtectedProfileProvider.InitializeResourceManagerProfile();
            IServicePrincipalKeyStore keyStore = new AzureRmServicePrincipalKeyStore(AzureRmProfileProvider.Instance.Profile);

            AzureSession.Instance.RegisterComponent(ServicePrincipalKeyStore.Name, () => keyStore);

            ContextAutosaveSettings settings = null;

            AzureSession.Modify((session) => EnableAutosave(session, true, out settings));
            ProtectedProfileProvider.InitializeResourceManagerProfile(true);

            _cmdlet                       = new ConnectAccount();
            _cmdlet.TenantId              = _tenantId;
            _cmdlet.SubscriptionId        = _subscriptionId;
            _cmdlet.SubscriptionName      = _subscriptionName;
            _cmdlet.UserName              = _userName;
            _cmdlet.Password              = _password;
            _cmdlet.ApplicationId         = _applicationId;
            _cmdlet.CertificateThumbprint = _certificateThumbprint;
            _cmdlet.CommandRuntime        = new MockCommandRuntime();
        }
 public override void ExecuteCmdlet()
 {
     if (MyInvocation.BoundParameters.ContainsKey(nameof(Scope)) && Scope == ContextModificationScope.Process)
     {
         ConfirmAction("Autosave the context in the current session", "Current session", () =>
         {
             ContextAutosaveSettings settings = null;
             AzureSession.Modify((session) => EnableAutosave(session, false, out settings));
             ProtectedProfileProvider.InitializeResourceManagerProfile(true);
             WriteObject(settings);
         });
     }
     else
     {
         ConfirmAction("Always autosave the context for the current user", "Current user",
                       () =>
         {
             ContextAutosaveSettings settings = null;
             AzureSession.Modify((session) => EnableAutosave(session, true, out settings));
             ProtectedProfileProvider.InitializeResourceManagerProfile(true);
             WriteObject(settings);
         });
     }
 }
Пример #8
0
        //This method may throw exception because of permission issue, exception should be handled from caller
        private static IAzureContextContainer GetAzureContextContainer()
        {
            var provider = new ProtectedProfileProvider();

            return(provider.Profile);
        }