mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-19 16:54:15 +00:00
remove unused code from credential-helper
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user