Skip to content
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

feat: allow additional methods in http datasource #13190

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

hegerdes
Copy link
Contributor

@hegerdes hegerdes commented Oct 19, 2024

What changed

This adds support for additional http methods for the http datasource.

I strongly orientated myself on the terrafrom http-datasource. With this PR the following methods are allowed:
HEAD, GET, POST, PUT, DELETE, OPTIONS, PATCH

If this list should be extended or reduced let me know.

Tests

I added one test to check for invalid methods, but there should probably be more. The problem is HTTP tests rely on the internet and it can be unstable. I was thinking of putting a POST test in for https://postman-echo.com/post but I don't know how hashicorp thinks about "dependencies" to external websites

Other

I am a total go nooby. I want to get more in to it and this seemed a good opportunity. I tried to follow existing style but I'm still lerning. If things should be done different, please tell me.

If your PR resolves any open issue(s), please indicate them like this so they will be closed when your PR is merged:

Closes #13169

EDIT1: Updated allowed HTTP methods

@hegerdes hegerdes requested a review from a team as a code owner October 19, 2024 19:09
Copy link

hashicorp-cla-app bot commented Oct 19, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hegerdes,

Thanks for the PR! I left a few comments, most are nits tbh, the code looks good to me overall.

The main thing I'd like to see addressed one way or another in this would be the methods supported, I believe I understand the rationale to limit it to a subset of what HTTP supports, that said I worry this might block some users unnecessarily, so I propose relaxing this check so all methods are accepted.
It's open for discussion of course, please feel free to push-back if you think I'm being too cautious here.

Thanks!


// Check if the input is in the list of allowed methods
validMethod := false
allowedMethods := []string{"HEAD", "GET", "POST", "PUT"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we support a subset of the methods allowed by HTTP? Notably PATCH is missing, and a bunch of others as well.

To be fair most of the methods won't be used with this datasource I'd think (typically HEAD or OPTIONS), but I wonder if we shouldn't relax this limitation so we don't hinder valid use-cases because of a misplaced assumption.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I limited it because it is limited in terraform (there even PUT is not allowed. I'm fully behind being more open, but there still should be some validation. Should we allow all HTTP methods, including CONNECT and TRACE from the standard? I don't know if these have to be handled diffferently.

datasource/http/data.go Outdated Show resolved Hide resolved
datasource/http/data.go Show resolved Hide resolved
datasource/http/test-fixtures/invalid_method.pkr.hcl Outdated Show resolved Hide resolved
This adds support for additional http methods for the http datasource.
Fixes hashicorp#13169

Signed-off-by: Henrik Gerdes <[email protected]>
@hegerdes hegerdes force-pushed the feat/extra-http-methods branch from c2a75ff to e858b68 Compare October 23, 2024 19:20
@hegerdes hegerdes changed the title [WIP] feat: allow additional methods in http datasource feat: allow additional methods in http datasource Oct 23, 2024
@hegerdes
Copy link
Contributor Author

Squashed the previous commits and fixed the expected text output. Also updated the generated docs, forgot this the last time.

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in the rerolled state, thanks for persevering with this change @hegerdes !

Merging now if tests are green

@lbajolet-hashicorp
Copy link
Contributor

Only Vercel's failing so merging since it's not relevant to the PR

@lbajolet-hashicorp lbajolet-hashicorp merged commit 6c40bfb into hashicorp:main Oct 29, 2024
10 of 11 checks passed
@hegerdes
Copy link
Contributor Author

Thanks for merging and taking a look at this at in such a quick time 😊 Awesome contributing experience!

I noted that the windows test in the main branch failed. Is this caused by my changes?

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add post to http data source
2 participants