diff --git a/cmd/credential-helper/main.go b/cmd/credential-helper/main.go index 15bf9f4..b2f140a 100644 --- a/cmd/credential-helper/main.go +++ b/cmd/credential-helper/main.go @@ -1,11 +1,8 @@ package main import ( - "bytes" "encoding/json" "fmt" - "io" - "net/http" "os" "path/filepath" @@ -231,52 +228,3 @@ func saveSession(path string, session *SessionStore) error { return nil } - -// exchangeSessionForRegistryToken exchanges the session token for a registry JWT -func exchangeSessionForRegistryToken(sessionToken, appViewURL string) (string, error) { - // Call the AppView's /auth/exchange endpoint - exchangeURL := fmt.Sprintf("%s/auth/exchange", appViewURL) - - reqBody := map[string]any{ - "scope": []string{"repository:*:pull,push"}, - } - - body, err := json.Marshal(reqBody) - if err != nil { - return "", fmt.Errorf("failed to marshal request: %w", err) - } - - req, err := http.NewRequest("POST", exchangeURL, bytes.NewReader(body)) - if err != nil { - return "", fmt.Errorf("failed to create request: %w", err) - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+sessionToken) - - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return "", fmt.Errorf("failed to call exchange endpoint: %w", err) - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - // Read response body for debugging - bodyBytes, _ := io.ReadAll(resp.Body) - return "", fmt.Errorf("exchange failed with status %d: %s", resp.StatusCode, string(bodyBytes)) - } - - var result struct { - Token string `json:"token"` - AccessToken string `json:"access_token"` - } - - if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { - return "", fmt.Errorf("failed to decode response: %w", err) - } - - if result.Token != "" { - return result.Token, nil - } - return result.AccessToken, nil -}