asset_manager

package
v0.0.0-...-aeb4a1d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package asset_manager is an interface for high-level asset management functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetIteratorInterface

type AssetIteratorInterface interface {
	// Inherits HasNext() and Close().
	shim.CommonIteratorInterface

	// Next returns the next asset in the iterator.
	Next() (*data_model.Asset, error)

	// GetPreviousLedgerKey returns the index ledger key of the previous item that was retrieved by Next().
	GetPreviousLedgerKey() string

	// GetAssetPage converts an asset iter to an array of assets.
	// Returns array of assets and previous ledger key.
	GetAssetPage() ([]data_model.Asset, string, error)
}

AssetIteratorInterface allows a chaincode to iterate over a set of assets.

type AssetManager

type AssetManager interface {

	// GetStub returns the stub, which provides functions for accessing and modifying the ledger.
	GetStub() cached_stub.CachedStubInterface

	// GetCaller returns the caller.
	GetCaller() data_model.User

	// AddAsset adds an asset to the ledger.
	// asset                 - asset data
	//                       - asset.AssetId must be generated using asset_mgmt.GetAssetId().
	// assetKey              - a sym key used to encrypt the asset's PrivateData field.
	// giveAccessToCaller    - if true, the caller will be given access to the assetKey. This access can be revoked later.
	//                       - if false, the caller will only be adding the asset and not given access to the assetKey.
	AddAsset(asset data_model.Asset, assetKey data_model.Key, giveAccessToCaller bool) error

	// UpdateAsset updates an existing asset on the ledger.
	// The asset owner is responsible for giving other users access to the assetKey.
	// asset                 - asset data
	//                       - asset.AssetId must be generated using asset_mgmt.GetAssetId().
	// assetKey              - a sym key used to encrypt the asset's PrivateData field
	// strictUpdate          - (optional) default = true
	//                       - if true, it returns an error if the asset does not exist.
	//                       - if false, it adds a new asset if it does not exist.
	//
	// Caller must have access to the asset to update.
	UpdateAsset(asset data_model.Asset, assetKey data_model.Key, strictUpdate ...bool) error

	// DeleteAsset deletes the asset for the given assetId, as long as the caller has write access.
	// Also updates any existing indices for this asset.
	DeleteAsset(assetId string, assetKey data_model.Key) error

	// GetAsset finds and decrypts the asset for the given assetId.
	// Caller must have access to the asset.
	// Returns empty asset if the passed assetId does not match any existing assets. It is the caller's responsibility to check if returned asset is empty.
	// If assetKey is an empty key, there will be no attempt to get the PrivateData of the asset. This can be a good speed optimization if private data is not needed.
	// If assetKey does not belong to the passed in assetID, it returns an error.
	GetAsset(assetId string, assetKey data_model.Key) (*data_model.Asset, error)

	// GetAssetKey finds an asset key using the key path passed in.
	// The first key ID in the key path should be the caller's private key ID,
	// and the last key ID should be the assetKey ID.
	// Returns an empty asset key if the assetId passed in does not exist.
	// If keyPath is invalid, it returns an error.
	GetAssetKey(assetId string, keyPath []string) (data_model.Key, error)

	// AddAccessToAsset adds read or write access from user to asset.
	// Read access is given by adding access from user's public key to asset key.
	// Write access is given by adding read access and setting its access type of access graph edge data to "write".
	// Adding write access will give both read and write access.
	// allowAddAccessBeforeAssetIsCreated is an optional bool flag (default = false).
	// If it's set to true, access is processed even if the asset is not yet created.
	// Caller must be asset owner.
	AddAccessToAsset(accessControl data_model.AccessControl, allowAddAccessBeforeAssetIsCreated ...bool) error

	// RemoveAccessFromAsset removes read or write access from user to asset.
	// Write access is removed by updating access type of access graph edge data to "read".
	// Removing read access will remove both read and write access and will delete access graph edge.
	// Removing write access will keep read access.
	// Caller must be asset owner.
	RemoveAccessFromAsset(accessControl data_model.AccessControl) error

	// CheckAccessToAsset returns true if the specified access has been given from user to asset.
	// Caller can only check caller's own access.
	// To check the access of another user, first get access control manager with that user as the caller. This requires caller to have access to that user's keys.
	CheckAccessToAsset(accessControl data_model.AccessControl) (bool, error)

	// previousKey           - the ledger key returned by the previous call to assetIter.Next()
	//                       - used for paging; pass empty string "" if you are not paging
	// limit                 - the max page size to be returned; if limit = -1, all assets are returned
	// filterRule            - this rule is applied to each asset and only assets which evaluate true against this rule will be returned
	//                       - the rule must be contrived such that a boolean is stored in a key called "$result" in the result
	//                       - when the rule is applied only the "$result" key of the result will be checked
	//                       - to access fields from the asset to filter by, use a "var" operator and an operand value of equal to the name of any field of data_model.Asset
	//                       - you can access arbitrary fields by indexing through the private_data or public_data field and using dot notation
	//                       - examples:  {"var", "owner_ids"}   {"var", "public_data.name"}   {"var", "private_data.data.arbitrary_field"}
	//                       - examples to return only public assets (when decrypPrivateData is set to true):
	//                         {"not": [{"bool": [{"var":"private_data.encrypted"}]}]}
	//                         This filter rule returns true if private_data.encryped field does not exist.
	// NOTE 1:    startValues & endValues should be identical except for the last entry.
	//            The first n-1 entries will be used for filtering, the last entry can be used for a range query.
	//            Range queries are between the startKey (inclusive) and endKey (exclusive).
	// NOTE 2:    If numbers/timestamps are being queried on, be sure to call utils.ConvertToString() to format the values properly.
	//
	// When calling GetAssetIter, caller should utilize start and end values to avoid starting from the beginning
	// of the ledger. Supplying start and end values will trigger a range query, which is more efficient.
	//
	GetAssetIter(
		assetNamespace string,
		indexTableName string,
		fieldNames []string,
		startValues []string,
		endValues []string,
		decryptPrivateData bool,
		returnOnlyPrivateAssets bool,
		assetKeyPath interface{},
		previousKey string,
		limit int,
		filterRule *simple_rule.Rule,
	) (AssetIteratorInterface, error)
}

AssetManager is an interface for high-level asset management functions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL