Skip to content

Conversation

@akalipetis
Copy link
Member

This is only to be used as an example command for testing #260

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
Copy link

Copilot AI left a 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:curl command 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.

Comment on lines 211 to 223
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)
}

Copy link

Copilot AI Aug 26, 2025

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.

Suggested change
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 uses AI. Check for mistakes.
@akalipetis akalipetis force-pushed the feature/authentication-api-curl branch from 723d9bb to 8c0a197 Compare September 2, 2025 11:53
@akalipetis akalipetis force-pushed the feature/authentication-api-curl branch from 8c0a197 to 57149a8 Compare September 2, 2025 12:40
@akalipetis akalipetis force-pushed the feature/authentication-api-curl branch from 57149a8 to 5cf91e8 Compare September 2, 2025 13:42

cmd := &cobra.Command{
Use: "api:curl [flags] [path]",
Short: "Run an authenticated cURL request on the Upsun API",
Copy link
Contributor

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.

Copy link
Member Author

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.

Base automatically changed from feature/authentication to main September 4, 2025 16:57
@akalipetis
Copy link
Member Author

Closing this one, as #260 is now merged.

@akalipetis akalipetis closed this Sep 8, 2025
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.

3 participants