Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/data): query iri by hash cli and rest endpoint #1107

Merged
merged 9 commits into from
May 23, 2022

Conversation

ryanchristo
Copy link
Member

@ryanchristo ryanchristo commented May 18, 2022

Description

Closes: #1087

This pull request adds a CLI command to query IRI by content hash using a json file as well as the ability to query IRI by raw and graph content hash properties using a gRPC REST endpoint.

CLI Command

./build/regen q data iri content.json
{
  "graph": {
    "hash": "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY=",
    "digest_algorithm": "DIGEST_ALGORITHM_BLAKE2B_256",
    "canonicalization_algorithm": "GRAPH_CANONICALIZATION_ALGORITHM_URDNA2015",
    "merkle_tree": "GRAPH_MERKLE_TREE_NONE_UNSPECIFIED"
  }
}

REST Endpoints

curl "localhost:1317/regen/data/v1/iri-by-raw?hash=YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY=&digest_algorithm=1"
curl "localhost:1317/regen/data/v1/iri-by-raw?hash=YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY=&digest_algorithm=DIGEST_ALGORITHM_BLAKE2B_256"
curl "localhost:1317/regen/data/v1/iri-by-graph?hash=YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY=&digest_algorithm=1&canonicalization_algorithm=1"
curl "localhost:1317/regen/data/v1/iri-by-graph?hash=YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY=&digest_algorithm=DIGEST_ALGORITHM_BLAKE2B_256&canonicalization_algorithm=GRAPH_CANONICALIZATION_ALGORITHM_URDNA2015"

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@codecov
Copy link

codecov bot commented May 18, 2022

Codecov Report

Merging #1107 (acef633) into master (484eeca) will increase coverage by 0.50%.
The diff coverage is 97.02%.

@@            Coverage Diff             @@
##           master    #1107      +/-   ##
==========================================
+ Coverage   68.44%   68.95%   +0.50%     
==========================================
  Files         212      213       +1     
  Lines       21390    21742     +352     
==========================================
+ Hits        14641    14992     +351     
+ Misses       5425     5418       -7     
- Partials     1324     1332       +8     
Flag Coverage Δ
experimental-codecov 68.82% <97.02%> (+0.48%) ⬆️
stable-codecov 63.08% <97.02%> (+0.68%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ryanchristo ryanchristo marked this pull request as ready for review May 18, 2022 21:33
@ryanchristo
Copy link
Member Author

cc @paul121 if you want to take a look as well.

Copy link
Contributor

@aleem1314 aleem1314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@technicallyty technicallyty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-approving, few nits 👍🏻

content.json Outdated
Comment on lines 1 to 4
{
"graph": {
"hash": "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY=",
"digest_algorithm": "DIGEST_ALGORITHM_BLAKE2B_256",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +268 to +269
require.Error(err)
require.Contains(string(bz), tc.errMsg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be able to use ErrorContains here

Copy link
Member Author

@ryanchristo ryanchristo May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bz is the response from GetRequest so we are checking if the error message is within the get response. The err above is from UnmarshalJSON. ErrorContains requires an error type and cannot be used with json.

Comment on lines +397 to +398
require.Error(err)
require.Contains(string(bz), tc.errMsg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. We need to check if the response contains the error message.

// encode base64 bytes to base64 string
encodedHash := base64.StdEncoding.EncodeToString(decodedHash)
// replace all instances of "+" with "%2b"
return strings.Replace(encodedHash, "+", "%2b", -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, why do we do the replace?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For REST endpoints, we cannot use + in the param value so it needs to be encoded.

@ryanchristo ryanchristo merged commit 8fdf355 into master May 23, 2022
@ryanchristo ryanchristo deleted the ryan/1087-query-by-hash branch May 23, 2022 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support to query IRI by ContentHash in gRPC and CLI
3 participants