File: auth.go

package info (click to toggle)
golang-github-samalba-dockerclient 0.0~git20160531.0.a303626-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 204 kB
  • sloc: makefile: 5
file content (39 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package dockerclient

import (
	"bytes"
	"encoding/base64"
	"encoding/json"
)

// AuthConfig hold parameters for authenticating with the docker registry
type AuthConfig struct {
	Username      string `json:"username,omitempty"`
	Password      string `json:"password,omitempty"`
	Email         string `json:"email,omitempty"`
	RegistryToken string `json:"registrytoken,omitempty"`
}

// encode the auth configuration struct into base64 for the X-Registry-Auth header
func (c *AuthConfig) encode() (string, error) {
	var buf bytes.Buffer
	if err := json.NewEncoder(&buf).Encode(c); err != nil {
		return "", err
	}
	return base64.URLEncoding.EncodeToString(buf.Bytes()), nil
}

// ConfigFile holds parameters for authenticating during a BuildImage request
type ConfigFile struct {
	Configs  map[string]AuthConfig `json:"configs,omitempty"`
	rootPath string
}

// encode the configuration struct into base64 for the X-Registry-Config header
func (c *ConfigFile) encode() (string, error) {
	var buf bytes.Buffer
	if err := json.NewEncoder(&buf).Encode(c); err != nil {
		return "", err
	}
	return base64.URLEncoding.EncodeToString(buf.Bytes()), nil
}