diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ad7cc59..0e43b31 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.21 - name: Build run: go build -v ./... diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..d5e0e85 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @hyperledger-labs/cc-tools-committers \ No newline at end of file diff --git a/MANTAINERS.md b/MANTAINERS.md new file mode 100644 index 0000000..d21de3a --- /dev/null +++ b/MANTAINERS.md @@ -0,0 +1,18 @@ +# Maintainers + +### **Active Maintainers** + +| Nome | Github | +|:-------|:--------| +| André Macedo | [andremacedopv](https://github.com/andremacedopv) | +| Samuel Venzi | [samuelvenzi](https://github.com/samuelvenzi) | +| Lucas Campelo | [lucas-campelo](https://github.com/lucas-campelo) | +| Marcos Sarres | [goledger](https://github.com/goledger) | + + +### **Retired Maintainers** +| Nome | Github | +|:-------|:--------| +| Bruno Andreghetti | [bandreghetti](https://github.com/bandreghetti) | +| João Pedro | [JoaoPedroAssis](https://github.com/JoaoPedroAssis) | +| Arthur Paiva | [ArthurPaivaT](https://github.com/ArthurPaivaT) | \ No newline at end of file diff --git a/README.md b/README.md index 185839b..8f41280 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/hyperledger-labs/cc-tools)](https://goreportcard.com/report/github.com/hyperledger-labs/cc-tools) [![GoDoc](https://godoc.org/github.com/hyperledger-labs/cc-tools?status.svg)](https://godoc.org/github.com/hyperledger-labs/cc-tools) -This project is a GoLedger open-source project aimed at providing tools for Hyperledger Fabric chaincode development in Golang. This might have breaking changes before we arrive at release v1.0.0. +This project is a GoLedger open-source project aimed at providing tools for Hyperledger Fabric chaincode development in Golang. ## Getting Started Make sure you visit the repository [hyperledger-labs/cc-tools-demo](https://github.com/hyperledger-labs/cc-tools-demo), which is a template of a functional chaincode that uses cc-tools and provides ready-to-use scripts to deploy development networks. This is our preferred way of working, but you can feel free to import the package and assemble the chaincode as you choose. -CC Tools has been tested with Hyperledger Fabric 1.x and 2.x realeases. +CC Tools has been tested with Hyperledger Fabric v2.2, v2.4 and v2.5 releases. ## Features - Standard asset data mapping (and their properties) diff --git a/accesscontrol/allowCaller.go b/accesscontrol/allowCaller.go new file mode 100644 index 0000000..5be780c --- /dev/null +++ b/accesscontrol/allowCaller.go @@ -0,0 +1,89 @@ +package accesscontrol + +import ( + "regexp" + + "github.com/hyperledger-labs/cc-tools/errors" + "github.com/hyperledger/fabric-chaincode-go/pkg/cid" + "github.com/hyperledger/fabric-chaincode-go/shim" +) + +func AllowCaller(stub shim.ChaincodeStubInterface, allowedCallers []Caller) (bool, error) { + if allowedCallers == nil { + return true, nil + } + + callerMSP, err := cid.GetMSPID(stub) + if err != nil { + return false, errors.WrapError(err, "could not get MSP id") + } + + var grantedPermission bool + for i := 0; i < len(allowedCallers) && !grantedPermission; i++ { + allowed := allowedCallers[i] + isAllowedMSP, err := checkMSP(callerMSP, allowed.MSP) + if err != nil { + return false, errors.WrapError(err, "failed to check MSP") + } + + isAllowedOU, err := checkOU(stub, allowed.OU) + if err != nil { + return false, errors.WrapError(err, "failed to check OU") + } + + isAllowedAttrs, err := checkAttributes(stub, allowed.Attributes) + if err != nil { + return false, errors.WrapError(err, "failed to check attributes") + } + + grantedPermission = isAllowedMSP && isAllowedOU && isAllowedAttrs + } + + return grantedPermission, nil +} + +func checkMSP(callerMsp, allowedMSP string) (bool, error) { + if len(allowedMSP) <= 1 { + return true, nil + } + + // if caller is regexp + if allowedMSP[0] == '$' { + match, err := regexp.MatchString(allowedMSP[1:], callerMsp) + if err != nil { + return false, errors.NewCCError("failed to check if caller matches regexp", 500) + } + + return match, nil + } + + // if caller is not regexss + return callerMsp == allowedMSP, nil +} + +func checkOU(stub shim.ChaincodeStubInterface, allowedOU string) (bool, error) { + if allowedOU == "" { + return true, nil + } + + return cid.HasOUValue(stub, allowedOU) +} + +func checkAttributes(stub shim.ChaincodeStubInterface, allowedAttrs map[string]string) (bool, error) { + if allowedAttrs == nil { + return true, nil + } + + for key, value := range allowedAttrs { + callerValue, _, err := cid.GetAttributeValue(stub, key) + if err != nil { + return false, err + } + + if callerValue != value { + return false, nil + } + } + + return true, nil +} diff --git a/accesscontrol/caller.go b/accesscontrol/caller.go new file mode 100644 index 0000000..746f6c6 --- /dev/null +++ b/accesscontrol/caller.go @@ -0,0 +1,7 @@ +package accesscontrol + +type Caller struct { + MSP string `json:"msp"` + OU string `json:"ou"` + Attributes map[string]string `json:"attributes"` +} diff --git a/assets/asset.go b/assets/asset.go index 4cc2883..7db83f6 100644 --- a/assets/asset.go +++ b/assets/asset.go @@ -106,6 +106,16 @@ func (a Asset) IsPrivate() bool { return assetTypeDef.IsPrivate() } +func (a Asset) CollectionName() string { + // Fetch asset properties + assetTypeDef := a.Type() + if assetTypeDef == nil { + return "" + } + + return assetTypeDef.CollectionName() +} + // TypeTag returns the @assetType attribute. func (a Asset) TypeTag() string { assetType, _ := a["@assetType"].(string) diff --git a/assets/assetProp.go b/assets/assetProp.go index a5b77f6..674e6c6 100644 --- a/assets/assetProp.go +++ b/assets/assetProp.go @@ -29,6 +29,7 @@ type AssetProp struct { // Primary types: "string", "number", "integer", "boolean", "datetime" // Special types: // ->: the specific asset type key (reference) as defined by in the assets packages + // ->@asset: an arbitrary asset type key (reference) // []: an array of elements specified by as any of the above valid types DataType string `json:"dataType"` diff --git a/assets/assetType.go b/assets/assetType.go index e73a8dc..6c0487f 100644 --- a/assets/assetType.go +++ b/assets/assetType.go @@ -30,6 +30,10 @@ type AssetType struct { // Dynamic is a flag that indicates if the asset type is dynamic. Dynamic bool `json:"dynamic,omitempty"` + + // Private collection name it belongs to. When empty and len(readers) > 0, + // Tag is considered instead + Collection string `json:"collection,omitempty"` } // Keys returns a list of asset properties which are defined as primary keys. (IsKey == true) @@ -48,6 +52,9 @@ func (t AssetType) SubAssets() (subAssets []AssetProp) { dataType := prop.DataType dataType = strings.TrimPrefix(dataType, "[]") dataType = strings.TrimPrefix(dataType, "->") + if dataType == "@asset" { + subAssets = append(subAssets, prop) + } subAssetType := FetchAssetType(dataType) if subAssetType != nil { subAssets = append(subAssets, prop) @@ -81,6 +88,15 @@ func (t AssetType) IsPrivate() bool { return len(t.Readers) > 0 } +// CollectionName returns the private collection name. Default is tag. +func (t AssetType) CollectionName() string { + if t.Collection == "" { + return t.Tag + } + + return t.Collection +} + // ToMap returns a map representation of the asset type. func (t AssetType) ToMap() map[string]interface{} { return map[string]interface{}{ diff --git a/assets/dataType.go b/assets/dataType.go index a429754..05ed2e9 100644 --- a/assets/dataType.go +++ b/assets/dataType.go @@ -6,6 +6,7 @@ import ( "math" "net/http" "strconv" + "strings" "time" "github.com/hyperledger-labs/cc-tools/errors" @@ -29,6 +30,11 @@ type DataType struct { // CustomDataTypes allows cc developer to inject custom primitive data types func CustomDataTypes(m map[string]DataType) error { + // Avoid initialization cycle + if FetchAssetType("->@asset") == nil { + dataTypeMap["->@asset"] = &assetDatatype + } + for k, v := range m { if v.Parse == nil { return errors.NewCCError(fmt.Sprintf("invalid custom data type '%s': nil Parse function", k), 500) @@ -192,3 +198,48 @@ var dataTypeMap = map[string]*DataType{ }, }, } + +var assetDatatype = DataType{ + AcceptedFormats: []string{"->@asset"}, + Parse: func(data interface{}) (string, interface{}, errors.ICCError) { + dataVal, ok := data.(map[string]interface{}) + if !ok { + switch v := data.(type) { + case []byte: + err := json.Unmarshal(v, &dataVal) + if err != nil { + return "", nil, errors.WrapErrorWithStatus(err, "failed to unmarshal []byte into map[string]interface{}", http.StatusBadRequest) + } + case string: + err := json.Unmarshal([]byte(v), &dataVal) + if err != nil { + return "", nil, errors.WrapErrorWithStatus(err, "failed to unmarshal string into map[string]interface{}", http.StatusBadRequest) + } + default: + return "", nil, errors.NewCCError(fmt.Sprintf("asset property must be either a byte array or a string, but received type is: %T", data), http.StatusBadRequest) + } + } + + key, er := GenerateKey(dataVal) + if er != nil { + return "", nil, errors.WrapError(er, "failed to generate key") + } + dataVal["@key"] = key + + assetType, ok := dataVal["@assetType"].(string) + if ok { + if !strings.Contains(key, assetType) { + return "", nil, errors.NewCCError(fmt.Sprintf("asset type '%s' doesnt match key '%s'", assetType, key), http.StatusBadRequest) + } + } else { + dataVal["@assetType"] = key[:strings.IndexByte(key, ':')] + } + + retVal, err := json.Marshal(dataVal) + if err != nil { + return "", nil, errors.WrapErrorWithStatus(err, "failed to marshal return value", http.StatusInternalServerError) + } + + return string(retVal), dataVal, nil + }, +} diff --git a/assets/delete.go b/assets/delete.go index 8836977..3cb68f5 100644 --- a/assets/delete.go +++ b/assets/delete.go @@ -34,7 +34,7 @@ func (a *Asset) delete(stub *sw.StubWrapper) ([]byte, errors.ICCError) { return nil, errors.WrapError(err, "failed to marshal asset") } } else { - err = stub.DelPrivateData(a.TypeTag(), a.Key()) + err = stub.DelPrivateData(a.CollectionName(), a.Key()) if err != nil { return nil, errors.WrapError(err, "failed to delete state from private collection") } diff --git a/assets/dynamicAssetTypeFuncs.go b/assets/dynamicAssetTypeFuncs.go index 2eb50c9..27102e8 100644 --- a/assets/dynamicAssetTypeFuncs.go +++ b/assets/dynamicAssetTypeFuncs.go @@ -163,6 +163,9 @@ func CheckDataType(dataType string, newTypesList []interface{}) errors.ICCError if strings.HasPrefix(trimDataType, "->") { trimDataType = strings.TrimPrefix(trimDataType, "->") + if trimDataType == "@asset" { + return nil + } assetType := FetchAssetType(trimDataType) if assetType == nil { diff --git a/assets/existsInLedger.go b/assets/existsInLedger.go index 8765932..55434da 100644 --- a/assets/existsInLedger.go +++ b/assets/existsInLedger.go @@ -6,15 +6,15 @@ import ( sw "github.com/hyperledger-labs/cc-tools/stubwrapper" ) -func existsInLedger(stub *sw.StubWrapper, isPrivate bool, typeTag, key string) (bool, errors.ICCError) { +func existsInLedger(stub *sw.StubWrapper, isPrivate bool, collection, key string) (bool, errors.ICCError) { var assetBytes []byte var err error if isPrivate { _, isMock := stub.Stub.(*mock.MockStub) if isMock { - assetBytes, err = stub.GetPrivateData(typeTag, key) + assetBytes, err = stub.GetPrivateData(collection, key) } else { - assetBytes, err = stub.GetPrivateDataHash(typeTag, key) + assetBytes, err = stub.GetPrivateDataHash(collection, key) } } else { assetBytes, err = stub.GetState(key) @@ -34,7 +34,7 @@ func (a *Asset) ExistsInLedger(stub *sw.StubWrapper) (bool, errors.ICCError) { if a.Key() == "" { return false, errors.NewCCError("asset key is empty", 500) } - return existsInLedger(stub, a.IsPrivate(), a.TypeTag(), a.Key()) + return existsInLedger(stub, a.IsPrivate(), a.CollectionName(), a.Key()) } // ExistsInLedger checks if asset referenced by a key object currently has a state. @@ -42,20 +42,20 @@ func (k *Key) ExistsInLedger(stub *sw.StubWrapper) (bool, errors.ICCError) { if k.Key() == "" { return false, errors.NewCCError("key is empty", 500) } - return existsInLedger(stub, k.IsPrivate(), k.TypeTag(), k.Key()) + return existsInLedger(stub, k.IsPrivate(), k.CollectionName(), k.Key()) } // ---------------------------------------- -func committedInLedger(stub *sw.StubWrapper, isPrivate bool, typeTag, key string) (bool, errors.ICCError) { +func committedInLedger(stub *sw.StubWrapper, isPrivate bool, collection, key string) (bool, errors.ICCError) { var assetBytes []byte var err error if isPrivate { _, isMock := stub.Stub.(*mock.MockStub) if isMock { - assetBytes, err = stub.Stub.GetPrivateData(typeTag, key) + assetBytes, err = stub.Stub.GetPrivateData(collection, key) } else { - assetBytes, err = stub.Stub.GetPrivateDataHash(typeTag, key) + assetBytes, err = stub.Stub.GetPrivateDataHash(collection, key) } } else { assetBytes, err = stub.Stub.GetState(key) @@ -75,7 +75,7 @@ func (a *Asset) CommittedInLedger(stub *sw.StubWrapper) (bool, errors.ICCError) if a.Key() == "" { return false, errors.NewCCError("asset key is empty", 500) } - return committedInLedger(stub, a.IsPrivate(), a.TypeTag(), a.Key()) + return committedInLedger(stub, a.IsPrivate(), a.CollectionName(), a.Key()) } // CommittedInLedger checks if asset referenced by a key object currently has a state committed in ledger. @@ -83,5 +83,5 @@ func (k *Key) CommittedInLedger(stub *sw.StubWrapper) (bool, errors.ICCError) { if k.Key() == "" { return false, errors.NewCCError("key is empty", 500) } - return committedInLedger(stub, k.IsPrivate(), k.TypeTag(), k.Key()) + return committedInLedger(stub, k.IsPrivate(), k.CollectionName(), k.Key()) } diff --git a/assets/generateKey.go b/assets/generateKey.go index 3f3708a..d96b10f 100644 --- a/assets/generateKey.go +++ b/assets/generateKey.go @@ -90,11 +90,6 @@ func GenerateKey(asset map[string]interface{}) (string, errors.ICCError) { keySeed += seed } else { // If key is a subAsset, generate subAsset's key to append to seed - assetTypeDef := FetchAssetType(dataTypeName) - if assetTypeDef == nil { - return "", errors.NewCCError(fmt.Sprintf("internal error: invalid sub asset type %s", prop.DataType), 500) - } - var propMap map[string]interface{} switch t := propInterface.(type) { case map[string]interface{}: @@ -108,6 +103,14 @@ func GenerateKey(asset map[string]interface{}) (string, errors.ICCError) { return "", errors.NewCCError(errMsg, 400) } + if dataTypeName == "@asset" { + dataTypeName = propMap["@assetType"].(string) + } + assetTypeDef := FetchAssetType(dataTypeName) + if assetTypeDef == nil { + return "", errors.NewCCError(fmt.Sprintf("internal error: invalid sub asset type %s", prop.DataType), 500) + } + propMap["@assetType"] = dataTypeName subAssetKey, err := GenerateKey(propMap) if err != nil { diff --git a/assets/get.go b/assets/get.go index 01ef058..a29a82b 100644 --- a/assets/get.go +++ b/assets/get.go @@ -48,7 +48,7 @@ func get(stub *sw.StubWrapper, pvtCollection, key string, committed bool) (*Asse func (a *Asset) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError) { var pvtCollection string if a.IsPrivate() { - pvtCollection = a.TypeTag() + pvtCollection = a.CollectionName() } return get(stub, pvtCollection, a.Key(), false) @@ -58,7 +58,7 @@ func (a *Asset) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError) { func (k *Key) Get(stub *sw.StubWrapper) (*Asset, errors.ICCError) { var pvtCollection string if k.IsPrivate() { - pvtCollection = k.TypeTag() + pvtCollection = k.CollectionName() } return get(stub, pvtCollection, k.Key(), false) @@ -71,7 +71,7 @@ func GetMany(stub *sw.StubWrapper, keys []Key) ([]*Asset, errors.ICCError) { for _, k := range keys { var pvtCollection string if k.IsPrivate() { - pvtCollection = k.TypeTag() + pvtCollection = k.CollectionName() } asset, err := get(stub, pvtCollection, k.Key(), false) @@ -88,7 +88,7 @@ func GetMany(stub *sw.StubWrapper, keys []Key) ([]*Asset, errors.ICCError) { func (a *Asset) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError) { var pvtCollection string if a.IsPrivate() { - pvtCollection = a.TypeTag() + pvtCollection = a.CollectionName() } return get(stub, pvtCollection, a.Key(), true) @@ -98,7 +98,7 @@ func (a *Asset) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError) { func (k *Key) GetCommitted(stub *sw.StubWrapper) (*Asset, errors.ICCError) { var pvtCollection string if k.IsPrivate() { - pvtCollection = k.TypeTag() + pvtCollection = k.CollectionName() } return get(stub, pvtCollection, k.Key(), true) @@ -109,7 +109,7 @@ func (k *Key) GetBytes(stub *sw.StubWrapper) ([]byte, errors.ICCError) { var assetBytes []byte var err error if k.IsPrivate() { - assetBytes, err = stub.GetPrivateData(k.TypeTag(), k.Key()) + assetBytes, err = stub.GetPrivateData(k.CollectionName(), k.Key()) } else { assetBytes, err = stub.GetState(k.Key()) } @@ -218,7 +218,7 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ var subAsset map[string]interface{} if propKey.IsPrivate() { - subAsset, err = getRecursive(stub, propKey.TypeTag(), propKey.Key(), keysChecked) + subAsset, err = getRecursive(stub, propKey.CollectionName(), propKey.Key(), keysChecked) } else { subAsset, err = getRecursive(stub, "", propKey.Key(), keysChecked) } @@ -265,7 +265,7 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ var subAsset map[string]interface{} if elemKey.IsPrivate() { - subAsset, err = getRecursive(stub, elemKey.TypeTag(), elemKey.Key(), keysChecked) + subAsset, err = getRecursive(stub, elemKey.CollectionName(), elemKey.Key(), keysChecked) } else { subAsset, err = getRecursive(stub, "", elemKey.Key(), keysChecked) } @@ -287,7 +287,7 @@ func getRecursive(stub *sw.StubWrapper, pvtCollection, key string, keysChecked [ func (a *Asset) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError) { var pvtCollection string if a.IsPrivate() { - pvtCollection = a.TypeTag() + pvtCollection = a.CollectionName() } return getRecursive(stub, pvtCollection, a.Key(), []string{}) @@ -297,7 +297,7 @@ func (a *Asset) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, erro func (k *Key) GetRecursive(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCError) { var pvtCollection string if k.IsPrivate() { - pvtCollection = k.TypeTag() + pvtCollection = k.CollectionName() } return getRecursive(stub, pvtCollection, k.Key(), []string{}) diff --git a/assets/history.go b/assets/history.go index 380c79d..8c93999 100644 --- a/assets/history.go +++ b/assets/history.go @@ -25,6 +25,7 @@ func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, defer resultsIterator.Close() historyResult := make([]map[string]interface{}, 0) + var subAssets []AssetProp for resultsIterator.HasNext() { queryResponse, err := resultsIterator.Next() @@ -40,15 +41,18 @@ func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, } if resolve { - key, err := NewKey(data) - if err != nil { - return nil, errors.WrapError(err, "failed to create key object to resolve result") + if subAssets == nil { + key, err := NewKey(data) + if err != nil { + return nil, errors.WrapError(err, "failed to create key object to resolve result") + } + subAssets = key.Type().SubAssets() } - asset, err := key.GetRecursive(stub) + + err := resolveHistory(stub, data, subAssets) if err != nil { return nil, errors.WrapError(err, "failed to resolve result") } - data = asset } historyResult = append(historyResult, data) @@ -60,3 +64,26 @@ func History(stub *sw.StubWrapper, key string, resolve bool) (*HistoryResponse, return &response, nil } + +func resolveHistory(stub *sw.StubWrapper, data map[string]interface{}, subAssets []AssetProp) errors.ICCError { + for _, refProp := range subAssets { + ref, ok := data[refProp.Tag].(map[string]interface{}) + if !ok { + continue + } + + key, err := NewKey(ref) + if err != nil { + return errors.WrapError(err, "could not make subasset key") + } + + resolved, err := key.GetRecursive(stub) + if err != nil { + return errors.WrapError(err, "failed to get subasset recursive") + } + + data[refProp.Tag] = resolved + } + + return nil +} diff --git a/assets/key.go b/assets/key.go index aa061d9..abd970b 100644 --- a/assets/key.go +++ b/assets/key.go @@ -99,6 +99,16 @@ func (k Key) IsPrivate() bool { return assetTypeDef.IsPrivate() } +func (k Key) CollectionName() string { + // Fetch asset properties + assetTypeDef := k.Type() + if assetTypeDef == nil { + return "" + } + + return assetTypeDef.CollectionName() +} + // TypeTag returns @assetType attribute func (k Key) TypeTag() string { assetType, _ := k["@assetType"].(string) diff --git a/assets/put.go b/assets/put.go index c98f865..7282f19 100644 --- a/assets/put.go +++ b/assets/put.go @@ -3,6 +3,7 @@ package assets import ( "encoding/json" "fmt" + "reflect" "strings" "github.com/hyperledger-labs/cc-tools/errors" @@ -31,7 +32,7 @@ func (a *Asset) put(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCErr // Write asset to blockchain if a.IsPrivate() { - err = stub.PutPrivateData(a.TypeTag(), a.Key(), assetJSON) + err = stub.PutPrivateData(a.CollectionName(), a.Key(), assetJSON) if err != nil { return nil, errors.WrapError(err, "failed to write asset to ledger") } @@ -46,6 +47,7 @@ func (a *Asset) put(stub *sw.StubWrapper) (map[string]interface{}, errors.ICCErr if err != nil { return nil, errors.WrapError(err, "failed to write asset to ledger") } + return *a, nil } @@ -89,7 +91,7 @@ func (a *Asset) PutNew(stub *sw.StubWrapper) (map[string]interface{}, errors.ICC return res, nil } -func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool) (map[string]interface{}, errors.ICCError) { +func putRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError) { var err error objAsKey, err := NewKey(object) @@ -97,52 +99,54 @@ func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool return nil, errors.WrapError(err, "unable to create asset object") } - if !root { - exists, err := objAsKey.ExistsInLedger(stub) + exists, err := objAsKey.ExistsInLedger(stub) + if err != nil { + return nil, errors.WrapError(err, "failed checking if asset exists") + } + + propsToUpdate := map[string]bool{} + if exists { + asset, err := objAsKey.GetMap(stub) if err != nil { - return nil, errors.WrapError(err, "failed checking if asset exists") + return nil, errors.WrapError(err, "failed fetching asset that already exists") } - if exists { - asset, err := objAsKey.GetRecursive(stub) - if err != nil { - return nil, errors.WrapError(err, "failed fetching sub-asset that already exists") - } - if asset == nil { - return nil, errors.NewCCError("existing sub-asset could not be fetched", 404) - } - // If asset key is not in object, add asset value to object (so that properties are not erased) - for k := range asset { - if _, ok := object[k]; !ok { - object[k] = asset[k] - } + // If asset key is not in object, add asset value to object (so that properties are not erased) + for k := range asset { + if _, ok := object[k]; !ok { + object[k] = asset[k] } - - // TODO: check property by property if asset must be updated } - } - objAsAsset, err := NewAsset(object) - if err != nil { - return nil, errors.WrapError(err, "unable to create asset object") + // Check props to update + for k, v := range object { + if !reflect.DeepEqual(v, asset[k]) { + propsToUpdate[k] = true + } + } } subAssetsMap := map[string]interface{}{} - subAssets := objAsAsset.Type().SubAssets() + subAssets := objAsKey.Type().SubAssets() for _, subAsset := range subAssets { + subAssetInterface, ok := object[subAsset.Tag] + if !ok { + // if subAsset is not included, continue onwards to the next possible subAsset + continue + } + + if propsToUpdate[subAsset.Tag] { + delete(propsToUpdate, subAsset.Tag) + } + + // Extract asset type isArray := false dType := subAsset.DataType if strings.HasPrefix(dType, "[]") { isArray = true dType = strings.TrimPrefix(dType, "[]") } - dType = strings.TrimPrefix(dType, "->") - subAssetInterface, ok := object[subAsset.Tag] - if !ok { - // if subAsset is not included, continue onwards to the next possible subAsset - continue - } var objArray []interface{} if !isArray { @@ -167,8 +171,15 @@ func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool // If subAsset is badly formatted, this method shouldn't have been called return nil, errors.NewCCError(fmt.Sprintf("asset reference property '%s' must be an object", subAsset.Tag), 400) } - obj["@assetType"] = dType - putSubAsset, err := putRecursive(stub, obj, false) + if dType != "@asset" { + obj["@assetType"] = dType + } else { + _, ok := obj["@assetType"].(string) + if !ok { + return nil, errors.NewCCError(fmt.Sprintf("asset reference property '%s' must have an '@assetType' property", subAsset.Tag), 400) + } + } + putSubAsset, err := putRecursive(stub, obj) if err != nil { return nil, errors.WrapError(err, fmt.Sprintf("failed to put sub-asset %s recursively", subAsset.Tag)) } @@ -176,28 +187,36 @@ func putRecursive(stub *sw.StubWrapper, object map[string]interface{}, root bool } if isArray { - subAssetsMap[subAsset.Tag] = objArray + object[subAsset.Tag] = objArray } else { - subAssetsMap[subAsset.Tag] = objArray[0] + object[subAsset.Tag] = objArray[0] } + subAssetsMap[subAsset.Tag] = object[subAsset.Tag] } - putAsset, err := objAsAsset.Put(stub) - if err != nil { - return nil, errors.WrapError(err, fmt.Sprintf("failed to put asset of type %s", objAsAsset.TypeTag())) - } + if shouldUpdate := len(propsToUpdate) > 0; shouldUpdate || !exists { + objAsAsset, err := NewAsset(object) + if err != nil { + return nil, errors.WrapError(err, "unable to create asset object") + } - for tag, subAsset := range subAssetsMap { - putAsset[tag] = subAsset + object, err = objAsAsset.Put(stub) + if err != nil { + return nil, errors.WrapError(err, fmt.Sprintf("failed to put asset of type %s", objAsAsset.TypeTag())) + } + + for tag, subAsset := range subAssetsMap { + object[tag] = subAsset + } } - return putAsset, nil + return object, nil } // PutRecursive inserts asset and all its subassets in blockchain. // This method is experimental and might not work as intended. Use with caution. func PutRecursive(stub *sw.StubWrapper, object map[string]interface{}) (map[string]interface{}, errors.ICCError) { - return putRecursive(stub, object, true) + return putRecursive(stub, object) } // PutNewRecursive inserts asset and all its subassets in blockchain diff --git a/assets/references.go b/assets/references.go index d672ef6..7eb99eb 100644 --- a/assets/references.go +++ b/assets/references.go @@ -67,11 +67,17 @@ func (a Asset) Refs() ([]Key, errors.ICCError) { } subAssetTypeName, ok := subAssetRefMap["@assetType"] - if ok && subAssetTypeName != subAssetDataType { - return nil, errors.NewCCError("sub-asset reference of wrong asset type", 400) - } - if !ok { - subAssetRefMap["@assetType"] = subAssetDataType + if subAssetDataType != "@asset" { + if ok && subAssetTypeName != subAssetDataType { + return nil, errors.NewCCError("sub-asset reference of wrong asset type", 400) + } + if !ok { + subAssetRefMap["@assetType"] = subAssetDataType + } + } else { + if !ok { + return nil, errors.NewCCError("sub-asset reference must have an '@assetType' property", 400) + } } // Generate key for subAsset diff --git a/assets/startupCheck.go b/assets/startupCheck.go index d69651c..cb72da0 100644 --- a/assets/startupCheck.go +++ b/assets/startupCheck.go @@ -69,10 +69,13 @@ func StartupCheck() errors.ICCError { // Check if there are references to undefined types if isSubAsset { // Checks if the prop's datatype exists on assetMap - propTypeDef := FetchAssetType(dataTypeName) - if propTypeDef == nil { - return errors.NewCCError(fmt.Sprintf("reference for undefined asset type '%s'", propDef.DataType), 500) + if dataTypeName != "@asset" { + propTypeDef := FetchAssetType(dataTypeName) + if propTypeDef == nil { + return errors.NewCCError(fmt.Sprintf("reference for undefined asset type '%s'", propDef.DataType), 500) + } } + if propDef.DefaultValue != nil { return errors.NewCCError(fmt.Sprintf("reference cannot have a default value in prop '%s' of asset '%s'", propDef.Label, assetType.Label), 500) } diff --git a/assets/update.go b/assets/update.go index 2e46f4f..2ecf931 100644 --- a/assets/update.go +++ b/assets/update.go @@ -159,11 +159,9 @@ func (k *Key) Update(stub *sw.StubWrapper, update map[string]interface{}) (map[s writePermission = true break } - } else { // if writer is not regexp - if w == txCreator { - writePermission = true - break - } + } else if w == txCreator { // if writer is not regexp + writePermission = true + break } } if !writePermission { @@ -296,7 +294,9 @@ func checkUpdateRecursive(stub *sw.StubWrapper, object map[string]interface{}, r // If subAsset is badly formatted, this method shouldn't have been called return errors.NewCCError(fmt.Sprintf("asset reference property '%s' must be an object", subAsset.Tag), 400) } - obj["@assetType"] = dType + if dType != "@asset" { + obj["@assetType"] = dType + } err := checkUpdateRecursive(stub, obj, false) if err != nil { return errors.WrapError(err, fmt.Sprintf("failed to check sub-asset %s recursively", subAsset.Tag)) diff --git a/assets/validateProp.go b/assets/validateProp.go index 11ce1cf..5b347d3 100644 --- a/assets/validateProp.go +++ b/assets/validateProp.go @@ -2,6 +2,7 @@ package assets import ( "fmt" + "net/http" "reflect" "strings" @@ -61,12 +62,6 @@ func validateProp(prop interface{}, propDef AssetProp) (interface{}, error) { return nil, errors.WrapError(err, fmt.Sprintf("invalid '%s' (%s) asset property", propDef.Tag, propDef.Label)) } } else { - // Check if type is defined in assetList - subAssetType := FetchAssetType(dataTypeName) - if subAssetType == nil { - return nil, errors.NewCCError(fmt.Sprintf("invalid asset type named '%s'", propDef.DataType), 400) - } - // Check if received subAsset is a map var recvMap map[string]interface{} switch t := prop.(type) { @@ -80,8 +75,32 @@ func validateProp(prop interface{}, propDef AssetProp) (interface{}, error) { return nil, errors.NewCCError("asset reference must be an object", 400) } - // Add assetType to received object - recvMap["@assetType"] = dataTypeName + if dataTypeName != "@asset" { + // Check if type is defined in assetList + subAssetType := FetchAssetType(dataTypeName) + if subAssetType == nil { + return nil, errors.NewCCError(fmt.Sprintf("invalid asset type named '%s'", propDef.DataType), 400) + } + + // Add assetType to received object + recvMap["@assetType"] = dataTypeName + } else { + keyStr, keyExists := recvMap["@key"].(string) + assetTypeStr, typeExists := recvMap["@assetType"].(string) + if !keyExists && !typeExists { + return nil, errors.NewCCError("invalid asset reference: missing '@key' or '@assetType' property", http.StatusBadRequest) + } + if keyExists { + assetTypeName := keyStr[:strings.IndexByte(keyStr, ':')] + if !typeExists { + recvMap["@assetType"] = assetTypeName + } else { + if assetTypeName != assetTypeStr { + return nil, errors.NewCCError("invalid asset reference: '@key' and '@assetType' properties do not match", http.StatusBadRequest) + } + } + } + } // Check if all key props are included key, err := NewKey(recvMap) diff --git a/go.mod b/go.mod index 1e08ede..3072962 100644 --- a/go.mod +++ b/go.mod @@ -1,30 +1,37 @@ module github.com/hyperledger-labs/cc-tools -go 1.14 +go 1.21 require ( - github.com/fsnotify/fsnotify v1.4.9 // indirect - github.com/golang/protobuf v1.4.3 - github.com/google/go-cmp v0.5.4 // indirect + github.com/golang/protobuf v1.5.3 github.com/google/uuid v1.3.0 github.com/hyperledger/fabric v2.1.1+incompatible github.com/hyperledger/fabric-chaincode-go v0.0.0-20210603161043-af0e3898842a github.com/hyperledger/fabric-protos-go v0.0.0-20210528200356-82833ecdac31 + github.com/stretchr/testify v1.6.1 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/kr/text v0.2.0 // indirect github.com/miekg/pkcs11 v1.0.3 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/viper v1.7.1 // indirect - github.com/stretchr/testify v1.6.1 github.com/sykesm/zap-logfmt v0.0.4 // indirect + go.uber.org/atomic v1.6.0 // indirect + go.uber.org/multierr v1.5.0 // indirect go.uber.org/zap v1.16.0 // indirect - golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect - golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b // indirect - golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect - golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect - google.golang.org/grpc v1.35.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/net v0.23.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect + google.golang.org/grpc v1.56.3 // indirect + google.golang.org/protobuf v1.30.0 // indirect gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 666cb16..bf0f3d7 100644 --- a/go.sum +++ b/go.sum @@ -24,10 +24,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -39,10 +37,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= @@ -63,34 +57,24 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= @@ -127,7 +111,6 @@ github.com/hyperledger/fabric-protos-go v0.0.0-20210528200356-82833ecdac31/go.mo github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -175,7 +158,6 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= @@ -186,9 +168,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -207,7 +187,6 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= @@ -238,9 +217,8 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -260,9 +238,8 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b h1:GgiSbuUyC0BlbUmHQBgFqu32eiRR/CEYdjOjOd4zE6Y= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -278,8 +255,8 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -303,16 +280,13 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -335,13 +309,10 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa h1:5E4dL8+NgFOgjwbTKz+OOEGGhP+ectTmF842l6KjupQ= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -361,26 +332,18 @@ google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8= -google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc= +google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -397,8 +360,8 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/mock/mockstub.go b/mock/mockstub.go index 718fdbd..2a498c7 100644 --- a/mock/mockstub.go +++ b/mock/mockstub.go @@ -17,6 +17,7 @@ import ( "github.com/golang/protobuf/ptypes/timestamp" "github.com/hyperledger/fabric-chaincode-go/shim" "github.com/hyperledger/fabric-protos-go/ledger/queryresult" + "github.com/hyperledger/fabric-protos-go/msp" pb "github.com/hyperledger/fabric-protos-go/peer" ) @@ -291,10 +292,10 @@ func (stub *MockStub) GetStateByRange(startKey, endKey string) (shim.StateQueryI return NewMockStateRangeQueryIterator(stub, startKey, endKey), nil } -//To ensure that simple keys do not go into composite key namespace, -//we validate simplekey to check whether the key starts with 0x00 (which -//is the namespace for compositeKey). This helps in avoding simple/composite -//key collisions. +// To ensure that simple keys do not go into composite key namespace, +// we validate simplekey to check whether the key starts with 0x00 (which +// is the namespace for compositeKey). This helps in avoding simple/composite +// key collisions. func validateSimpleKeys(simpleKeys ...string) error { for _, key := range simpleKeys { if len(key) > 0 && key[0] == compositeKeyNamespace[0] { @@ -508,10 +509,25 @@ func NewMockStub(name string, cc shim.Chaincode) *MockStub { s.Keys = list.New() s.ChaincodeEventsChannel = make(chan *pb.ChaincodeEvent, 100) //define large capacity for non-blocking setEvent calls. s.Decorations = make(map[string][]byte) - + s.Creator, _ = newCreator(name, []byte{}) return s } +// NewMockStubWithCert Constructor to initialize mock stub with a certificate. Useful for transactions with robust permissioning. +func NewMockStubWithCert(name string, cc shim.Chaincode, cert []byte) (*MockStub, error) { + s := NewMockStub(name, cc) + var err error + s.Creator, err = newCreator(name, cert) + + return s, err +} + +func newCreator(orgMSP string, cert []byte) ([]byte, error) { + sid := &msp.SerializedIdentity{Mspid: orgMSP, + IdBytes: cert} + return proto.Marshal(sid) +} + /***************************** Range Query Iterator *****************************/ diff --git a/test/assets_assetType_test.go b/test/assets_assetType_test.go index 2270398..760557a 100644 --- a/test/assets_assetType_test.go +++ b/test/assets_assetType_test.go @@ -83,6 +83,17 @@ func TestAssetTypeToMap(t *testing.T) { "dataType": "@object", "writers": emptySlice, }, + { + "tag": "association", + "label": "Association", + "description": "", + "isKey": false, + "required": false, + "readOnly": false, + "defaultValue": nil, + "dataType": "[]->@asset", + "writers": emptySlice, + }, }, "readers": emptySlice, "dynamic": false, @@ -198,6 +209,17 @@ func TestAssetTypeListToMap(t *testing.T) { "dataType": "@object", "writers": emptySlice, }, + { + "tag": "association", + "label": "Association", + "description": "", + "isKey": false, + "required": false, + "readOnly": false, + "defaultValue": nil, + "dataType": "[]->@asset", + "writers": emptySlice, + }, }, "readers": emptySlice, "dynamic": false, diff --git a/test/assets_dataType_test.go b/test/assets_dataType_test.go index 2f1d1e4..7556559 100644 --- a/test/assets_dataType_test.go +++ b/test/assets_dataType_test.go @@ -1,7 +1,9 @@ package test import ( + "encoding/json" "log" + "net/http" "reflect" "testing" @@ -21,7 +23,7 @@ func testParseValid(t *testing.T, dtype assets.DataType, inputVal interface{}, e log.Printf("parsing %v expected key: %q but got %q\n", inputVal, expectedKey, key) t.FailNow() } - if val != expectedVal { + if !reflect.DeepEqual(val, expectedVal) { log.Printf("parsing %v expected parsed val: \"%v\" of type %s but got \"%v\" of type %s\n", inputVal, expectedVal, reflect.TypeOf(expectedVal), val, reflect.TypeOf(val)) t.FailNow() } @@ -92,3 +94,86 @@ func TestDataTypeBoolean(t *testing.T) { testParseInvalid(t, dtype, "True", 400) testParseInvalid(t, dtype, 37.3, 400) } + +func TestDataTypeObject(t *testing.T) { + dtypeName := "@object" + dtype, exists := assets.DataTypeMap()[dtypeName] + if !exists { + log.Printf("%s datatype not declared in DataTypeMap\n", dtypeName) + t.FailNow() + } + + testCase1 := map[string]interface{}{ + "key1": "value1", + "key2": "value2", + } + testCaseByte1, _ := json.Marshal(testCase1) + testCaseExpected1 := map[string]interface{}{ + "@assetType": "@object", + "key1": "value1", + "key2": "value2", + } + testCaseExpectedByte1, _ := json.Marshal(testCaseExpected1) + + testParseValid(t, dtype, testCase1, string(testCaseExpectedByte1), testCase1) + testParseValid(t, dtype, testCaseByte1, string(testCaseExpectedByte1), testCase1) + testParseValid(t, dtype, string(testCaseByte1), string(testCaseExpectedByte1), testCase1) + testParseInvalid(t, dtype, "{'key': 'value'}", http.StatusBadRequest) +} +func TestDataTypeAsset(t *testing.T) { + dtypeName := "->@asset" + dtype, exists := assets.DataTypeMap()[dtypeName] + if !exists { + log.Printf("%s datatype not declared in DataTypeMap\n", dtypeName) + t.FailNow() + } + + testCase1 := map[string]interface{}{ + "@assetType": "person", + "id": "42186475006", + } + testCaseExpected1 := map[string]interface{}{ + "@assetType": "person", + "id": "42186475006", + "@key": "person:a11e54a8-7e23-5d16-9fed-45523dd96bfa", + } + testCaseExpectedByte1, _ := json.Marshal(testCaseExpected1) + testParseValid(t, dtype, testCase1, string(testCaseExpectedByte1), testCaseExpected1) + + testCase2 := map[string]interface{}{ + "@assetType": "book", + "title": "Book Name", + "author": "Author Name", + "@key": "book:983a78df-9f0e-5ecb-baf2-4a8698590c81", + } + testCaseExpectedByte2, _ := json.Marshal(testCase2) + testParseValid(t, dtype, testCase2, string(testCaseExpectedByte2), testCase2) + testParseValid(t, dtype, testCaseExpectedByte2, string(testCaseExpectedByte2), testCase2) + testParseValid(t, dtype, string(testCaseExpectedByte2), string(testCaseExpectedByte2), testCase2) + + testCase3 := map[string]interface{}{ + "@key": "library:ca683ce5-05bf-5799-a359-b28a1f981f96", + } + testCaseExpected3 := map[string]interface{}{ + "@assetType": "library", + "@key": "library:ca683ce5-05bf-5799-a359-b28a1f981f96", + } + testCaseExpectedByte3, _ := json.Marshal(testCaseExpected3) + testParseValid(t, dtype, testCase3, string(testCaseExpectedByte3), testCase3) + + invalidCase1 := map[string]interface{}{ + "@assetType": "library", + } + testParseInvalid(t, dtype, invalidCase1, http.StatusBadRequest) + + invalidCase2 := map[string]interface{}{ + "@assetType": "inexistant", + } + testParseInvalid(t, dtype, invalidCase2, http.StatusBadRequest) + + invalidCase3 := map[string]interface{}{ + "@assetType": "person", + "@key": "library:ca683ce5-05bf-5799-a359-b28a1f981f96", + } + testParseInvalid(t, dtype, invalidCase3, http.StatusBadRequest) +} diff --git a/test/assets_get_test.go b/test/assets_get_test.go index 579f8dc..5ec10e2 100644 --- a/test/assets_get_test.go +++ b/test/assets_get_test.go @@ -160,6 +160,7 @@ func TestGetCommittedAsset(t *testing.T) { log.Println(err) t.FailNow() } + if !reflect.DeepEqual(*gotAsset, expectedResponse) { log.Println("these should be deeply equal") log.Println(expectedResponse) diff --git a/test/chaincode_test.go b/test/chaincode_test.go index de57b85..ee0fea9 100644 --- a/test/chaincode_test.go +++ b/test/chaincode_test.go @@ -76,6 +76,12 @@ var testAssetList = []assets.AssetType{ Label: "Other Info", DataType: "@object", }, + { + // Generic JSON object + Tag: "association", + Label: "Association", + DataType: "[]->@asset", + }, }, }, { diff --git a/test/main_test.go b/test/main_test.go index fcc8af5..3161ac8 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -15,7 +15,7 @@ func TestMain(m *testing.M) { tx.InitHeader(tx.Header{ Name: "CC Tools Test", - Version: "v0.8.1", + Version: "v1.0.0", Colors: map[string][]string{ "@default": {"#4267B2", "#34495E", "#ECF0F1"}, }, diff --git a/test/tx_createAsset_test.go b/test/tx_createAsset_test.go index fe44fa3..bc0bed8 100644 --- a/test/tx_createAsset_test.go +++ b/test/tx_createAsset_test.go @@ -88,6 +88,112 @@ func TestCreateAsset(t *testing.T) { } } +func TestCreateAssetGenericAssociation(t *testing.T) { + stub := mock.NewMockStub("org1MSP", new(testCC)) + book := map[string]interface{}{ + "@assetType": "book", + "title": "Book Title", + "author": "Author", + } + + library := map[string]interface{}{ + "@assetType": "library", + "name": "Library Name", + } + + req := map[string]interface{}{ + "asset": []map[string]interface{}{book, library}, + } + reqBytes, err := json.Marshal(req) + if err != nil { + t.FailNow() + } + + res := stub.MockInvoke("createAsset", [][]byte{ + []byte("createAsset"), + reqBytes, + }) + + person := map[string]interface{}{ + "@assetType": "person", + "name": "Maria", + "id": "318.207.920-48", + "association": []map[string]interface{}{book, library}, + } + req = map[string]interface{}{ + "asset": []map[string]interface{}{person}, + } + reqBytes, err = json.Marshal(req) + if err != nil { + t.FailNow() + } + + res = stub.MockInvoke("createAsset", [][]byte{ + []byte("createAsset"), + reqBytes, + }) + lastUpdated, _ := stub.GetTxTimestamp() + expectedResponse := map[string]interface{}{ + "@key": "person:47061146-c642-51a1-844a-bf0b17cb5e19", + "@lastTouchBy": "org1MSP", + "@lastTx": "createAsset", + "@lastUpdated": lastUpdated.AsTime().Format(time.RFC3339), + "@assetType": "person", + "name": "Maria", + "id": "31820792048", + "height": 0.0, + "association": []interface{}{ + map[string]interface{}{ + "@assetType": "book", + "@key": "book:46179ee0-5503-54e1-aa51-bbaad559638b", + }, + map[string]interface{}{ + "@assetType": "library", + "@key": "library:9aeaddc4-d1cb-5b03-9ad0-1d9af7416c2e", + }, + }, + } + + if res.GetStatus() != 200 { + log.Println(res) + t.FailNow() + } + + var resPayload []map[string]interface{} + err = json.Unmarshal(res.GetPayload(), &resPayload) + if err != nil { + log.Println(err) + t.FailNow() + } + + if len(resPayload) != 1 { + log.Println("response length should be 1") + t.FailNow() + } + + if !reflect.DeepEqual(resPayload[0], expectedResponse) { + log.Println("these should be equal") + log.Printf("%#v\n", resPayload[0]) + log.Printf("%#v\n", expectedResponse) + t.FailNow() + } + + var state map[string]interface{} + stateBytes := stub.State["person:47061146-c642-51a1-844a-bf0b17cb5e19"] + err = json.Unmarshal(stateBytes, &state) + if err != nil { + log.Println(err) + t.FailNow() + } + + if !reflect.DeepEqual(state, expectedResponse) { + log.Println("these should be equal") + log.Printf("%#v\n", state) + log.Printf("%#v\n", expectedResponse) + t.FailNow() + } +} + func TestCreateAssetEmptyList(t *testing.T) { stub := mock.NewMockStub("org1MSP", new(testCC)) diff --git a/test/tx_getDataTypes_test.go b/test/tx_getDataTypes_test.go index 48b06c4..41d1639 100644 --- a/test/tx_getDataTypes_test.go +++ b/test/tx_getDataTypes_test.go @@ -51,6 +51,12 @@ func TestGetDataTypes(t *testing.T) { }, "DropDownValues": nil, }, + "->@asset": map[string]interface{}{ + "acceptedFormats": []interface{}{ + "->@asset", + }, + "DropDownValues": nil, + }, } err := invokeAndVerify(stub, "getDataTypes", nil, expectedResponse, 200) if err != nil { diff --git a/test/tx_getHeader_test.go b/test/tx_getHeader_test.go index 77ea5f6..b9e9aec 100644 --- a/test/tx_getHeader_test.go +++ b/test/tx_getHeader_test.go @@ -11,7 +11,7 @@ func TestGetHeader(t *testing.T) { stub := mock.NewMockStub("org1MSP", new(testCC)) expectedResponse := map[string]interface{}{ - "ccToolsVersion": "v0.8.1", + "ccToolsVersion": "v1.0.0", "colors": []interface{}{ "#4267B2", "#34495E", @@ -20,7 +20,7 @@ func TestGetHeader(t *testing.T) { "name": "CC Tools Test", "orgMSP": "org1MSP", "orgTitle": "CC Tools Demo", - "version": "v0.8.1", + "version": "v1.0.0", } err := invokeAndVerify(stub, "getHeader", nil, expectedResponse, 200) if err != nil { diff --git a/test/tx_getSchema_test.go b/test/tx_getSchema_test.go index 1b1f2a1..baf8b4a 100644 --- a/test/tx_getSchema_test.go +++ b/test/tx_getSchema_test.go @@ -120,6 +120,16 @@ func TestGetSchema(t *testing.T) { "tag": "info", "writers": nil, }, + map[string]interface{}{ + "dataType": "[]->@asset", + "description": "", + "isKey": false, + "label": "Association", + "readOnly": false, + "required": false, + "tag": "association", + "writers": nil, + }, }, } err = invokeAndVerify(stub, "getSchema", req, expectedPersonSchema, 200) diff --git a/transactions/getArgs.go b/transactions/getArgs.go index 9e3cc69..d100121 100644 --- a/transactions/getArgs.go +++ b/transactions/getArgs.go @@ -3,6 +3,7 @@ package transactions import ( "encoding/json" "fmt" + "net/http" "strings" "github.com/hyperledger-labs/cc-tools/assets" @@ -122,11 +123,17 @@ func validateTxArg(argType string, arg interface{}) (interface{}, errors.ICCErro return nil, errors.NewCCError("invalid argument format", 400) } assetTypeName, ok := argMap["@assetType"] - if ok && assetTypeName != argType { // in case an @assetType is specified, check if it is correct - return nil, errors.NewCCError(fmt.Sprintf("invalid @assetType '%s' (expecting '%s')", assetTypeName, argType), 400) - } - if !ok { // if @assetType is not specified, inject it - argMap["@assetType"] = argType + if argType != "@asset" { + if ok && assetTypeName != argType { // in case an @assetType is specified, check if it is correct + return nil, errors.NewCCError(fmt.Sprintf("invalid @assetType '%s' (expecting '%s')", assetTypeName, argType), 400) + } + if !ok { // if @assetType is not specified, inject it + argMap["@assetType"] = argType + } + } else { + if !ok { + return nil, errors.NewCCError("missing @assetType", http.StatusBadRequest) + } } key, err := assets.NewKey(argMap) if err != nil { diff --git a/transactions/getHeader.go b/transactions/getHeader.go index 573f27b..a5ab9c3 100644 --- a/transactions/getHeader.go +++ b/transactions/getHeader.go @@ -19,7 +19,7 @@ var header Header func InitHeader(h Header) { header = h - header.CCToolsVersion = "v0.8.1" + header.CCToolsVersion = "v1.0.0" } // GetHeader returns data in CCHeader diff --git a/transactions/getSchema.go b/transactions/getSchema.go index 60e60e2..daea396 100644 --- a/transactions/getSchema.go +++ b/transactions/getSchema.go @@ -59,6 +59,7 @@ var GetSchema = Transaction{ Readers []string `json:"readers,omitempty"` Writers []string `json:"writers"` Dynamic bool `json:"dynamic"` + Collection string `json:"collection,omitempty"` } var assetList []assetListElem for _, assetTypeDef := range assetTypeList { @@ -68,6 +69,7 @@ var GetSchema = Transaction{ Description: assetTypeDef.Description, Readers: assetTypeDef.Readers, Dynamic: assetTypeDef.Dynamic, + Collection: assetTypeDef.Collection, }) } diff --git a/transactions/getTx.go b/transactions/getTx.go index 4ad5f1c..baf98f9 100644 --- a/transactions/getTx.go +++ b/transactions/getTx.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + "github.com/hyperledger-labs/cc-tools/accesscontrol" "github.com/hyperledger-labs/cc-tools/errors" sw "github.com/hyperledger-labs/cc-tools/stubwrapper" ) @@ -50,10 +51,10 @@ var getTx = Transaction{ // If user requested asset list type txListElem struct { - Tag string `json:"tag"` - Label string `json:"label"` - Description string `json:"description"` - Callers []string `json:"callers,omitempty"` + Tag string `json:"tag"` + Label string `json:"label"` + Description string `json:"description"` + Callers []accesscontrol.Caller `json:"callers,omitempty"` } var txRetList []txListElem for _, tx := range txList { diff --git a/transactions/run.go b/transactions/run.go index 1573f81..d3d3db9 100644 --- a/transactions/run.go +++ b/transactions/run.go @@ -2,8 +2,8 @@ package transactions import ( "fmt" - "regexp" + "github.com/hyperledger-labs/cc-tools/accesscontrol" "github.com/hyperledger-labs/cc-tools/assets" "github.com/hyperledger-labs/cc-tools/errors" sw "github.com/hyperledger-labs/cc-tools/stubwrapper" @@ -40,38 +40,13 @@ func Run(stub shim.ChaincodeStubInterface) ([]byte, errors.ICCError) { } // Verify callers permissions - if tx.Callers != nil { - // Get tx caller MSP ID - txCaller, err := sw.GetMSPID() - if err != nil { - return nil, errors.WrapErrorWithStatus(err, "error getting tx caller", 500) - } + callPermission, err := accesscontrol.AllowCaller(stub, tx.Callers) + if err != nil { + return nil, errors.WrapError(err, "failed to check permissions") + } - // Check if caller is allowed - callPermission := false - for _, c := range tx.Callers { - if len(c) <= 1 { - continue - } - if c[0] == '$' { // if caller is regexp - match, err := regexp.MatchString(c[1:], txCaller) - if err != nil { - return nil, errors.NewCCError("failed to check if caller matches regexp", 500) - } - if match { - callPermission = true - break - } - } else { // if caller is not regexp - if c == txCaller { - callPermission = true - break - } - } - } - if !callPermission { - return nil, errors.NewCCError(fmt.Sprintf("%s cannot call this transaction", txCaller), 403) - } + if !callPermission { + return nil, errors.NewCCError("current caller not allowed", 403) } return tx.Routine(sw, reqMap) diff --git a/transactions/startupCheck.go b/transactions/startupCheck.go index fe8a731..0fb5d65 100644 --- a/transactions/startupCheck.go +++ b/transactions/startupCheck.go @@ -15,13 +15,13 @@ func StartupCheck() errors.ICCError { for _, tx := range txList { txName := tx.Tag for _, c := range tx.Callers { - if len(c) <= 1 { + if len(c.MSP) <= 1 { continue } - if c[0] == '$' { - _, err := regexp.Compile(c[1:]) + if c.MSP[0] == '$' { + _, err := regexp.Compile(c.MSP[1:]) if err != nil { - return errors.WrapErrorWithStatus(err, fmt.Sprintf("invalid caller regular expression %s for tx %s", c, txName), 500) + return errors.WrapErrorWithStatus(err, fmt.Sprintf("invalid caller msp regular expression %s for tx %s", c, txName), 500) } } } @@ -41,7 +41,7 @@ func StartupCheck() errors.ICCError { dtype != "@object" { if strings.HasPrefix(dtype, "->") { dtype = strings.TrimPrefix(dtype, "->") - if assets.FetchAssetType(dtype) == nil { + if assets.FetchAssetType(dtype) == nil && dtype != "@asset" { return errors.NewCCError(fmt.Sprintf("invalid arg type %s in tx %s", arg.DataType, txName), 500) } } else { diff --git a/transactions/transaction.go b/transactions/transaction.go index 1455524..c36fea0 100644 --- a/transactions/transaction.go +++ b/transactions/transaction.go @@ -1,6 +1,7 @@ package transactions import ( + "github.com/hyperledger-labs/cc-tools/accesscontrol" "github.com/hyperledger-labs/cc-tools/errors" sw "github.com/hyperledger-labs/cc-tools/stubwrapper" ) @@ -11,7 +12,7 @@ type Transaction struct { // Regexp is supported by putting '$' before the MSP regexp e.g. []string{`$org\dMSP`}. // Please note this restriction DOES NOT protect ledger data from being // read by unauthorized organizations, this should be done with Private Data. - Callers []string `json:"callers,omitempty"` + Callers []accesscontrol.Caller `json:"callers,omitempty"` // Tag is how the tx will be called. Tag string `json:"tag"` diff --git a/transactions/txList.go b/transactions/txList.go index f8b1271..0786474 100644 --- a/transactions/txList.go +++ b/transactions/txList.go @@ -1,6 +1,9 @@ package transactions -import "github.com/hyperledger-labs/cc-tools/assets" +import ( + "github.com/hyperledger-labs/cc-tools/accesscontrol" + "github.com/hyperledger-labs/cc-tools/assets" +) var txList = []Transaction{} @@ -45,7 +48,14 @@ func FetchTx(txName string) *Transaction { func InitTxList(l []Transaction) { txList = append(l, basicTxs...) if assets.GetEnabledDynamicAssetType() { - callers := assets.GetAssetAdminsDynamicAssetType() + callersMSP := assets.GetAssetAdminsDynamicAssetType() + var callers []accesscontrol.Caller + for _, msp := range callersMSP { + callers = append(callers, accesscontrol.Caller{ + MSP: msp, + }) + } + for i := range dynamicAssetTypesTxs { if dynamicAssetTypesTxs[i].Tag != "loadAssetTypeList" { dynamicAssetTypesTxs[i].Callers = callers