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

Add PEM encoded certificate to external api response #5078

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions nexus/db-model/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ impl TryFrom<Certificate> for views::Certificate {
Ok(Self {
identity: cert.identity(),
service: cert.service.try_into()?,
// This is expected to succeed in normal circumstances. Certificates are stored in the
// database with PEM encoding which are essentially bundles of Base64 encoded text.
// The only cases in which this conversion should fail is when our internal database
// representation of the certificate is invalid.
cert: String::from_utf8(cert.cert).map_err(|_| {
Error::internal_error("Certificate is not valid UTF-8")
})?,
})
}
}
3 changes: 3 additions & 0 deletions nexus/types/src/external_api/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ pub struct Project {
pub struct Certificate {
#[serde(flatten)]
pub identity: IdentityMetadata,
/// The service using this certificate
pub service: ServiceUsingCertificate,
/// PEM-formatted string containing public certificate chain
pub cert: String,
}

// IMAGES
Expand Down
12 changes: 11 additions & 1 deletion openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -11021,6 +11021,10 @@
"description": "View of a Certificate",
"type": "object",
"properties": {
"cert": {
"description": "PEM-formatted string containing public certificate chain",
"type": "string"
},
"description": {
"description": "human-readable free-form text about a resource",
"type": "string"
Expand All @@ -11039,7 +11043,12 @@
]
},
"service": {
"$ref": "#/components/schemas/ServiceUsingCertificate"
"description": "The service using this certificate",
"allOf": [
{
"$ref": "#/components/schemas/ServiceUsingCertificate"
}
]
},
"time_created": {
"description": "timestamp when this resource was created",
Expand All @@ -11053,6 +11062,7 @@
}
},
"required": [
"cert",
"description",
"id",
"name",
Expand Down
Loading