Is there a way to authenticate the client other th...
# ask-community
t
Is there a way to authenticate the client other than using prefect auth login? I am trying to use prefect inside a CI/CD pipeline and it would be ideal to set an environment variable instead.
j
Yep! You can create a
TENANT
token (https://docs.prefect.io/orchestration/concepts/tokens.html#tenant) and set it as
PREFECT__CLOUD__AUTH_TOKEN
.
t
I get this error when using a tenant token with the client (venv) (base) % prefect register flow -f scripts/example.py -p example -l 488335898155-default /usr/local/anaconda3/lib/python3.8/site-packages/prefect/core/flow.py1674 UserWarning: No result handler was specified on your Flow. Cloud features such as input caching and resuming task runs from failure may not work properly.  registered_flow = client.register( Result check: OK Traceback (most recent call last):  File "/usr/local/anaconda3/bin/prefect", line 8, in <module>   sys.exit(cli())  File "/usr/local/anaconda3/lib/python3.8/site-packages/click/core.py", line 829, in call   return self.main(*args, **kwargs)  File "/usr/local/anaconda3/lib/python3.8/site-packages/click/core.py", line 782, in main   rv = self.invoke(ctx)  File "/usr/local/anaconda3/lib/python3.8/site-packages/click/core.py", line 1259, in invoke   return _process_result(sub_ctx.command.invoke(sub_ctx))  File "/usr/local/anaconda3/lib/python3.8/site-packages/click/core.py", line 1259, in invoke   return _process_result(sub_ctx.command.invoke(sub_ctx))  File "/usr/local/anaconda3/lib/python3.8/site-packages/click/core.py", line 1066, in invoke   return ctx.invoke(self.callback, **ctx.params)  File "/usr/local/anaconda3/lib/python3.8/site-packages/click/core.py", line 610, in invoke   return callback(*args, **kwargs)  File "/usr/local/anaconda3/lib/python3.8/site-packages/prefect/cli/register.py", line 100, in flow   flow.register(project_name=project, labels=label, idempotency_key=idempotency_key)  File "/usr/local/anaconda3/lib/python3.8/site-packages/prefect/core/flow.py", line 1674, in register   registered_flow = client.register(  File "/usr/local/anaconda3/lib/python3.8/site-packages/prefect/client/client.py", line 859, in register   flow_url = self.get_cloud_url("flow", flow_group_id)  File "/usr/local/anaconda3/lib/python3.8/site-packages/prefect/client/client.py", line 908, in get_cloud_url   tenant_slug = self.get_default_tenant_slug(as_user=as_user and using_cloud_api)  File "/usr/local/anaconda3/lib/python3.8/site-packages/prefect/client/client.py", line 941, in get_default_tenant_slug   res = self.graphql(query)  File "/usr/local/anaconda3/lib/python3.8/site-packages/prefect/client/client.py", line 319, in graphql   raise ClientError(result["errors"]) prefect.utilities.exceptions.ClientError: [{'path': ['user'], 'message': 'field "user" not found in type: \'query_root\'', 'extensions': {'path': '$.selectionSet.user', 'code': 'validation-failed', 'exception': {'message': 'field "user" not found in type: \'query_root\''}}}]
j
Ah, I see what's happening here. Add
no_url=True
to your
flow.register
call and things should work for now.
t
Thanks. That worked.