Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sign certificate functionality of PKI secret engine. #192

Merged
merged 3 commits into from
Jun 5, 2021

Conversation

sj-lt
Copy link
Contributor

@sj-lt sj-lt commented Jun 4, 2021

PKI secret engine sign certificate endpoint implementation.

… CertificateRequestOptions for PKI engine. Added example in README.md and small note in CHANGELOG.md.
Checker.NotNull(signCertificatesRequestOptions, "signCertificatesRequestOptions");

var result = await _polymath.MakeVaultApiRequest<Secret<SignedCertificateData>>(pkiBackendMountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.PKI, "/sign/" + pkiRoleName, HttpMethod.Post, signCertificatesRequestOptions, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext);
result.Data.CertificateFormat = signCertificatesRequestOptions.CertificateFormat;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a null check on result.Data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's assigned as in GetCredentialsAsync function. Thought that there will be some exception, error code from Api if there will be no data send. For my purpose i don't even need that CertificateFormat Assigned cause as a caller you already know it.

[JsonProperty("csr")]
public string Csr { get; set; }

/// <summary>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this. redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you right. Removed Abstract class and created separate classes for both endpoints so this one is fixed too.

Copy link
Owner

@rajanadar rajanadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor

/// <summary>
/// Represents the Certificate request options.
/// </summary>
public abstract class AbstractCertificateRequestOptions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please replicate the class for your need and leave the original POCO intact?

For payload classes, I am deliberately avoiding inheritance to decouple them.

/// <summary>
/// Initializes a new instance of the <see cref="CertificateCredentialsRequestOptions"/> class.
/// </summary>
public CertificateCredentialsRequestOptions()
public CertificateCredentialsRequestOptions() : base()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for base() right?

Checker.NotNull(signCertificatesRequestOptions, "signCertificatesRequestOptions");

var result = await _polymath.MakeVaultApiRequest<Secret<SignedCertificateData>>(pkiBackendMountPoint ?? _polymath.VaultClientSettings.SecretsEngineMountPoints.PKI, "/sign/" + pkiRoleName, HttpMethod.Post, signCertificatesRequestOptions, wrapTimeToLive: wrapTimeToLive).ConfigureAwait(_polymath.VaultClientSettings.ContinueAsyncTasksOnCapturedContext);
result.Data.CertificateFormat = signCertificatesRequestOptions.CertificateFormat;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is not marked with JsonIgnore... Either we should let json set it, or if we are explicitly setting it, it should be marked with json-ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CertificateFormat property is marked as JsonIgnore in AbstractCertificateData class. Or maybe I am referring to wrong property?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. i was looking at the request poco by mistake.

…tracted details to SignCertificateRequestOptions class
@sj-lt sj-lt requested a review from rajanadar June 5, 2021 13:03
@rajanadar rajanadar merged commit f6f24ea into rajanadar:master Jun 5, 2021
@rajanadar
Copy link
Owner

thanks @slutkiewicz for the pr and for using the library

@rajanadar
Copy link
Owner

i'll get this published within 7 days max. maybe faster.

@rajanadar
Copy link
Owner

it was faster. @slutkiewicz Your fix is published:

https://www.nuget.org/packages/VaultSharp/1.6.2.3

@rajanadar rajanadar linked an issue Jun 6, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PKI secret engine sign certificate endpoint
2 participants