diff --git a/rust-connector-sdk/src/secret.rs b/rust-connector-sdk/src/secret.rs index 5ffb6bcd..e15d9826 100644 --- a/rust-connector-sdk/src/secret.rs +++ b/rust-connector-sdk/src/secret.rs @@ -1,22 +1,42 @@ -use schemars::{self, JsonSchema}; +use schemars::{self, schema::Schema, JsonSchema}; use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)] #[serde(rename_all = "camelCase")] #[schemars(title = "SecretValue")] /// Either a literal string or a reference to a Hasura secret -pub enum SecretValue { +pub enum SecretValueImpl { Value(String), StringValueFromSecret(String), } -pub fn secretable_value_reference( - _gen: &mut schemars::gen::SchemaGenerator, -) -> schemars::schema::Schema { - schemars::schema::Schema::Object(schemars::schema::SchemaObject { - reference: Some("https://raw.githubusercontent.com/hasura/ndc-hub/main/rust-connector-sdk/tests/json_schema/secret_value.jsonschema".into()), - ..Default::default() - }) +/// Use this type to refer to secret strings within a +/// connector's configuration types. For example, a connection +/// string which might contain a password should be configured +/// using this type. +/// +/// This marker type indicates that a value should be configured +/// from secrets drawn from a secret store. +pub struct SecretValue(SecretValueImpl); + +impl JsonSchema for SecretValue { + fn schema_name() -> String { + SecretValueImpl::schema_name() + } + + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + let mut s = SecretValueImpl::json_schema(gen); + if let Schema::Object(o) = &mut s { + if let Some(m) = &mut o.metadata { + m.id = Some(Self::schema_id().into()); + } + } + s + } + + fn schema_id() -> std::borrow::Cow<'static, str> { + "hasura.io/SecretValue".into() + } } #[cfg(test)] diff --git a/rust-connector-sdk/tests/json_schema/secret_value.jsonschema b/rust-connector-sdk/tests/json_schema/secret_value.jsonschema index 92bddad8..507aed4e 100644 --- a/rust-connector-sdk/tests/json_schema/secret_value.jsonschema +++ b/rust-connector-sdk/tests/json_schema/secret_value.jsonschema @@ -1,5 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "hasura.io/SecretValue", "title": "SecretValue", "description": "Either a literal string or a reference to a Hasura secret", "oneOf": [