//not overriding BeginProcessing so resource context validation will happen here

        public override void ExecuteCmdlet()
        {
            try
            {
                List <IscsiConnection> iscsiConnections = null;
                var    currentResourceName = StorSimpleClient.GetResourceContext().ResourceName;
                string deviceIdFinal       = null;
                if (ParameterSetName == StorSimpleCmdletParameterSet.IdentifyByName)
                {
                    var deviceToUse = StorSimpleClient.GetAllDevices().Where(x => x.FriendlyName.Equals(DeviceName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                    if (deviceToUse == null)
                    {
                        throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, currentResourceName, DeviceName));
                    }
                    deviceIdFinal = deviceToUse.DeviceId;
                }
                else
                {
                    deviceIdFinal = DeviceId;
                }

                //verify that this device is configured
                this.VerifyDeviceConfigurationCompleteForDevice(deviceIdFinal);
                iscsiConnections = StorSimpleClient.GetAllIscsiConnections(deviceIdFinal);
                WriteObject(iscsiConnections);
                WriteVerbose(string.Format(Resources.IscsiConnectionGet_StatusMessage, iscsiConnections.Count, (iscsiConnections.Count > 1?"s":string.Empty)));
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
Exemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            try
            {
                var currentContext = StorSimpleClient.GetResourceContext();
                this.WriteObject(currentContext);
                this.WriteVerbose(string.Format(Resources.ResourceContextFound, currentContext.ResourceName, currentContext.ResourceId));
            }

            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            try
            {
                this.WriteVerbose(Resources.ResourceContextInitializeMessage);
                var resCred = StorSimpleClient.GetResourceDetails(ResourceName);
                if (resCred == null)
                {
                    this.WriteVerbose(Resources.NotFoundMessageResource);
                    throw GetGenericException(Resources.NotFoundMessageResource, null);
                }

                StorSimpleClient.SetResourceContext(resCred);
                var deviceInfos = StorSimpleClient.GetAllDevices();
                if (!deviceInfos.Any())
                {
                    StorSimpleClient.ResetResourceContext();
                    throw base.GetGenericException(Resources.DeviceNotRegisteredMessage, null);
                }

                //now check for the key
                if (string.IsNullOrEmpty(RegistrationKey))
                {
                    this.WriteVerbose(Resources.RegistrationKeyNotPassedMessage);
                }
                else
                {
                    this.WriteVerbose(Resources.RegistrationKeyPassedMessage);
                    EncryptionCmdLetHelper.PersistCIK(this, resCred.ResourceId, StorSimpleClient.ParseCIKFromRegistrationKey(RegistrationKey));
                }
                EncryptionCmdLetHelper.ValidatePersistedCIK(this, resCred.ResourceId);
                this.WriteVerbose(Resources.SecretsValidationCompleteMessage);

                this.WriteVerbose(Resources.SuccessMessageSetResourceContext);
                var currentContext = StorSimpleClient.GetResourceContext();
                this.WriteObject(currentContext);
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
        /// <summary>
        /// Helper method that will return an encrypted secret using rakpub.
        /// Fetches CIK from the keystore and uses it to get plaintext rakpub
        /// </summary>
        /// <param name="secret"></param>
        /// <param name="encryptedSecret"></param>
        /// <returns></returns>
        public KeyStoreOperationStatus EncryptSecretWithRakPub(string secret, out string encryptedSecret)
        {
            StorSimpleKeyManager keyManager = StorSimpleClient.GetResourceContext().StorSimpleKeyManager;

            encryptedSecret = null;

            //reading from keystore
            string cik = null;
            KeyStoreOperationStatus status = keyManager.RetrieveCIK(out cik);

            if (status != KeyStoreOperationStatus.RETRIEVE_SUCCESS)
            {
                return(status);
            }

            string decryptedRAKPub = GetPlainTextRAKPub(cik);

            //encrypt secret using RAKPub
            encryptedSecret = CryptoHelper.EncryptSecretRSAPKCS(secret, decryptedRAKPub);

            return(KeyStoreOperationStatus.SUCCESS);
        }