`Get-VCFCertificateCSR` cmdlet output needs newline character (\n) escapes
jeffwongcf opened this issue · 6 comments
Code of Conduct
- I have read and agree to the project's Code of Conduct.
PowerVCF
2.3.0.1004
VMware Cloud Foundation
5.0
PowerShell
5.1
Guest Operating System
Windows Server 2019/2022 Standard
Environment Details
Reproducible in any VCF 5.0 environment.
Description
In the cmdlet Get-VCFCertificateCSR
, the output format is truncated due to newline (\n
) character that is not escaped in the CSR .
Expected Behavior
Raw output equivalent
{
"elements": [
{
"csrEncodedContent": "-----BEGIN CERTIFICATE REQUEST-----\nMIIDKDCCAhACAQAwbjEhMB8GA1UEAwwYdmNlbnRlcjAxYS1tZ210LnNkZGMubGFi\nMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExETAPBgNVBAcMCFNhbiBGcmFuMQ8w\nDQYDVQQKDAZWTXdhcmUxCzAJBgNVBAsMAklUMIIBIjANBgkqhkiG9w0BAQEFAAOC\nAQ8AMIIBCgKCAQEAzXPurDh51XsJmamDf8HShT3FqbXtQnBtUUXVeXPfBbpduxvl\nLsSxQmcy33IqG2pCg3W/76yyDUHvyI3mYfmdPBmTmGuLZveyFaoMz5ytpqn8WnVn\nEOdb9CC7sDkP6QkaCWtyUpj5+dtmQQbVoC5yUEGxNTKSzFSO78y1Um2qxj3uZLIk\nwRUNzaeEoMhy9SkZHqp7YMmTNMLd1NPrl24MxSInqAjm4J8Z0HKzwYnvwnI7Nbf+\nHiGI5+GbgkwCdEJcmYZyBL3SH1MXuElS9A+SXSCK4iAGhqfzOdbMO4WVbiOixCRc\nGzuOu3dHC4lyAF3pbjwl+ect9PG5cwLEOKVhUQIDAQABoHUwcwYJKoZIhvcNAQkO\nMWYwZDALBgNVHQ8EBAMCBeAwNgYDVR0RBC8wLYERc2FtQHZzcGhlcmUubG9jYWyC\nGHZjZW50ZXIwMWEtbWdtdC5zZGRjLmxhYjAdBgNVHQ4EFgQU6BAiR+XyfY7PcXPm\n3o29SIDW3tcwDQYJKoZIhvcNAQELBQADggEBADHiBwTNh7XSqYAdnTbkJYh6hzQJ\naaHwbzuvcob09+loFyGi4snbyAzikGOZHRvGHwoCW9t4W5iVi0mfYZT9LU8u27TJ\nRK8cCnfj40cTzYEI0zo0PUgk7vlfQRJ+Fk+vdtbBqnbhVylEHQjK9PFaXW98bUca\nwQCytYDnJ38seqSznicPiNUNm1dFfE9r7tUK6zC8+lPk7TZEELRFs7PpMgVYrmpt\ny9OStsTEenZJ2hWzHlRtIx/1mQe9G4DHHQcZ5DKg8lFumTZBdV7FXLwkIu4fTp+W\nhJMnV+na+HcPXi0JahAuFeWI779GnWwSedNgcYeYjqvlGQOwX89LwUg+CzQ=\n-----END CERTIFICATE REQUEST-----",
"resource": {
"fqdn": "vcenter01a-mgmt.sddc.lab"
},
"csrDecodedContent": "Subject: CN=vcenter01a-mgmt.sddc.lab, C=US, ST=CA, L=San Fran, O=VMware, OU=IT\n\nPublic Key Algorithm: rsaEncryption\n Public-Key: (2048 bit)\n\nRequested Extensions:\n X509v3 Key Usage: \n Digital Signature, Non Repudiation, Key Encipherment\n X509v3 Subject Alternative Name: \n email:sam@vsphere.local, DNS:vcenter01a-mgmt.sddc.lab\n X509v3 Subject Key Identifier: \n E8:10:22:47:E5:F2:7D:8E:CF:71:73:E6:DE:8D:BD:48:80:D6:DE:D7\n"
}
]
}
Actual Behavior
PS C:\> Get-VCFCertificateCSR -domainName MGMT
csrEncodedContent
-----------------
-----BEGIN CERTIFICATE REQUEST-----...
Steps to Reproduce
Generate a CSR (vCenter Server in my example) and run Get-VCFCertificateCSR
.
Log Fragments and Files
Screenshots
Additional Context
Can I have a chat with reviewer of this bug to learn to check in code?
Potential solution to escape output special characters.
https://stackoverflow.com/questions/42068/how-do-i-handle-newlines-in-json
yeah this works. the elements are returned correctly. Just the output is not formatted correctly by PS cosmetically when there is a \n in the value I guess. I wonder if there is a way to format it nicely in a standard element return output or just document this expectation since the CSR content is expected to contain \n ?
PS C:\> Get-VCFCertificateCSR -domainName mgmt | ConvertTo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HHQcZ5DKg8lFumTZBdV7FXLwkIu4fTp+W\nhJMnV+na+HcPXi0JahAuFeWI779GnWwSedNgcYeYjqvlGQOwX89LwUg+CzQ=\n-----END CERTIFICATE REQUEST-----",
"resource": {
"fqdn": "vcenter01a-mgmt.sddc.lab"
},
"csrDecodedContent": "Subject: CN=vcenter01a-mgmt.sddc.lab, C=US, ST=CA, L=San Fran, O=VMware, OU=IT\n\nPublic Key Algorithm: rsaEncryption\n Public-Key: (2048 bit)\n\nRequested Extensions:\n X509v3 Key Usage: \n Digital Signature, Non Repudiation, Key Encipherment\n X509v3 Subject Alternative Name: \n email:sam@vsphere.local, DNS:vcenter01a-mgmt.sddc.lab\n X509v3 Subject Key Identifier: \n E8:10:22:47:E5:F2:7D:8E:CF:71:73:E6:DE:8D:BD:48:80:D6:DE:D7\n"
}
@jeffwongcf it's pretty simple what you're looking for, PS offers pretty good object manipulation.
Load the data returned by Get-VCFCertificateCSR into a variable and then access the object csrEncodedContent as following:
$vcfCSR = Get-VCFCertificateCsr -domainName MGMT
$vcfCSR.csrEncodedContent
Or, alternatively, call the nested object directly when you're making the call, as following:
$(Get-VCFCertificateCsr -domainName MGMT).csrEncodedContent
@jeffwongcf If you want to contribute a change to the docs to assist with this example just let me know and Incan walk you through the steps.
The docs already denote that the following can be used:
Get-VCFCertificateCsr -domainName sfo-m01 | ConvertTo-Json
'I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.'