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(gsheets2): added hidden properties #208

Closed
wants to merge 2 commits into from

Conversation

testinnplayin
Copy link
Contributor

@testinnplayin testinnplayin commented Sep 16, 2020

Change Summary

We added a class to hide certain properties from the user. These can be divided into two main categories: flags and non-flags.

Flags are properties that are required by the front to do something. In this case auth_flow_id is for initiating the oauth dance.

Non-flags are everything else. Non-flags can be divided into two categories: static and dynamic. Static non-flags are kept on the connector itself and have a '_' at the front of their name. Dynamic ones are kept on the new class. The reason why we put the static non-flags is so that we don't have to return them if we don't want to when we fetch hidden properties from the class that contains them.

On the front-end, we will eventually want to hide all properties that are stored in 'hidden_properties' on the connector. Those properties that begin with a '_' are hidden automatically.

Dynamic properties cannot be hidden with a '_' in front of their variable name because we can't set them afterwards.

Related issue number

#206

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable

@testinnplayin testinnplayin self-assigned this Sep 16, 2020
@testinnplayin testinnplayin added enhancement New feature or request good first issue Good for newcomers wip labels Sep 16, 2020
@codecov
Copy link

codecov bot commented Sep 16, 2020

Codecov Report

Merging #208 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #208      +/-   ##
==========================================
+ Coverage   97.74%   97.75%   +0.01%     
==========================================
  Files          43       43              
  Lines        2220     2231      +11     
==========================================
+ Hits         2170     2181      +11     
  Misses         50       50              
Impacted Files Coverage Δ
toucan_connectors/toucan_connector.py 98.59% <ø> (-0.02%) ⬇️
...ctors/google_sheets_2/google_sheets_2_connector.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 35b7e72...25ce76a. Read the comment docs.

@testinnplayin testinnplayin force-pushed the f/hide-certain-properties branch from df53a59 to 395e18a Compare September 16, 2020 14:21
@testinnplayin testinnplayin force-pushed the f/hide-certain-properties branch from 1d01379 to 25ce76a Compare September 16, 2020 15:44
Copy link
Member

@davinov davinov left a comment

Choose a reason for hiding this comment

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

Thanks for all this work and research you put it in.

However, reading the code, I feel weird about the hidden_properties method.
First : it contains only a token for now, so maybe a generic name is not appropriate to make following readers understand what this is about. IMO this name would have make sense if this was in the base class ToucanConnectors when we have no clue what will be inside.
Second : I have suggestion to ease the API of the connector. Since what the connector needs is to retrieve an access_token using the auth_flow_id, maybe it's easier to just pass to a connector the method that does this, and then the connector will be able use it when needed. What do you think about this ?


The `secrets` dictionary contains the `access_token` and a `refresh_token` (if there is one). Though `secrets` is optional during the initial creation of the connector, it is necessary for when the user wants to make requests to the connector. If there is no `access_token`, an Exception is thrown.
The `hidden_properties` propertie contains the `access_token` and a `refresh_token` (if there is one) in a class called `GoogleSheets2HiddenProperties`. Though `hidden_properties` is optional during the initial creation of the connector, it is necessary for when the user wants to make requests to the connector. If there is no `access_token`, an Exception is thrown. This is a dynamic *non-flag* property.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The `hidden_properties` propertie contains the `access_token` and a `refresh_token` (if there is one) in a class called `GoogleSheets2HiddenProperties`. Though `hidden_properties` is optional during the initial creation of the connector, it is necessary for when the user wants to make requests to the connector. If there is no `access_token`, an Exception is thrown. This is a dynamic *non-flag* property.
The `hidden_properties` property contains the `access_token` and a `refresh_token` (if there is one) in a class called `GoogleSheets2HiddenProperties`. Though `hidden_properties` is optional during the initial creation of the connector, it is necessary for when the user wants to make requests using the connector. If there is no `access_token`, an Exception is thrown. This is a dynamic property (not a static one).


The `baseroute` is fixed and is 'https://sheets.googleapis.com/v4/spreadsheets/'.
The `_baseroute` is fixed and is 'https://sheets.googleapis.com/v4/spreadsheets/'. It too is hidden from being rendered in the front. It is a static *non-flag*
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The `_baseroute` is fixed and is 'https://sheets.googleapis.com/v4/spreadsheets/'. It too is hidden from being rendered in the front. It is a static *non-flag*
The `_baseroute` is fixed and is 'https://sheets.googleapis.com/v4/spreadsheets/'. It too is hidden from being rendered in the front. It is a static property.

Or class property (something that doesn't change with the instance)


The `auth_flow` property marks this as being a connector that uses the connector_oauth_manager for the oauth dance.
The `_auth_flow` property marks this as being a connector that uses the connector_oauth_manager for the oauth dance. It is hidden from being rendered in the front but appears in the front as a flag for initiating the oauth dance. It is a static *flag*.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The `_auth_flow` property marks this as being a connector that uses the connector_oauth_manager for the oauth dance. It is hidden from being rendered in the front but appears in the front as a flag for initiating the oauth dance. It is a static *flag*.
The `_auth_flow` property marks this as being a connector that uses the connector_oauth_manager for the oauth dance. It is hidden from being rendered in the front but appears in the front as a flag for initiating the oauth dance. It is a static *property*.

I prefer we use the term property, which has a clear meaning in Python.
Flag is less clear : it suggest a boolean, a feature-flag, and many other things.

@@ -54,20 +57,41 @@ def get_form(cls, connector: 'GoogleSheets2Connector', current_config):
Secrets = Dict[str, Any]


class GoogleSheets2HiddenProperties(BaseModel):
"""
This class contains dynamic hidden properties for Google Sheets 2 that are not flags
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
This class contains dynamic hidden properties for Google Sheets 2 that are not flags
This class contains dynamic hidden properties for Google Sheets 2 that are not configured directly by a user, like tokens retrieved via OAuth2

auth_flow_id: Optional[str]

# The following should be hidden properties
# flagging variable; required for initiating the oauth dance
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines +90 to +91
# static variable
_baseroute = 'https://sheets.googleapis.com/v4/spreadsheets/'
Copy link
Member

Choose a reason for hiding this comment

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

Could we make that a real class property by the way ? That will save some db space and prevent to send it to the front-end

@@ -54,20 +57,41 @@ def get_form(cls, connector: 'GoogleSheets2Connector', current_config):
Secrets = Dict[str, Any]


class GoogleSheets2HiddenProperties(BaseModel):
Copy link
Member

Choose a reason for hiding this comment

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

I don't really see the value of using a Pydantic BaseModel here. Their usage is to validate/enforce a model, when some data comes from an uncertain source, like a form filled by someone, or an unknown database without a schema.
I wonder if a very simple dataclass would be enough here.

auth_flow_id: Optional[str]

# The following should be hidden properties
# flagging variable; required for initiating the oauth dance
_auth_flow = 'oauth2'
Copy link
Member

Choose a reason for hiding this comment

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

I took a few minutes to look at Pydantic's docs and saw the keep_untouched config option.
https://pydantic-docs.helpmanual.io/usage/model_config/

Is that worth to try ?

@testinnplayin
Copy link
Contributor Author

testinnplayin commented Sep 17, 2020

I put in generic terms because I'm thinking of the future of the connectors. We could do similar things with other connectors if we wanted to go this route.

If we have a retry policy in place for the connector, we might need the refresh token in secrets as well and not just the access token.

I'm not sure about your second point sorry.

@f-bb-toucantoco f-bb-toucantoco deleted the f/hide-certain-properties branch June 29, 2021 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Need Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants