Ejemplo n.º 1
0
        protected override void EndProcessing()
        {
            if (LocalCredManStore.ReadObject(
                    name: Name,
                    outObject: out object outObject,
                    out int errorCode))
            {
                WriteObject(
                    sendToPipeline: outObject,
                    enumerateCollection: false);

                return;
            }

            if (errorCode > 0 && errorCode != NativeUtils.ERROR_NOT_FOUND)
            {
                var message = string.Format(CultureInfo.InvariantCulture,
                                            @"Error while retrieving secret from vault {0} : {1}",
                                            VaultName,
                                            LocalCredManStore.GetErrorMessage(errorCode));

                WriteError(
                    new ErrorRecord(
                        new PSInvalidOperationException(message),
                        "CredManVaultGetError",
                        ErrorCategory.InvalidOperation,
                        this));
            }
        }
Ejemplo n.º 2
0
        protected override void EndProcessing()
        {
            if (!LocalCredManStore.DeleteObject(
                    name: Name,
                    out int errorCode))
            {
                var message = string.Format(CultureInfo.InvariantCulture,
                                            @"Error while deleting secret from vault {0} : {1}",
                                            VaultName,
                                            LocalCredManStore.GetErrorMessage(errorCode));

                WriteError(
                    new ErrorRecord(
                        new PSInvalidOperationException(message),
                        "CredManVaultWriteError",
                        ErrorCategory.InvalidOperation,
                        this));
            }
        }
Ejemplo n.º 3
0
        protected override void EndProcessing()
        {
            if (LocalCredManStore.EnumerateObjectInfo(
                    filter: Filter,
                    out KeyValuePair <string, SecretType>[] outObjectInfos,
                    out int errorCode))
            {
                var secretInfoList = new List <SecretInformation>(outObjectInfos.Length);
                foreach (var item in outObjectInfos)
                {
                    secretInfoList.Add(
                        new SecretInformation(
                            name: item.Key,
                            type: item.Value,
                            vaultName: VaultName));
                }

                WriteObject(
                    sendToPipeline: secretInfoList.ToArray(),
                    enumerateCollection: false);

                return;
            }

            if (errorCode > 0 && errorCode != NativeUtils.ERROR_NOT_FOUND)
            {
                var message = string.Format(CultureInfo.InvariantCulture,
                                            @"Error while retrieving secret information from vault {0} : {1}",
                                            VaultName,
                                            LocalCredManStore.GetErrorMessage(errorCode));

                WriteError(
                    new ErrorRecord(
                        new PSInvalidOperationException(message),
                        "CredManVaultGetInfoError",
                        ErrorCategory.InvalidOperation,
                        this));
            }
        }
Ejemplo n.º 4
0
        protected override void EndProcessing()
        {
            var secretName = System.IO.Path.GetRandomFileName();
            var secret     = System.IO.Path.GetRandomFileName();

            // Setting a secret
            var success = LocalCredManStore.WriteObject(
                name: secretName,
                objectToWrite: secret,
                out int errorCode);

            if (!success)
            {
                var message = string.Format(CultureInfo.InvariantCulture,
                                            @"Test-SecretVault failed to write secret on vault {0} with error: {1}",
                                            VaultName, LocalCredManStore.GetErrorMessage(errorCode));
                WriteError(
                    new ErrorRecord(
                        new PSInvalidOperationException(message),
                        errorId: "CredManVaultTestFailWrite",
                        errorCategory: ErrorCategory.InvalidOperation,
                        this));

                WriteObject(success);
                return;
            }

            // Getting secret info
            success = LocalCredManStore.EnumerateObjectInfo(
                filter: secretName,
                out KeyValuePair <string, SecretType>[] outObjectInfos,
                out errorCode);
            if (!success)
            {
                var message = string.Format(CultureInfo.InvariantCulture,
                                            @"Test-SecretVault failed to get secret info on vault {0} with error: {1}",
                                            VaultName, LocalCredManStore.GetErrorMessage(errorCode));
                WriteError(
                    new ErrorRecord(
                        new PSInvalidOperationException(message),
                        errorId: "CredManVaultTestFailReadInfo",
                        errorCategory: ErrorCategory.InvalidOperation,
                        this));
            }

            // Getting secret value
            success = LocalCredManStore.ReadObject(
                name: secretName,
                outObject: out object outObject,
                out errorCode);
            if (!success)
            {
                var message = string.Format(CultureInfo.InvariantCulture,
                                            @"Test-SecretVault failed to get secret value on vault {0} with error: {1}",
                                            VaultName, LocalCredManStore.GetErrorMessage(errorCode));
                WriteError(
                    new ErrorRecord(
                        new PSInvalidOperationException(message),
                        errorId: "CredManVaultTestFailRead",
                        errorCategory: ErrorCategory.InvalidOperation,
                        this));
            }

            // Removing secret
            success = LocalCredManStore.DeleteObject(
                name: secretName,
                out errorCode);
            if (!success)
            {
                var message = string.Format(CultureInfo.InvariantCulture,
                                            @"Test-SecretVault failed to remove secret on vault {0} with error: {1}",
                                            VaultName, LocalCredManStore.GetErrorMessage(errorCode));
                WriteError(
                    new ErrorRecord(
                        new PSInvalidOperationException(message),
                        errorId: "CredManVaultTestFailDelete",
                        errorCategory: ErrorCategory.InvalidOperation,
                        this));
            }

            WriteObject(success);
        }