Skip to content

Commit

Permalink
Use
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Oct 18, 2023
1 parent 3726c92 commit 6b55c1d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
40 changes: 30 additions & 10 deletions rust-connector-sdk/src/secret.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit 6b55c1d

Please sign in to comment.