From e1135a1fb1ae63314110caeadbf613b4696527bc Mon Sep 17 00:00:00 2001 From: Bruno Gomes Date: Fri, 14 Jun 2024 16:54:41 -0300 Subject: [PATCH] revert policy marshal type location --- acp/acp_local.go | 10 ++-------- acp/source_hub_client.go | 8 ++++++++ acp/types.go | 9 +++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/acp/acp_local.go b/acp/acp_local.go index 6ab8aa57dd..b62c4a454c 100644 --- a/acp/acp_local.go +++ b/acp/acp_local.go @@ -20,7 +20,6 @@ import ( "github.com/sourcenetwork/acp_core/pkg/runtime" "github.com/sourcenetwork/acp_core/pkg/types" "github.com/sourcenetwork/immutable" - "github.com/valyala/fastjson" ) const localACPStoreName = "local_acp" @@ -108,6 +107,7 @@ func (l *ACPLocal) AddPolicy( ctx context.Context, creatorID string, policy string, + marshalType policyMarshalType, creationTime *protoTypes.Timestamp, ) (string, error) { principal, err := auth.NewDIDPrincipal(creatorID) @@ -116,19 +116,13 @@ func (l *ACPLocal) AddPolicy( } ctx = auth.InjectPrincipal(ctx, principal) - marshalType := types.PolicyMarshalingType_SHORT_YAML - if isJSON := fastjson.Validate(policy) == nil; isJSON { // Detect JSON format. - marshalType = types.PolicyMarshalingType_SHORT_JSON - } - createPolicy := types.CreatePolicyRequest{ Policy: policy, - MarshalType: marshalType, + MarshalType: types.PolicyMarshalingType(marshalType), CreationTime: protoTypes.TimestampNow(), } response, err := l.engine.CreatePolicy(ctx, &createPolicy) - if err != nil { return "", err } diff --git a/acp/source_hub_client.go b/acp/source_hub_client.go index 30cf773c96..22371cd6e2 100644 --- a/acp/source_hub_client.go +++ b/acp/source_hub_client.go @@ -16,6 +16,7 @@ import ( protoTypes "github.com/cosmos/gogoproto/types" "github.com/sourcenetwork/corelog" "github.com/sourcenetwork/immutable" + "github.com/valyala/fastjson" ) // sourceHubClient is a private abstraction to allow multiple ACP implementations @@ -40,6 +41,7 @@ type sourceHubClient interface { ctx context.Context, creatorID string, policy string, + marshalType policyMarshalType, creationTime *protoTypes.Timestamp, ) (string, error) @@ -116,10 +118,16 @@ func (a *sourceHubBridge) AddPolicy(ctx context.Context, creatorID string, polic return "", ErrPolicyDataMustNotBeEmpty } + marshalType := policyMarshalType_YAML + if isJSON := fastjson.Validate(policy) == nil; isJSON { // Detect JSON format. + marshalType = policyMarshalType_JSON + } + policyID, err := a.client.AddPolicy( ctx, creatorID, policy, + marshalType, protoTypes.TimestampNow(), ) diff --git a/acp/types.go b/acp/types.go index c7ffa17d73..e17f9d9dc4 100644 --- a/acp/types.go +++ b/acp/types.go @@ -23,6 +23,15 @@ const ( RegistrationResult_Unarchived RegistrationResult = 2 ) +// policyMarshalType represents the format in which a policy +// is marshaled as +type policyMarshalType int32 + +const ( + policyMarshalType_YAML policyMarshalType = 1 + policyMarshalType_JSON policyMarshalType = 2 +) + // policy is a data container carrying the necessary data // to verify whether a policy meets DPI requirements type policy struct {