From db3f9c9955b6848d320eede7ed415ca2b11d27a8 Mon Sep 17 00:00:00 2001 From: stack72 Date: Fri, 22 Dec 2023 23:14:05 +0000 Subject: [PATCH] fix(si-pkg): Ensure we carry the secrets to leaf functions This means we can keep the toggle when a qualification requires secrets --- lib/si-pkg/src/node/leaf_function.rs | 17 +++++++++++++++-- lib/si-pkg/src/pkg/leaf_function.rs | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/si-pkg/src/node/leaf_function.rs b/lib/si-pkg/src/node/leaf_function.rs index cf3d7a961c..16db7dd1b0 100644 --- a/lib/si-pkg/src/node/leaf_function.rs +++ b/lib/si-pkg/src/node/leaf_function.rs @@ -4,8 +4,8 @@ use std::{ }; use object_tree::{ - read_key_value_line, write_key_value_line, GraphError, NodeChild, NodeKind, NodeWithChildren, - ReadBytes, WriteBytes, + read_key_value_line, read_key_value_line_opt, write_key_value_line, GraphError, NodeChild, + NodeKind, NodeWithChildren, ReadBytes, WriteBytes, }; use crate::{LeafFunctionSpec, LeafInputLocation, LeafKind}; @@ -15,6 +15,7 @@ use super::{read_common_fields, write_common_fields, PkgNode}; const FUNC_UNIQUE_ID_STR: &str = "func_unique_id"; const LEAF_KIND_STR: &str = "leaf_kind"; const INPUT_DOMAIN_STR: &str = "input_domain"; +const INPUT_SECRET_STR: &str = "input_secret"; const INPUT_DELETED_AT_STR: &str = "input_deleted_at"; const INPUT_CODE_STR: &str = "input_code"; const INPUT_RESOURCE_STR: &str = "input_resource"; @@ -25,6 +26,7 @@ pub struct LeafFunctionNode { pub leaf_kind: LeafKind, pub input_code: bool, pub input_deleted_at: bool, + pub input_secret: bool, pub input_domain: bool, pub input_resource: bool, pub unique_id: Option, @@ -39,6 +41,7 @@ impl WriteBytes for LeafFunctionNode { write_key_value_line(writer, INPUT_DOMAIN_STR, self.input_domain)?; write_key_value_line(writer, INPUT_DELETED_AT_STR, self.input_deleted_at)?; write_key_value_line(writer, INPUT_RESOURCE_STR, self.input_resource)?; + write_key_value_line(writer, INPUT_SECRET_STR, self.input_secret)?; write_common_fields(writer, self.unique_id.as_deref(), self.deleted)?; @@ -65,11 +68,20 @@ impl ReadBytes for LeafFunctionNode { let (unique_id, deleted) = read_common_fields(reader)?; + let input_secret; + let maybe_secret = read_key_value_line_opt(reader, INPUT_SECRET_STR)?; + if let Some(secret) = maybe_secret { + input_secret = bool::from_str(secret.as_str()).map_err(GraphError::parse)?; + } else { + input_secret = false + } + Ok(Some(Self { func_unique_id, leaf_kind, input_code, input_domain, + input_secret, input_deleted_at, input_resource, unique_id, @@ -93,6 +105,7 @@ impl NodeChild for LeafFunctionSpec { input_resource: self.inputs.contains(&LeafInputLocation::Resource), unique_id: self.unique_id.to_owned(), deleted: self.deleted, + input_secret: self.inputs.contains(&LeafInputLocation::Secrets), }), vec![], ) diff --git a/lib/si-pkg/src/pkg/leaf_function.rs b/lib/si-pkg/src/pkg/leaf_function.rs index 96c4bb5b7d..f91cd25460 100644 --- a/lib/si-pkg/src/pkg/leaf_function.rs +++ b/lib/si-pkg/src/pkg/leaf_function.rs @@ -33,7 +33,7 @@ impl<'a> SiPkgLeafFunction<'a> { return Err(SiPkgError::UnexpectedPkgNodeType( PkgNode::LEAF_FUNCTION_KIND_STR, unexpected.node_kind_str(), - )) + )); } }; @@ -50,6 +50,9 @@ impl<'a> SiPkgLeafFunction<'a> { if node.input_deleted_at { inputs.push(LeafInputLocation::DeletedAt); } + if node.input_secret { + inputs.push(LeafInputLocation::Secrets); + } Ok(Self { func_unique_id: node.func_unique_id,