Skip to content

Commit

Permalink
acp core refactor wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Lodek committed Jul 12, 2024
1 parent 7aef15b commit 62e3ef2
Show file tree
Hide file tree
Showing 26 changed files with 238 additions and 300 deletions.
5 changes: 3 additions & 2 deletions example/bearer_auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
cryptocdc "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
prototypes "github.com/cosmos/gogoproto/types"
coretypes "github.com/sourcenetwork/acp_core/pkg/types"

"github.com/sourcenetwork/sourcehub/sdk"
"github.com/sourcenetwork/sourcehub/x/acp/bearer_token"
Expand Down Expand Up @@ -56,7 +57,7 @@ resources:
`

msgSet := sdk.MsgSet{}
policyMapper := msgSet.WithCreatePolicy(acptypes.NewMsgCreatePolicyNow(txSigner.GetAccAddress(), policy, acptypes.PolicyMarshalingType_SHORT_YAML))
policyMapper := msgSet.WithCreatePolicy(acptypes.NewMsgCreatePolicyNow(txSigner.GetAccAddress(), policy, coretypes.PolicyMarshalingType_SHORT_YAML))
tx, err := txBuilder.Build(ctx, txSigner, &msgSet)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -101,7 +102,7 @@ resources:
Creator: txSigner.GetAccAddress(),
BearerToken: jws,
PolicyId: policyResponse.Policy.Id,
Cmd: acptypes.NewRegisterObjectCmd(acptypes.NewObject("resource", "foo")),
Cmd: acptypes.NewRegisterObjectCmd(coretypes.NewObject("resource", "foo")),
CreationTime: prototypes.TimestampNow(),
}

Expand Down
5 changes: 3 additions & 2 deletions example/sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocdc "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
coretypes "github.com/sourcenetwork/acp_core/pkg/types"

"github.com/sourcenetwork/sourcehub/sdk"
"github.com/sourcenetwork/sourcehub/x/acp/did"
Expand Down Expand Up @@ -59,7 +60,7 @@ resources:
`

msgSet := sdk.MsgSet{}
policyMapper := msgSet.WithCreatePolicy(acptypes.NewMsgCreatePolicyNow(signer.GetAccAddress(), policy, acptypes.PolicyMarshalingType_SHORT_YAML))
policyMapper := msgSet.WithCreatePolicy(acptypes.NewMsgCreatePolicyNow(signer.GetAccAddress(), policy, coretypes.PolicyMarshalingType_SHORT_YAML))
tx, err := txBuilder.Build(ctx, signer, &msgSet)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -90,7 +91,7 @@ resources:
if err != nil {
log.Fatal(err)
}
cmdBuilder.RegisterObject(acptypes.NewObject("resource", "readme.txt"))
cmdBuilder.RegisterObject(coretypes.NewObject("resource", "readme.txt"))
cmdBuilder.PolicyID(policyResponse.Policy.Id)
cmdBuilder.Actor(aliceDid)
cmdBuilder.SetSigner(aliceSigner)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.3

toolchain go1.22.4

replace github.com/sourcenetwork/acp_core => ../../acp_core
replace github.com/sourcenetwork/acp_core => ./submodules/acp_core

