feat(cli): ✨ Implement Edge Connect CLI tool
Creates a new command-line interface for managing Edge Connect applications and instances with the following features: - Configuration management via YAML files and environment variables - Application lifecycle commands (create, show, list, delete) - Instance management with cloudlet support - Improved error handling and authentication flow - Comprehensive documentation with usage examples The CLI provides a user-friendly interface for managing Edge Connect resources while following best practices for command-line tool development using Cobra and Viper.
This commit is contained in:
parent
4429f3fa18
commit
a71f35163c
10 changed files with 589 additions and 4 deletions
|
|
@ -5,9 +5,10 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ErrResourceNotFound = fmt.Errorf("resource not found")
|
||||
|
|
@ -32,7 +33,8 @@ func (e *EdgeConnect) RetrieveToken(ctx context.Context) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
request, err := http.NewRequestWithContext(ctx, "POST", e.BaseURL+"/api/v1/login", bytes.NewBuffer(json_data))
|
||||
baseURL := strings.TrimRight(e.BaseURL, "/")
|
||||
request, err := http.NewRequestWithContext(ctx, "POST", baseURL+"/api/v1/login", bytes.NewBuffer(json_data))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -45,12 +47,22 @@ func (e *EdgeConnect) RetrieveToken(ctx context.Context) (string, error) {
|
|||
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Read the entire response body
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error reading response body: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("login failed with status %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
var respData struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
err = json.NewDecoder(resp.Body).Decode(&respData)
|
||||
err = json.Unmarshal(body, &respData)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", fmt.Errorf("error parsing JSON (status %d): %v", resp.StatusCode, err)
|
||||
}
|
||||
|
||||
return respData.Token, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue