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

Authenticate when fetching monitors #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tony-pizza
Copy link

Adds authentication to the API request that fetches data for individual monitors (via Cronitor::Monitor#data). Currently no authentication is used and this method always returns an Unauthorized response. If an API key is set on the Cronitor::Monitor instance it will be used, otherwise Cronitor.api_key will be used.

Before:

Cronitor::Monitor.new("my-monitor").data
=> #<HTTParty::Response:0x28370 parsed_response={"detail"=>"Authentication credentials were not provided."}, @response=#<Net::HTTPUnauthorized 401 Unauthorized readbody=true>, @headers={"date"=>["Tue, 27 Aug 2024 20:12:07 GMT"], "content-type"=>["application/json"], "content-length"=>["58"], "connection"=>["close"], "server"=>["nginx/1.18.0 (Ubuntu)"], "www-authenticate"=>["bearer"], "vary"=>["Accept, Cookie"], "allow"=>["GET, PUT, DELETE, HEAD, OPTIONS"], "x-frame-options"=>["DENY"]}>

After:

Cronitor::Monitor.new("my-monitor").data
=> #<HTTParty::Response:0x28280 parsed_response={"attributes"=>{...}}, @response=#<Net::HTTPOK 200 OK readbody=true>, @headers={"date"=>["Tue, 27 Aug 2024 19:33:53 GMT"], "content-type"=>["application/json"], "content-length"=>["1159"], "connection"=>["close"], "server"=>["nginx/1.18.0 (Ubuntu)"], "vary"=>["Accept"], "allow"=>["GET, PUT, DELETE, HEAD, OPTIONS"], "x-frame-options"=>["DENY"]}>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant