Skip to content

Commit

Permalink
Fix lint issues and GET_NOC_ROOT_BY_VID_AND_SKID REST query
Browse files Browse the repository at this point in the history
  • Loading branch information
akarabashov committed Apr 18, 2024
1 parent af46592 commit 39a46b3
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9877,7 +9877,7 @@ paths:
format: int32
tags:
- Query
/dcl/pki/noc_root_certificates/{vid}/{subjectKeyId}:
/dcl/pki/noc-root-certificates/{vid}/{subjectKeyId}:
get:
summary: Queries a NocRootCertificatesByVidAndSkid by index.
operationId: NocRootCertificatesByVidAndSkid
Expand Down
2 changes: 1 addition & 1 deletion proto/pki/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ service Query {

// Queries a NocRootCertificatesByVidAndSkid by index.
rpc NocRootCertificatesByVidAndSkid(QueryGetNocRootCertificatesByVidAndSkidRequest) returns (QueryGetNocRootCertificatesByVidAndSkidResponse) {
option (google.api.http).get = "/dcl/pki/noc_root_certificates/{vid}/{subjectKeyId}";
option (google.api.http).get = "/dcl/pki/noc-root-certificates/{vid}/{subjectKeyId}";
}

// Queries a list of NocRootCertificates items.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,11 +845,11 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
* @tags Query
* @name QueryNocRootCertificatesByVidAndSkid
* @summary Queries a NocRootCertificatesByVidAndSkid by index.
* @request GET:/dcl/pki/noc_root_certificates/{vid}/{subjectKeyId}
* @request GET:/dcl/pki/noc-root-certificates/{vid}/{subjectKeyId}
*/
queryNocRootCertificatesByVidAndSkid = (vid: number, subjectKeyId: string, params: RequestParams = {}) =>
this.request<PkiQueryGetNocRootCertificatesByVidAndSkidResponse, RpcStatus>({
path: `/dcl/pki/noc_root_certificates/${vid}/${subjectKeyId}`,
path: `/dcl/pki/noc-root-certificates/${vid}/${subjectKeyId}`,
method: "GET",
format: "json",
...params,
Expand Down
2 changes: 1 addition & 1 deletion x/pki/handler_revoke_noc_root_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func TestHandler_RevokeNocX509RootCert_RevokeWithSerialNumber(t *testing.T) {
require.Equal(t, 1, len(revNocRoot.Certs))
require.Equal(t, testconstants.NocRootCert1CopySerialNumber, revNocRoot.Certs[0].SerialNumber)

// query noc root certificate by VID and SKID should return only one root cert
// query noc root certificate by VID and SKID
nocRootCertificatesByVidAndSkid, err := queryNocRootCertificatesByVidAndSkid(setup, testconstants.Vid, testconstants.NocRootCert1SubjectKeyID)
require.NoError(t, err)
require.Equal(t, testconstants.NocRootCert1SubjectKeyID, nocRootCertificatesByVidAndSkid.SubjectKeyId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/zigbee-alliance/distributed-compliance-ledger/x/pki/types"
)

// Prevent strconv unused error
// Prevent strconv unused error.
var _ = strconv.IntSize

func TestNocRootCertificatesByVidAndSkidQuerySingle(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions x/pki/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ func findCertificate(serialNumber string, certificates *[]*types.Certificate) (*

func filterCertificates(certificates *[]*types.Certificate, predicate CertificatePredicate) []*types.Certificate {
var result []*types.Certificate

for _, s := range *certificates {
if predicate(s) {
result = append(result, s)
}
}

return result
}
9 changes: 5 additions & 4 deletions x/pki/keeper/noc_root_certificates_by_vid_and_skid.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/zigbee-alliance/distributed-compliance-ledger/x/pki/types"
)

// SetNocRootCertificatesByVidAndSkid set a specific nocRootCertificatesByVidAndSkid in the store from its index
// SetNocRootCertificatesByVidAndSkid set a specific nocRootCertificatesByVidAndSkid in the store from its index.
func (k Keeper) SetNocRootCertificatesByVidAndSkid(ctx sdk.Context, nocRootCertificatesByVidAndSkid types.NocRootCertificatesByVidAndSkid) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), pkitypes.KeyPrefix(types.NocRootCertificatesByVidAndSkidKeyPrefix))
b := k.cdc.MustMarshal(&nocRootCertificatesByVidAndSkid)
Expand All @@ -18,7 +18,7 @@ func (k Keeper) SetNocRootCertificatesByVidAndSkid(ctx sdk.Context, nocRootCerti
), b)
}

// GetNocRootCertificatesByVidAndSkid returns a nocRootCertificatesByVidAndSkid from its index
// GetNocRootCertificatesByVidAndSkid returns a nocRootCertificatesByVidAndSkid from its index.
func (k Keeper) GetNocRootCertificatesByVidAndSkid(
ctx sdk.Context,
vid int32,
Expand All @@ -36,6 +36,7 @@ func (k Keeper) GetNocRootCertificatesByVidAndSkid(
}

k.cdc.MustUnmarshal(b, &val)

return val, true
}

Expand Down Expand Up @@ -63,7 +64,7 @@ func (k Keeper) AddNocRootCertificatesByVidAndSkid(ctx sdk.Context, nocCertifica
store.Set(types.NocRootCertificatesByVidAndSkidKey(nocCertificate.Vid, nocCertificate.SubjectKeyId), b)
}

// RemoveNocRootCertificatesByVidAndSkid removes a nocRootCertificatesByVidAndSkid from the store
// RemoveNocRootCertificatesByVidAndSkid removes a nocRootCertificatesByVidAndSkid from the store.
func (k Keeper) RemoveNocRootCertificatesByVidAndSkid(
ctx sdk.Context,
vid int32,
Expand Down Expand Up @@ -129,7 +130,7 @@ func (k Keeper) _filterAndSetNocRootCertificateByVidAndSkid(
}
}

// GetAllNocRootCertificatesByVidAndSkid returns all nocRootCertificatesByVidAndSkid
// GetAllNocRootCertificatesByVidAndSkid returns all nocRootCertificatesByVidAndSkid.
func (k Keeper) GetAllNocRootCertificatesByVidAndSkid(ctx sdk.Context) (list []types.NocRootCertificatesByVidAndSkid) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), pkitypes.KeyPrefix(types.NocRootCertificatesByVidAndSkidKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})
Expand Down
3 changes: 2 additions & 1 deletion x/pki/keeper/noc_root_certificates_by_vid_and_skid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/zigbee-alliance/distributed-compliance-ledger/x/pki/types"
)