require (
cosmossdk.io/api v0.7.4
Expand Down
2 changes: 1 addition & 1 deletion submodules/acp_core
Submodule acp_core updated 63 files
+19 −19 go.mod
+58 −138 go.sum
+3 −2 internal/access_decision/query.go
+3 −3 internal/authz_db/query.go
+2 −2 internal/infra/span.go
+3 −13 internal/policy/cmd.go
+6 −11 internal/policy/errors.go
+2 −2 internal/policy/factory.go
+4 −3 internal/policy/query.go
+2 −1 internal/policy/spec.go
+1 −1 internal/policy/types.go
+1 −1 internal/policy/unmarshaler.go
+10 −3 internal/relationship/authorizer.go
+27 −4 internal/relationship/errors.go
+7 −10 internal/relationship/helpers.go
+91 −80 internal/relationship/object_cmd.go
+28 −32 internal/relationship/object_query.go
+40 −45 internal/relationship/relationship_cmd.go
+5 −5 internal/relationship/relationship_query.go
+18 −10 internal/relationship/spec.go
+13 −0 internal/system/errors.go
+4 −4 internal/system/handlers.go
+4 −2 internal/system/types.go
+0 −31 internal/utils/functional.go
+0 −90 internal/utils/sort.go
+3 −4 internal/zanzi/adapter.go
+0 −10 internal/zanzi/logger.go
+5 −4 internal/zanzi/mappers.go
+2 −2 pkg/did/did.go
+2 −2 pkg/did/key.go
+1 −1 pkg/engine/decorator.go
+18 −0 pkg/errors/error_type.go
+100 −0 pkg/errors/error_type.pb.go
+29 −0 pkg/errors/errors.go
+113 −0 pkg/errors/types.go
+4 −4 pkg/runtime/types.go
+1 −1 pkg/types/access_decision.go
+789 −560 pkg/types/engine.pb.go
+0 −49 pkg/types/errors.go
+22 −73 pkg/types/event.pb.go
+1 −1 pkg/types/management_graph.go
+1 −1 pkg/types/policy.go
+34 −85 pkg/types/policy.pb.go
+0 −2,650 pkg/types/policy_cmd.pb.go
+198 −30 pkg/types/policy_record.pb.go
+226 −111 pkg/types/relationship.pb.go
+11 −0 pkg/types/types.go
+11 −1 proto/sourcenetwork/acp_core/engine.proto
+26 −0 proto/sourcenetwork/acp_core/errors/error_type.proto
+0 −1 proto/sourcenetwork/acp_core/event.proto
+0 −2 proto/sourcenetwork/acp_core/policy.proto
+0 −95 proto/sourcenetwork/acp_core/policy_cmd.proto
+3 −0 proto/sourcenetwork/acp_core/policy_record.proto
+9 −9 proto/sourcenetwork/acp_core/relationship.proto
+4 −0 test/integration/object/common.go
+2 −1 test/integration/object/object_query_owner_test.go
+9 −7 test/integration/object/object_register_test.go
+10 −6 test/integration/object/object_unregister_test.go
+8 −23 test/integration/policy/create_test.go
+2 −5 test/integration/policy/get_test.go
+4 −0 test/integration/relationship/common.go
+2 −1 test/integration/relationship/relationship_delete_test.go
+8 −5 test/integration/relationship/relationship_set_test.go
4 changes: 3 additions & 1 deletion tests/e2e/sdk/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"testing"

coretypes "github.com/sourcenetwork/acp_core/pkg/types"

"github.com/sourcenetwork/sourcehub/sdk"
"github.com/sourcenetwork/sourcehub/testutil/e2e"
"github.com/sourcenetwork/sourcehub/x/acp/types"
Expand Down Expand Up @@ -31,7 +33,7 @@ name: test policy
types.NewMsgCreatePolicyNow(
network.GetValidatorAddr(),
policy,
types.PolicyMarshalingType_SHORT_YAML,
coretypes.PolicyMarshalingType_SHORT_YAML,
),
)

Expand Down
38 changes: 17 additions & 21 deletions tests/integration/acp/actions.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package test

import (
"github.com/sourcenetwork/acp_core/pkg/types"
coretypes "github.com/sourcenetwork/acp_core/pkg/types"

"github.com/sourcenetwork/sourcehub/x/acp/types"
)

type CreatePolicyAction struct {
Policy string
Expected *types.Policy
Expected *coretypes.Policy
Creator *TestActor
ExpectedErr error
}

func (a *CreatePolicyAction) Run(ctx *TestCtx) *types.Policy {
func (a *CreatePolicyAction) Run(ctx *TestCtx) *coretypes.Policy {
msg := &types.MsgCreatePolicy{
Policy: a.Policy,
Creator: a.Creator.SourceHubAddr,
MarshalType: types.PolicyMarshalingType_SHORT_YAML,
MarshalType: coretypes.PolicyMarshalingType_SHORT_YAML,
CreationTime: TimeToProto(ctx.Timestamp),
}
response, err := ctx.Executor.CreatePolicy(ctx, msg)
Expand All @@ -37,17 +39,14 @@ func (a *CreatePolicyAction) Run(ctx *TestCtx) *types.Policy {

type SetRelationshipAction struct {
PolicyId string
Relationship *types.Relationship
Relationship *coretypes.Relationship
Actor *TestActor
Expected *types.SetRelationshipCmdResult
ExpectedErr error
}

func (a *SetRelationshipAction) Run(ctx *TestCtx) *types.RelationshipRecord {
func (a *SetRelationshipAction) Run(ctx *TestCtx) *coretypes.RelationshipRecord {
result, err := setRelationshipDispatcher(ctx, a)
if a.Expected != nil {
a.Expected.Record.Creator = ctx.TxSigner.SourceHubAddr
}
AssertResults(ctx, result, a.Expected, err, a.ExpectedErr)
if result != nil {
return result.Record
Expand All @@ -57,17 +56,14 @@ func (a *SetRelationshipAction) Run(ctx *TestCtx) *types.RelationshipRecord {

type RegisterObjectAction struct {
PolicyId string
Object *types.Object
Object *coretypes.Object
Actor *TestActor
Expected *types.RegisterObjectCmdResult
ExpectedErr error
}

func (a *RegisterObjectAction) Run(ctx *TestCtx) *types.RelationshipRecord {
func (a *RegisterObjectAction) Run(ctx *TestCtx) *coretypes.RelationshipRecord {
result, err := registerObjectDispatcher(ctx, a)
if a.Expected != nil {
a.Expected.Record.Creator = ctx.TxSigner.SourceHubAddr
}
AssertResults(ctx, result, a.Expected, err, a.ExpectedErr)
if result != nil {
return result.Record
Expand All @@ -77,7 +73,7 @@ func (a *RegisterObjectAction) Run(ctx *TestCtx) *types.RelationshipRecord {

type RegisterObjectsAction struct {
PolicyId string
Objects []*types.Object
Objects []*coretypes.Object
Actor *TestActor
}

Expand All @@ -94,7 +90,7 @@ func (a *RegisterObjectsAction) Run(ctx *TestCtx) {

type SetRelationshipsAction struct {
PolicyId string
Relationships []*types.Relationship
Relationships []*coretypes.Relationship
Actor *TestActor
}

Expand All @@ -111,7 +107,7 @@ func (a *SetRelationshipsAction) Run(ctx *TestCtx) {

type DeleteRelationshipsAction struct {
PolicyId string
Relationships []*types.Relationship
Relationships []*coretypes.Relationship
Actor *TestActor
}

Expand All @@ -128,7 +124,7 @@ func (a *DeleteRelationshipsAction) Run(ctx *TestCtx) {

type DeleteRelationshipAction struct {
PolicyId string
Relationship *types.Relationship
Relationship *coretypes.Relationship
Actor *TestActor
Expected *types.DeleteRelationshipCmdResult
ExpectedErr error
Expand All @@ -142,7 +138,7 @@ func (a *DeleteRelationshipAction) Run(ctx *TestCtx) *types.DeleteRelationshipCm

type UnregisterObjectAction struct {
PolicyId string
Object *types.Object
Object *coretypes.Object
Actor *TestActor
Expected *types.UnregisterObjectCmdResult
ExpectedErr error
Expand All @@ -157,8 +153,8 @@ func (a *UnregisterObjectAction) Run(ctx *TestCtx) *types.UnregisterObjectCmdRes
type PolicySetupAction struct {
Policy string
PolicyCreator *TestActor
ObjectsPerActor map[string][]*types.Object
RelationshipsPerActor map[string][]*types.Relationship
ObjectsPerActor map[string][]*coretypes.Object
RelationshipsPerActor map[string][]*coretypes.Relationship
}

func (a *PolicySetupAction) Run(ctx *TestCtx) {
Expand Down
1 change: 1 addition & 0 deletions tests/integration/acp/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type TestCtx struct {
AccountKeeper *testutil.AccountKeeperStub
ActorType ActorKeyType
LogicalClock signed_policy_cmd.LogicalClock
TxHash string
}

func NewTestCtx(t *testing.T) *TestCtx {
Expand Down
Loading

0 comments on commit 62e3ef2

Please sign in to comment.