-
Notifications
You must be signed in to change notification settings - Fork 44
API endpoints mishandle trailing slash #496
Comments
I'll need more info:
And if nothing suspicious turns up, please create a variable via https://developer.hashicorp.com/terraform/cloud-docs/api-docs/variables#sample-request |
Hi @leg100
So why is the POST for that particular method turned into a 301? Maybe is the trailing "/" after the "vars"? Notice how the post command ends as "POST /api/v2/workspaces/ws-tXxC4AFtf5e3V9Ko/vars/" Many browsers are very special with extra forward slashes. |
I was looking at the Terrasnek code, yes it is sending a trailing slash in that endpoint. It is not ideal but the OTF API should be able to handle it. |
Yes I tested with curl, this is the result. I created a simple payload:
The I run a curl, note the endpoint without the trailing slash.
Notice it responds just fine. Now I the same experiment but I added a trailing slash (I deleted the variable created in the step before).
Notice in this case the 301 and the new location is without the forward slash. This code works fine in TFC so there should be a way to handle the ending slash without causing a 301. Or maybe return a 307 which allows for a POST follow? |
I changed my python code to use a custom function for that endpoint that does not include the trailing slash and it works fine. This sseems like a minor issue but makes OTF non-Terrasnek compatible. |
I'll make a change to all endpoints, to accept a trailing slash, and to disable redirects. I've renamed the issue accordingly. |
🤖 I have created a release *beep* *boop* --- ## [0.0.53](v0.0.52...v0.0.53) (2023-07-12) ### Bug Fixes * delete existing unreferenced webhooks too ([6b61b48](6b61b48)) * delete webhooks when org or vcs provider is deleted ([#518](#518)) ([0d36ea5](0d36ea5)) * **docs:** version using tag not branch name ([8613fe8](8613fe8)) * only set not null after populating column ([1da3936](1da3936)) * remove trailing slash from requests ([#516](#516)) ([c1ee39e](c1ee39e)), closes [#496](#496) * **ui:** add cache-control header to static files ([061261f](061261f)) ### Miscellaneous * add hashes to all static urls ([3650926](3650926)) * test create connected workspace via api ([9bf4bae](9bf4bae)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Hi,
I have been testing the new autorun function using Terrasnek and it is working, however there is a new bug I noticed during the variable registration.
My python program creates a Git-backed workspace, then registers four variables then starts a run. Note I know this code works because I have been using it in TFC for a while.
The output from the python program is as follows:
So you can see the variables are not created then the run fails.
Now, from the OTF logs, there is no mention about the variable creation. There is the workspace creation log and the run log, but there is no variable creation log.
Now I know the API is handling the endpoint at:
otf/internal/api/variable.go
Line 20 in 5cb3cb1
And the function is implemented a few lines below:
https://github.com/leg100/otf/blob/5cb3cb1e34f28a6b2ab5d7faa940e76656585831/internal/api/variable.go#L27C6-L27C7
I have followed the function down to:
otf/internal/variable/db.go
Line 33 in 5cb3cb1
otf/internal/sql/pggen/variable.sql.go
Line 46 in 5cb3cb1
All looks good, but the result is still empty and with no error message at all.
This is the python code and payloads I use to create two of the variables:
Again I know this code works fine in TFC.
The interface I use for in the "tfc" object above is a Terrasnek object. I can provide a more complete code if interested.
The text was updated successfully, but these errors were encountered: