Skip to content

Commit

Permalink
PR(ACP): Rename Registering Document Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Mar 14, 2024
1 parent e4de9fd commit 3bf1d54
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 27 deletions.
4 changes: 2 additions & 2 deletions acp/acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type ACPModule interface {
// Learn more about DefraDB ACP Terminologies [TERMINOLOGY](/acp/TERMINOLOGY.md)
ValidateResourceExistsOnValidDPI(ctx context.Context, policyID, resource string) error

// RegisterDocCreation registers the document (object) to have access control.
// RegisterDocObject registers the document (object) to have access control.
// No error is returned upon successful registering of a document.
//
// Note(s):
Expand All @@ -78,7 +78,7 @@ type ACPModule interface {
// - actorID here is the identity of the actor registering the doc object.
// - resource here is the resource name from the policy.
// - docID here is the object identifier.
RegisterDocCreation(ctx context.Context, actorID, policyID, resource, docID string) error
RegisterDocObject(ctx context.Context, actorID, policyID, resource, docID string) error

// IsDocRegistered returns true if the check was successfull and the document was found to be registered
// with ACP, if the check was successful and the document was not found to be registered then return false.
Expand Down
2 changes: 1 addition & 1 deletion acp/acp_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (l *ACPLocal) ValidateResourceExistsOnValidDPI(
return nil
}

func (l *ACPLocal) RegisterDocCreation(
func (l *ACPLocal) RegisterDocObject(
ctx context.Context,
actorID string,
policyID string,
Expand Down
6 changes: 3 additions & 3 deletions db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ func (c *collection) create(
return err
}

return c.registerDocCreation(ctx, identity, doc.ID().String())
return c.registerDocWithACP(ctx, identity, doc.ID().String())
}

// Update an existing document with the new values.
Expand Down Expand Up @@ -1167,7 +1167,7 @@ func (c *collection) update(
doc *client.Document,
) error {
// Stop the update if the correct permissions aren't there.
canUpdate, err := c.checkDocPermissionedAccess(
canUpdate, err := c.checkAccessOfDocWithACP(
ctx,
identity,
acp.WritePermission,
Expand Down Expand Up @@ -1518,7 +1518,7 @@ func (c *collection) exists(
txn datastore.Txn,
primaryKey core.PrimaryDataStoreKey,
) (exists bool, isDeleted bool, err error) {
canRead, err := c.checkDocPermissionedAccess(
canRead, err := c.checkAccessOfDocWithACP(
ctx,
identity,
acp.ReadPermission,
Expand Down
12 changes: 6 additions & 6 deletions db/collection_acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ import (
"github.com/sourcenetwork/defradb/db/permission"
)

func (c *collection) registerDocCreation(
func (c *collection) registerDocWithACP(
ctx context.Context,
identity immutable.Option[string],
docID string,
) error {
return permission.RegisterDocCreationOnCollection(
return permission.RegisterDocOnCollectionWithACP(
ctx,
identity,
c.db.ACPModule(),
c.db.acp,
c,
docID,
)
}

func (c *collection) checkDocPermissionedAccess(
func (c *collection) checkAccessOfDocWithACP(
ctx context.Context,
identity immutable.Option[string],
dpiPermission acp.DPIPermission,
docID string,
) (bool, error) {
return permission.CheckDocPermissionedAccessOnCollection(
return permission.CheckAccessOfDocOnCollectionWithACP(
ctx,
identity,
c.db.ACPModule(),
c.db.acp,
c,
dpiPermission,
docID,
Expand Down
2 changes: 1 addition & 1 deletion db/collection_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (c *collection) applyDelete(
}

// Stop deletion of document if the correct permissions aren't there.
canDelete, err := c.checkDocPermissionedAccess(
canDelete, err := c.checkAccessOfDocWithACP(
ctx,
identity,
acp.WritePermission,
Expand Down
4 changes: 0 additions & 4 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ func (db *db) LensRegistry() client.LensRegistry {
return db.lensRegistry
}

func (db *db) ACPModule() immutable.Option[acp.ACPModule] {
return db.acp
}

// Initialize is called when a database is first run and creates all the db global meta data
// like Collection ID counters.
func (db *db) initialize(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion db/fetcher/fetcher_acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// or not, according to our access logic based on weather (1) the request is permissioned,
// (2) the collection is permissioned (has a policy), (3) acp module exists.
func (df *DocumentFetcher) runDocReadPermissionCheck(ctx context.Context) error {
hasPermission, err := permission.CheckDocPermissionedAccessOnCollection(
hasPermission, err := permission.CheckAccessOfDocOnCollectionWithACP(
ctx,
df.identity,
df.acp,
Expand Down
6 changes: 3 additions & 3 deletions db/permission/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"github.com/sourcenetwork/defradb/client"
)

// CheckDocPermissionedAccessOnCollection handles the check, which tells us if access to the target
// CheckAccessOfDocOnCollectionWithACP handles the check, which tells us if access to the target
// document is valid, with respect to the permission type, and the specified collection.
//
// According to our access logic we have these components to worry about:
// (1) the request is permissioned (has an identity signature),
// (1) the request is permissioned (has an identity),
// (2) the collection is permissioned (has a policy),
// (3) acp module exists (acp is enabled).
//
Expand All @@ -38,7 +38,7 @@ import (
// - Document is public (unregistered), whether signatured request or not, doesn't matter.
//
// Otherwise, check with acp module to verify signature has the appropriate access.
func CheckDocPermissionedAccessOnCollection(
func CheckAccessOfDocOnCollectionWithACP(
ctx context.Context,
identityOptional immutable.Option[string],
acpModuleOptional immutable.Option[acp.ACPModule],
Expand Down
9 changes: 3 additions & 6 deletions db/permission/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import (
"github.com/sourcenetwork/defradb/client"
)

// The document is only registered with ACP if all (1) (2) and (3) are true.
// In all other cases, nothing is registered with ACP.

// RegisterDocCreationOnCollection handles the registration of the document with acp module.
// RegisterDocOnCollectionWithACP handles the registration of the document with acp module.
// The registering is done at document creation on the collection.
//
// According to our access logic we have these components to worry about:
Expand All @@ -39,7 +36,7 @@ import (
// The document is only registered if all (1) (2) and (3) are true.
//
// Otherwise, nothing is registered on the acp module.
func RegisterDocCreationOnCollection(
func RegisterDocOnCollectionWithACP(
ctx context.Context,
identity immutable.Option[string],
acpModule immutable.Option[acp.ACPModule],
Expand All @@ -50,7 +47,7 @@ func RegisterDocCreationOnCollection(
if acpModule.HasValue() && identity.HasValue() {
// And collection has policy.
if policyID, resourceName, hasPolicy := IsPermissioned(collection); hasPolicy {
return acpModule.Value().RegisterDocCreation(
return acpModule.Value().RegisterDocObject(
ctx,
identity.Value(),
policyID,
Expand Down

0 comments on commit 3bf1d54

Please sign in to comment.