Skip to content

Commit 8b48ade

Browse files
committed
feat: add low-level request auth
1 parent 2fe67a8 commit 8b48ade

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pkg/client/request.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package client
2+
3+
import (
4+
"encoding/base64"
5+
"encoding/json"
6+
"fmt"
7+
"github.com/distribution/reference"
8+
"net/http"
9+
)
10+
11+
func (c *Client) RequestAuthenticate(req *http.Request, ref reference.Named) error {
12+
authConfig := c.authProvider.AuthConfig(ref)
13+
confBytes, err := json.Marshal(authConfig)
14+
if err != nil {
15+
return fmt.Errorf("failed to marshal auth config: %w", err)
16+
}
17+
encoded := base64.URLEncoding.EncodeToString(confBytes)
18+
req.Header.Set("X-Registry-Auth", encoded)
19+
return nil
20+
}

0 commit comments

Comments
 (0)