vmware / versatile-data-kit

One framework to develop, deploy and operate data workflows with Python and SQL.
Apache License 2.0
423 stars 56 forks source link

vdk commands silently fails #3030

Open antoniivanov opened 8 months ago

antoniivanov commented 8 months ago

Describe the bug When attempting to set a secret using the vdk secrets --set-prompt command, the operation incorrectly reports success even when it fails due to authentication issues. This behavior is misleading and can lead to confusion about the actual state of the secret.

This behaviour is noticeable in other commands as well like vdk deploy or vdk show , vdk list, vdk create

Steps To Reproduce Steps to reproduce the behavior:

  1. Make sure the api token has expired or invalid and canont be refreshed . export VDK_API_TOKEN=wrong-token
  2. Execute the command vdk -v debug ist
  3. The command does not update the secret due to authentication issues (token expired and cannot be refreshed) but still succeeds.

Expected behavior The command should fail and return an error message indicating the failure due to authentication issues.

Log Snippet Command: vdk -v debug secrets --set-prompt "xxx_password" -n aivanov-xxx -t supercollider

... Passed parameters to function <function secrets_command at 0x123b80f40>: (), {'set_prompt': ('xxx_password',), 'name': 'aivanov-xxx', 'team': 'supercollider', 'set': (), 'delete': (), 'delete_all_job_secrets': False, 'overwrite_all_job_secrets': None, 'get': None, 'list': False, 'rest_api_url': 'https://dp.supercollider.vmware.com', 'output': 'TEXT'} secrets passed options: name: aivanov-xxx, team: supercollider, set: (), set_prompt: ('xxx_password',), get: None, list: False, delete: () rest_api_url: https://dp.supercollider.vmware.com, output: TEXT xxx_password: Rest API URL: https://dp.supercollider.vmware.com Reading vdk credential file: /Users/aivanov/.sc.vdk/.vdk.internal/vdk-cred.json ... Acquire access token (it's either expired or missing) ... Using auth type credentials to acquire access token Save vdk credential file: /Users/aivanov/.sc.vdk/.vdk.internal/vdk-cred.json Save vdk credential file: /Users/aivanov/.sc.vdk/.vdk.internal/vdk-cred.json Refresh API token against https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize Adding auto refresh key word arguments {}. Prepared refresh token request body grant_type=refresh_token&refresh_token=xxx-xxx Requesting url https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize using method POST. Supplying headers {'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'} and data {'grant_type': 'refresh_token', 'refresh_token': 'xxx-ddd'}

Version (please complete the following information):

dakodakov commented 7 months ago

Hey @antoniivanov , we tried reproducing this locally and the command fails as expected, e.g.:

