-
Notifications
You must be signed in to change notification settings - Fork 129
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
Pass dapr api token #598
Pass dapr api token #598
Conversation
Signed-off-by: Deepanshu Agarwal <[email protected]>
Great changes! The only question I have is if/how these changes were tested and verified and if it is possible to create a test (or modify an existing one) in order to ensure that this new behavior doesn't break in the future. |
address = getAddress(host, port) | ||
self.__obj = client.TaskHubGrpcClient(host_address=address) | ||
metadata = [] | ||
if apiToken is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[not blocking] Are you sure you even need the API token as parameter? I'd rather refer people to using the settings package to set the token:
from dapr.conf import settings
settings.DAPR_API_TOKEN='mytokenhere'
And as you know that is only necessary if the token itself isn't already set as an environment variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can keep the parameter if you'd like to have it for consistency with other SDKs - but if other SDKs do not use this, then I recommend also removing it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed api_token option. It will pick only if corresponding env. setting is there.
python DaprClient also doing the same thing - so to maintain consistency.
@@ -17,6 +17,7 @@ | |||
|
|||
from dapr.conf import settings | |||
|
|||
DAPR_API_TOKEN_HEADER = 'dapr-api-token' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please import this instead so we can change everything in one place if it ever must change.
from dapr.ext.workflow.util import DAPR_API_TOKEN_HEADER
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, used from original place only now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some feedback - 2 small questions, but you do need to use snake case instead of camelcase :)
@@ -37,9 +38,14 @@ class DaprWorkflowClient: | |||
This client is intended to be used by workflow application, not by general purpose | |||
application. | |||
""" | |||
def __init__(self, host: Optional[str] = None, port: Optional[str] = None): | |||
def __init__(self, host: Optional[str] = None, port: Optional[str] = None, apiToken: Optional[str] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __init__(self, host: Optional[str] = None, port: Optional[str] = None, apiToken: Optional[str] = None): | |
def __init__(self, host: Optional[str] = None, port: Optional[str] = None, api_token: Optional[str] = None): |
Python requires snake case instead of camelcase per style guide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the option.
@@ -31,10 +32,15 @@ class WorkflowRuntime: | |||
"""WorkflowRuntime is the entry point for registering workflows and activities. | |||
""" | |||
|
|||
def __init__(self, host: Optional[str] = None, port: Optional[str] = None): | |||
def __init__(self, host: Optional[str] = None, port: Optional[str] = None, apiToken: Optional[str] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this snake case. api_token
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the option.
def __init__(self, host: Optional[str] = None, port: Optional[str] = None): | ||
def __init__(self, host: Optional[str] = None, port: Optional[str] = None, apiToken: Optional[str] = None): | ||
metadata = [] | ||
if apiToken is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same feedback [not blocking] - do you really need this in the method signature?
In Python we really want folks to use our settings package to centrally set these things (if they are not already provided via environment variables)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, removed the option
Please run the linter and typecheck locally before updating this PR and fix issues.
Current issues for lint:
|
@RyanLettieri I do not think we should modify the examples - however, if you'd like a unit test / mock could be added here. To me this is not a blocking issue because this code is very straightforward and in line with what we have already in the SDK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow example also currently appears broken
== APP == Traceback (most recent call last):
== APP == File "/home/runner/work/python-sdk/python-sdk/examples/demo_workflow/app.py", line 113, in <module>
== APP == main()
== APP == File "/home/runner/work/python-sdk/python-sdk/examples/demo_workflow/app.py", line 49, in main
== APP == workflowRuntime = WorkflowRuntime(host, port)
== APP == File "/home/runner/work/python-sdk/python-sdk/ext/dapr-ext-workflow/dapr/ext/workflow/workflow_runtime.py", line 43, in __init__
== APP == self.__worker = worker.TaskHubGrpcWorker(host_address=address, metadata=metadata)
== APP == TypeError: __init__() got an unexpected keyword argument 'metadata'
This is likely caused by the fact you made metadata
a list now instead of a tuple. See comment above.
@DeepanshuA was there no update to |
@DeepanshuA @RyanLettieri this PR cannot work right now. This needs to be done:
|
ext/dapr-ext-workflow/dapr/ext/workflow/dapr_workflow_client.py
Outdated
Show resolved
Hide resolved
Yeah @berndverst. |
Signed-off-by: Deepanshu Agarwal <[email protected]>
@DeepanshuA now that microsoft/durabletask-python#16 is merged, please cut a release and complete this PR so that this will not delay the Python SDK release. Thanks! |
Signed-off-by: Deepanshu Agarwal <[email protected]>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #598 +/- ##
==========================================
- Coverage 86.42% 86.40% -0.02%
==========================================
Files 74 74
Lines 3595 3605 +10
==========================================
+ Hits 3107 3115 +8
- Misses 488 490 +2
☔ View full report in Codecov by Sentry. |
Description
microsoft/durabletask-python#16 is merged. So, updating this PR.
This change enables user to pass an API token to WorkflowRuntime and DaprWorkflowClient.
If user doesn't pass explicitly and API Token and environment variable is set for DAPR_API_TOKEN, it will be picked.
Issue reference
We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.
Please reference the issue this PR will close: #594
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: