Open tkoller-averbis opened 2 years ago
ensure_available()
is used to wait for the server to respond at all - this happens even before obtaining an API token in some cases.
which imho does not ensure the availability of the client as suggest by the name.
The reason that I came across this is that I used the url http://localhost:8080/health-discovery/#/
(which is the url that is actually copied to the clipboard in the browser) instead of http://localhost:8080/health-discovery/
which lead to the semi-informative error
The server successfully returned a response, however, this response could not be converted to Json.: line 1 column 1 (char 0)
on the last line of
HD_URL = "https://health-discovery.averbis.com/health-discovery/#/"
API_TOKEN = "Definitely not a valid API Token"
client = Client(HD_URL, api_token=API_TOKEN)
client.ensure_available()
project = client.get_project("MY_PROJECT_NAME")
project.get_pipeline("MY Pipeline").ensure_started()
Judging from the documentation, the Client constructor expects authentication credentials and a Client object without proper authentication is imho worthless.
Actually, you can use the client with a username/password instead of an API token - and if you do that, it obtains an API token. So you don't need to have an API token.
Of course, it is not necessarily a good idea to use username/pw because it re-generates an API token every time you do it so if you have two clients connecting concurrently to the same instance, you'd get into trouble - but it is very useful during automatic testing.
Is your feature request related to a problem? Please describe.
As the first step of my client logic, I typically establish a client connection with the server, which I would like to verify immediately via client.ensure_available(). Unfortunately, ensure_available only sends a get request to the URL without checking
E.g.:
does not throw an error and hence does not really provide utility in verifying that the client is available.
Describe the solution you'd like
Client.ensure_available should send a get request to URL + "/rest/v1/buildInfo" and ideally throw an error when either
With a corresponding informative error message!