`(sc-vdk) [ddakov@ddakovvm venvs]$ vdk -v debug secrets -n mzhivkov-job -t supercollider --set-prompt "key2" Passed parameters to function <function secrets_command at 0x79f0fb332160>: (), {'name': 'mzhivkov-job', 'team': 'supercollider', 'set_prompt': ('key2',), 'set': (), 'delete': (), 'delete_all_job_secrets': False, 'overwrite_all_job_secrets': None, 'get': None, 'list': False, 'rest_api_url': 'https://dp.supercollider.vmware.com', 'output': 'TEXT'} secrets passed options: name: mzhivkov-job, team: supercollider, set: (), set_prompt: ('key2',), get: None, list: False, delete: () rest_api_url: https://dp.supercollider.vmware.com, output: TEXT key2: Rest API URL: https://dp.supercollider.vmware.com Reading vdk credential file: /home/ddakov/.vdk.internal/vdk-cred.json ... Acquire access token (it's either expired or missing) ... Using auth type None to acquire access token No authentication mechanism found. Will not cache access token.If Control Service authentication is enabled, API calls will fail. Call function vdk.internal.control.command_groups.job.secrets.update_secrets --- Logging error --- Traceback (most recent call last): File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/vdk/internal/control/rest_lib/rest_client_errors.py", line 57, in decorated result = fn(*args, kwargs) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/vdk/internal/control/command_groups/job/secrets.py", line 129, in update_secrets remote_secrets = self.get_all_remote_secrets() File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/vdk/internal/control/command_groups/job/secrets.py", line 52, in get_all_remote_secrets return self.__secrets_api.data_job_secrets_read( File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call File "pydantic/decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/taurus_datajob_api/api/data_jobs_secrets_api.py", line 78, in data_job_secrets_read return self.data_job_secrets_read_with_http_info(team_name, job_name, deployment_id, kwargs) # noqa: E501 File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call File "pydantic/decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/taurus_datajob_api/api/data_jobs_secrets_api.py", line 185, in data_job_secrets_read_with_http_info return self.api_client.call_api( File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/taurus_datajob_api/api_client.py", line 406, in call_api return self.__call_api(resource_path, method, File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/taurus_datajob_api/api_client.py", line 221, in call_api raise e File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/taurus_datajob_api/api_client.py", line 211, in call_api response_data = self.request( File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/taurus_datajob_api/api_client.py", line 432, in request return self.rest_client.get_request(url, File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/taurus_datajob_api/rest.py", line 239, in get_request return self.request("GET", url, File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/taurus_datajob_api/rest.py", line 222, in request raise UnauthorizedException(http_resp=r) taurus_datajob_api.exceptions.UnauthorizedException: (401) Reason: HTTP response headers: HTTPHeaderDict({'Date': 'Wed, 21 Feb 2024 13:28:58 GMT', 'Content-Length': '0', 'Connection': 'keep-alive', 'WWW-Authenticate': 'Bearer', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains', 'X-Frame-Options': 'DENY'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/ddakov/.pyenv/versions/3.9.16/lib/python3.9/logging/init.py", line 1083, in emit msg = self.format(record) File "/home/ddakov/.pyenv/versions/3.9.16/lib/python3.9/logging/init.py", line 927, in format return fmt.format(record) File "/home/ddakov/.pyenv/versions/3.9.16/lib/python3.9/logging/init.py", line 663, in format record.message = record.getMessage() File "/home/ddakov/.pyenv/versions/3.9.16/lib/python3.9/logging/init.py", line 367, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting Call stack: File "/home/ddakov/dev/venvs/sc-vdk/bin/vdk", line 33, in sys.exit(load_entry_point('vdk-core==0.3.1184833162', 'console_scripts', 'vdk')()) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/vdk/internal/cli_entry.py", line 187, in main exit_code = cast(InternalHookSpecs, plugin_registry.hook()).vdk_main( File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/pluggy/_hooks.py", line 501, in call return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/pluggy/_manager.py", line 119, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/pluggy/_callers.py", line 102, in _multicall res = hook_impl.function(args) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/vdk/internal/cli_entry.py", line 137, in vdk_main exit_code = cast( File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/pluggy/_hooks.py", line 501, in call return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/pluggy/_manager.py", line 119, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/pluggy/_callers.py", line 102, in _multicall res = hook_impl.function(args) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/vdk/internal/cli_entry.py", line 98, in vdk_cli_execute exit_code = root_command( File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/click/core.py", line 783, in invoke return __callback(args, *kwargs) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/vdk/internal/control/utils/cli_utils.py", line 91, in check return f(args, **kwargs) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/vdk/internal/control/command_groups/job/secrets.py", line 305, in secrets_command cmd.update_secrets(key_value_pairs) File "/home/ddakov/dev/venvs/sc-vdk/lib/python3.9/site-packages/vdk/internal/control/rest_lib/rest_client_errors.py", line 60, in decorated log.debug( Message: 'An API Exception occurred in vdk.internal.control.command_groups.job.secrets.update_secrets' Arguments: ("The Exception class was: (401)\nReason: \nHTTP response headers: HTTPHeaderDict({'Date': 'Wed, 21 Feb 2024 13:28:58 GMT', 'Content-Length': '0', 'Connection': 'keep-alive', 'WWW-Authenticate': 'Bearer', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains', 'X-Frame-Options': 'DENY'})\n",) Usage: vdk secrets [OPTIONS] Try 'vdk secrets --help' for help.

Error: ¯_(ツ)_/¯

what: Control Service Error why: The request has not been applied because it lacks valid authentication credentials. Error returned by control service is b'' consequences: Operation cannot complete. countermeasures: Try to login again using VDK CLI login command.Or set correct api token configuration (see vdk config-help).Make sure you have permission to execute the given operation.Investigate (google) the error returned by control service.And if all fails try to contact the support team.

Check version for package supercollider-vdk from index https://build-artifactory.eng.vmware.com/api/pypi/supercollider-pypi-local/simple ... Current version of supercollider-vdk is (0, 0, 9070299) and highest is (0, 0, 9070299) `