-
Notifications
You must be signed in to change notification settings - Fork 13
Add an api:curl command as an authentication example usage
#261
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
Conversation
1. Use the Legacy CLI for getting a token 2. If the token is not valid (ie expired), force re-authentication 3. If the client receives a 401 response, force re-authentication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds an api:curl command to provide an example of authenticated API usage for testing purposes. The command mimics curl functionality with OAuth2 authentication and retry logic for 401 errors.
- Adds a new
api:curlcommand with comprehensive curl-like options including method, data, headers, and response formatting - Integrates with existing authentication system using OAuth2 tokens and automatic 401 retry mechanisms
- Registers the new command in the root command structure
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| commands/root.go | Registers the new api:curl command in the root command structure |
| commands/api_curl.go | Implements the complete api:curl command with authentication, HTTP client setup, and curl-like functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
commands/api_curl.go
Outdated
| func cloneHeader(h http.Header) http.Header { | ||
| out := make(http.Header, len(h)) | ||
| for k, v := range h { | ||
| out[k] = append([]string(nil), v...) | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| func readAllToString(r io.Reader) string { | ||
| b, _ := io.ReadAll(r) | ||
| return string(b) | ||
| } | ||
|
|
Copilot
AI
Aug 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper functions cloneHeader and readAllToString are defined but never used in this file. Consider removing them or documenting their intended purpose if they're meant for future use.
| func cloneHeader(h http.Header) http.Header { | |
| out := make(http.Header, len(h)) | |
| for k, v := range h { | |
| out[k] = append([]string(nil), v...) | |
| } | |
| return out | |
| } | |
| func readAllToString(r io.Reader) string { | |
| b, _ := io.ReadAll(r) | |
| return string(b) | |
| } |
723d9bb to
8c0a197
Compare
8c0a197 to
57149a8
Compare
57149a8 to
5cf91e8
Compare
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "api:curl [flags] [path]", | ||
| Short: "Run an authenticated cURL request on the Upsun API", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note - this is good for testing, but the old command actually invoked curl, whereas this is pure Go, so it may need a different name if it's ultimately wanted as a feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! This is only to be used as an example command to test the client created in #260 - I won't keep this afterwards.
|
Closing this one, as #260 is now merged. |
This is only to be used as an example command for testing #260