// Prevent strconv unused error
// Prevent strconv unused error.
var _ = strconv.IntSize

func createNNocRootCertificatesByVidAndSkid(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.NocRootCertificatesByVidAndSkid {
Expand All @@ -23,6 +23,7 @@ func createNNocRootCertificatesByVidAndSkid(keeper *keeper.Keeper, ctx sdk.Conte

keeper.SetNocRootCertificatesByVidAndSkid(ctx, items[i])
}

return items
}

Expand Down
2 changes: 1 addition & 1 deletion x/pki/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func DefaultGenesis() *GenesisState {

// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
func (gs GenesisState) Validate() error { //nolint:gocyclo,vet
// Check for duplicated index in approvedCertificates
approvedCertificatesIndexMap := make(map[string]struct{})

Expand Down
8 changes: 4 additions & 4 deletions x/pki/types/key_noc_root_certificates_by_vid_and_skid.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "encoding/binary"
var _ binary.ByteOrder

const (
// NocRootCertificatesByVidAndSkidKeyPrefix is the prefix to retrieve all NocRootCertificatesByVidAndSkid
// NocRootCertificatesByVidAndSkidKeyPrefix is the prefix to retrieve all NocRootCertificatesByVidAndSkid.
NocRootCertificatesByVidAndSkidKeyPrefix = "NocRootCertificatesByVidAndSkid/value/"
)

// NocRootCertificatesByVidAndSkidKey returns the store key to retrieve a NocRootCertificatesByVidAndSkid from the index fields
// NocRootCertificatesByVidAndSkidKey returns the store key to retrieve a NocRootCertificatesByVidAndSkid from the index fields.
func NocRootCertificatesByVidAndSkidKey(
vid int32,
subjectKeyID string,
Expand All @@ -21,8 +21,8 @@ func NocRootCertificatesByVidAndSkidKey(
key = append(key, vidBytes...)
key = append(key, []byte("/")...)

subjectKeyIdBytes := []byte(subjectKeyID)
key = append(key, subjectKeyIdBytes...)
subjectKeyIDBytes := []byte(subjectKeyID)
key = append(key, subjectKeyIDBytes...)
key = append(key, []byte("/")...)

return key
Expand Down
2 changes: 1 addition & 1 deletion x/pki/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 39a46b3

Please sign in to comment.