Skip to content

Refactor Specifications/Serializers#1555

Merged
KPrasch merged 33 commits intonucypher:masterfrom
vepkenez:refactor-specifications
Feb 6, 2020
Merged

Refactor Specifications/Serializers#1555
KPrasch merged 33 commits intonucypher:masterfrom
vepkenez:refactor-specifications

Conversation

@vepkenez
Copy link
Contributor

@vepkenez vepkenez commented Jan 5, 2020

  • refactors code around input and output specifications and serializers
  • removes 100+ lines of controllers/serializers code
  • adds new declarative format for io specification using py-marshmallow
  • adds improved validation for different datatypes
  • additional extensibility to validate keys, treasure maps, message kits etc.
  • allows for specifications to indicate type which enables better connect native integration as well as improved compatibility with REST/OPTIONS interfaces
  • required by [WIP] NuCypher ConnectNative Firefox Extension  #1299

@vepkenez vepkenez added the API label Jan 5, 2020
@vepkenez vepkenez added Bob 👨‍💼 Effects the "Bob" development area Alice 👩 Effects the "Alice" development area labels Jan 5, 2020
@vepkenez vepkenez changed the title Refactor Specifications [WIP] Refactor Specifications Jan 5, 2020
Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

@vepkenez - marshmellow definitely provides some specification clarity.

Some questions/comments for you.

n: int,
expiration: maya.MayaDT,
value: int = None,
first_period_reward: int = None,
Copy link
Member

@derekpierre derekpierre Jan 6, 2020

Choose a reason for hiding this comment

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

I believe @vzotova got rid of this parameter in #1459 - Perhaps it is best to rebase your PR on that branch?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think this parameter got removed

Copy link
Member

@derekpierre derekpierre Feb 3, 2020

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

#1459 is already merged into matster, so if this PR is currently based over the latest, and this variable is unused within this function it can be safely removed.

@vepkenez vepkenez force-pushed the refactor-specifications branch from 7a84aa8 to 8c0600e Compare January 7, 2020 20:01
@vepkenez vepkenez changed the title [WIP] Refactor Specifications Refactor Specifications/Serializers Jan 8, 2020
def get_serializer(self, interface_name: str):
return self.specification.get_serializer(inteface_name)

def _perform_action(self, action: str, request: dict) -> dict:
Copy link
Member

Choose a reason for hiding this comment

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

👏

@vepkenez vepkenez force-pushed the refactor-specifications branch 4 times, most recently from 761105a to e540f89 Compare January 12, 2020 20:26
Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

Unsure how I feel about the CLI integration - a bit of indirection - need to think a bit more about it.

Seems like we need some more tests...?

def _deserialize(self, value, attr, data, **kwargs):
return b64decode(value)

def _validate(self, value):
Copy link
Member

Choose a reason for hiding this comment

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

Can validate here simply be (?)

try:
    treasure_map = TreasureMap.from_bytes(value):
    return True
except:
    return False

I'm unsure whether the verify kwarg for from_bytes can remain as True (default) or needs to be set to False.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'd love it if that worked but unfortunately importing nucypher.policy.collections.Treasuremap causes a circular import since Bob is imported into that same file... which I think should maybe be a TODO but maybe there is some reason I'm not aware of.

@vepkenez
Copy link
Contributor Author

Unsure how I feel about the CLI integration - a bit of indirection - need to think a bit more about it.

I agree @derekpierre. It's not ideal. It was better before the cleanup-options PR. I think in the long run, the path is going to be to remove some of the complexity and have all of the CLI options be specified through similar schemas so it will actually be very simple.

so instead of

alice_verifying_key = fields.Key(
         load_only=True, required=True,
         click=click.option(
             '--alice-verifying-key',
             help="Alice's verifying key as a hexadecimal string",
             required=True, type=click.STRING,))

we'll have

alice_verifying_key = fields.Key(load_only=True, required=True, help="Alice's verifying key as a hexadecimal string")

And then the click stuff would be generated from that.
Because of the recent changes that happened concurrently to the work in this PR, I just folded it in in a way that would provide exactly matching results.

@KPrasch and I are planning to expand this concept to move most of the ad-hoc code that lives in the cli files into interfaces that can then be accessed through any entry point... but later.

@vepkenez vepkenez changed the title Refactor Specifications/Serializers [WIP] Refactor Specifications/Serializers Jan 17, 2020
jMyles added a commit that referenced this pull request Jan 28, 2020
jMyles added a commit that referenced this pull request Jan 28, 2020
jMyles added a commit that referenced this pull request Jan 28, 2020
@KPrasch KPrasch force-pushed the refactor-specifications branch from 6d59811 to e449341 Compare January 31, 2020 20:06
vepkenez and others added 23 commits February 6, 2020 03:20
handle TypeError in invalid RPC input
fix double encode
…ilaizers with schema modeling (Needs adiitional follow up).
…ication API (successful policy creation by RPC controller)
remove specifications references
remove bad idea
rename 'connect' to 'connect_cli'
Co-Authored-By: Derek Pierre <derek.pierre@gmail.com>
Co-Authored-By: Derek Pierre <derek.pierre@gmail.com>
@vepkenez vepkenez force-pushed the refactor-specifications branch from 3c5d1a8 to d656142 Compare February 6, 2020 11:25
Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

🎸

@derekpierre
Copy link
Member

I agree with @cygnusv that some commits can probably be squashed for a cleaner history.

@KPrasch KPrasch force-pushed the refactor-specifications branch from 7531d5e to 0a0761e Compare February 6, 2020 22:24
@KPrasch KPrasch merged commit 481af33 into nucypher:master Feb 6, 2020
@jMyles jMyles mentioned this pull request May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Alice 👩 Effects the "Alice" development area Bob 👨‍💼 Effects the "Bob" development area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants