PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

CredentialInfo usability enhancements

Open ThomasNieto opened this issue 2 years ago • 3 comments

Summary of the new feature / enhancement

The CredentialInfo parameter currently requires the user to create a PSCredentialInfo object in order to pass the values to the cmdlet. This can create some usability barriers since its an extra hoop for users to get the data in the desired format/object. From what I can tell the user only needs to supply the VaultName and SecretName.

This can be simplified in a few different ways:

  • Replace CredentialInfo parameter with separate Vault and Secret parameters
  • Allow CredentialInfo to accept a hashtable @{ VaultName = 'SecretStore'; SecretName = 'PSGet' } by using a ArgumentTransformation attribute.

Proposed technical implementation details (optional)

class PSCredentialInfoTransformAttribute : ArgumentTransformationAttribute
    {
        private const string VaultName = "VaultName";
        private const string SecretName = "SecretName";
        
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            if (inputData is Hashtable)
            {
                var ht = inputData as Hashtable;

                if (ht.ContainsKey(VaultName) && ht.ContainsKey(SecretName))
                {
                    return new PSCredentialInfo(ht[VaultName], ht[SecretName]);
                }
                else
                {
                    throw new ArgumentTransformationMetadataException();
                }
            }
            else if (inputData is PSCredentialInfo)
            {
                return inputData;
            }
            else
            {
                throw new ArgumentTransformationMetadataException();
            }
        }
    }

ThomasNieto avatar Jun 20 '22 05:06 ThomasNieto

@ThomasNieto thanks for this detailed suggestion, there's still some work we aim to do with CredentialInfo so we can consider incorporating this in then. Thank you!

anamnavi avatar Jun 23 '22 18:06 anamnavi

Hi @ThomasNieto would you be interested in putting in a PR for the ArgumentTransformation? If not, we can add this in, but figured I'd ask you first :smiley:

alerickson avatar Jul 14 '22 22:07 alerickson

@alerickson yeah I can.

ThomasNieto avatar Jul 19 '22 20:07 ThomasNieto