Browse code

golint: trust

contributes to #14756

Signed-off-by: Sevki Hasirci <s@sevki.org>

Sevki Hasirci authored on 2015/07/29 03:18:04
Showing 5 changed files
... ...
@@ -70,10 +70,10 @@ func (config *Config) InstallFlags(cmd *flag.FlagSet, usageFn func(string) strin
70 70
 	cmd.StringVar(&config.Bridge.Iface, []string{"b", "-bridge"}, "", usageFn("Attach containers to a network bridge"))
71 71
 	cmd.StringVar(&config.Bridge.FixedCIDR, []string{"-fixed-cidr"}, "", usageFn("IPv4 subnet for fixed IPs"))
72 72
 	cmd.StringVar(&config.Bridge.FixedCIDRv6, []string{"-fixed-cidr-v6"}, "", usageFn("IPv6 subnet for fixed IPs"))
73
-	cmd.Var(opts.NewIpOpt(&config.Bridge.DefaultGatewayIPv4, ""), []string{"-default-gateway"}, usageFn("Container default gateway IPv4 address"))
74
-	cmd.Var(opts.NewIpOpt(&config.Bridge.DefaultGatewayIPv6, ""), []string{"-default-gateway-v6"}, usageFn("Container default gateway IPv6 address"))
73
+	cmd.Var(opts.NewIPOpt(&config.Bridge.DefaultGatewayIPv4, ""), []string{"-default-gateway"}, usageFn("Container default gateway IPv4 address"))
74
+	cmd.Var(opts.NewIPOpt(&config.Bridge.DefaultGatewayIPv6, ""), []string{"-default-gateway-v6"}, usageFn("Container default gateway IPv6 address"))
75 75
 	cmd.BoolVar(&config.Bridge.InterContainerCommunication, []string{"#icc", "-icc"}, true, usageFn("Enable inter-container communication"))
76
-	cmd.Var(opts.NewIpOpt(&config.Bridge.DefaultIP, "0.0.0.0"), []string{"#ip", "-ip"}, usageFn("Default IP when binding container ports"))
76
+	cmd.Var(opts.NewIPOpt(&config.Bridge.DefaultIP, "0.0.0.0"), []string{"#ip", "-ip"}, usageFn("Default IP when binding container ports"))
77 77
 	cmd.BoolVar(&config.Bridge.EnableUserlandProxy, []string{"-userland-proxy"}, true, usageFn("Use userland proxy for loopback traffic"))
78 78
 	cmd.BoolVar(&config.EnableCors, []string{"#api-enable-cors", "#-api-enable-cors"}, false, usageFn("Enable CORS headers in the remote API, this is deprecated by --api-cors-header"))
79 79
 	cmd.StringVar(&config.CorsHeaders, []string{"-api-cors-header"}, "", usageFn("Set CORS headers in the remote API"))
... ...
@@ -40,7 +40,7 @@ type TagStore struct {
40 40
 	pushingPool     map[string]chan struct{}
41 41
 	registryService *registry.Service
42 42
 	eventsService   *events.Events
43
-	trustService    *trust.TrustStore
43
+	trustService    *trust.Store
44 44
 }
45 45
 
46 46
 // Repository maps tags to image IDs.
... ...
@@ -77,7 +77,7 @@ type TagStoreConfig struct {
77 77
 	// Events is the events service to use for logging.
78 78
 	Events *events.Events
79 79
 	// Trust is the trust service to use for push and pull operations.
80
-	Trust *trust.TrustStore
80
+	Trust *trust.Store
81 81
 }
82 82
 
83 83
 // NewTagStore creates a new TagStore at specified path, using the parameters
... ...
@@ -10,7 +10,7 @@ func TestIpOptString(t *testing.T) {
10 10
 	var ip net.IP
11 11
 
12 12
 	for _, address := range addresses {
13
-		stringAddress := NewIpOpt(&ip, address).String()
13
+		stringAddress := NewIPOpt(&ip, address).String()
14 14
 		if stringAddress != address {
15 15
 			t.Fatalf("IpOpt string should be `%s`, not `%s`", address, stringAddress)
16 16
 		}
... ...
@@ -21,7 +21,7 @@ func TestNewIpOptInvalidDefaultVal(t *testing.T) {
21 21
 	ip := net.IPv4(127, 0, 0, 1)
22 22
 	defaultVal := "Not an ip"
23 23
 
24
-	ipOpt := NewIpOpt(&ip, defaultVal)
24
+	ipOpt := NewIPOpt(&ip, defaultVal)
25 25
 
26 26
 	expected := "127.0.0.1"
27 27
 	if ipOpt.String() != expected {
... ...
@@ -33,7 +33,7 @@ func TestNewIpOptValidDefaultVal(t *testing.T) {
33 33
 	ip := net.IPv4(127, 0, 0, 1)
34 34
 	defaultVal := "192.168.1.1"
35 35
 
36
-	ipOpt := NewIpOpt(&ip, defaultVal)
36
+	ipOpt := NewIPOpt(&ip, defaultVal)
37 37
 
38 38
 	expected := "192.168.1.1"
39 39
 	if ipOpt.String() != expected {
... ...
@@ -43,7 +43,7 @@ func TestNewIpOptValidDefaultVal(t *testing.T) {
43 43
 
44 44
 func TestIpOptSetInvalidVal(t *testing.T) {
45 45
 	ip := net.IPv4(127, 0, 0, 1)
46
-	ipOpt := &IpOpt{IP: &ip}
46
+	ipOpt := &IPOpt{IP: &ip}
47 47
 
48 48
 	invalidIP := "invalid ip"
49 49
 	expectedError := "invalid ip is not an ip address"
... ...
@@ -8,13 +8,16 @@ import (
8 8
 	"github.com/docker/libtrust"
9 9
 )
10 10
 
11
+// NotVerifiedError implements the error interface
11 12
 type NotVerifiedError string
12 13
 
13 14
 func (e NotVerifiedError) Error() string {
14 15
 	return string(e)
15 16
 }
16 17
 
17
-func (t *TrustStore) CheckKey(ns string, key []byte, perm uint16) (bool, error) {
18
+// CheckKey verifies that the given public key is allowed to perform
19
+// the given action on the given node according to the trust graph.
20
+func (t *Store) CheckKey(ns string, key []byte, perm uint16) (bool, error) {
18 21
 	if len(key) == 0 {
19 22
 		return false, fmt.Errorf("Missing PublicKey")
20 23
 	}
... ...
@@ -48,6 +51,8 @@ func (t *TrustStore) CheckKey(ns string, key []byte, perm uint16) (bool, error)
48 48
 	return true, nil
49 49
 }
50 50
 
51
-func (t *TrustStore) UpdateBase() {
51
+// UpdateBase retrieves updated base graphs.  This function cannot error, it
52
+// should only log errors
53
+func (t *Store) UpdateBase() {
52 54
 	t.fetch()
53 55
 }
... ...
@@ -17,7 +17,8 @@ import (
17 17
 	"github.com/docker/libtrust/trustgraph"
18 18
 )
19 19
 
20
-type TrustStore struct {
20
+// Store defines a TrustStore
21
+type Store struct {
21 22
 	path          string
22 23
 	caPool        *x509.CertPool
23 24
 	graph         trustgraph.TrustGraph
... ...
@@ -38,7 +39,9 @@ const defaultFetchtime = 45 * time.Second
38 38
 
39 39
 var baseEndpoints = map[string]string{"official": "https://dvjy3tqbc323p.cloudfront.net/trust/official.json"}
40 40
 
41
-func NewTrustStore(path string) (*TrustStore, error) {
41
+// NewTrustStore creates from a given path, if the path is not
42
+// relative, it will be joined with the working directory.
43
+func NewTrustStore(path string) (*Store, error) {
42 44
 	abspath, err := filepath.Abs(path)
43 45
 	if err != nil {
44 46
 		return nil, err
... ...
@@ -55,7 +58,7 @@ func NewTrustStore(path string) (*TrustStore, error) {
55 55
 	}
56 56
 
57 57
 	// Load grant files
58
-	t := &TrustStore{
58
+	t := &Store{
59 59
 		path:          abspath,
60 60
 		caPool:        nil,
61 61
 		httpClient:    &http.Client{},
... ...
@@ -70,7 +73,7 @@ func NewTrustStore(path string) (*TrustStore, error) {
70 70
 	return t, nil
71 71
 }
72 72
 
73
-func (t *TrustStore) reload() error {
73
+func (t *Store) reload() error {
74 74
 	t.Lock()
75 75
 	defer t.Unlock()
76 76
 
... ...
@@ -121,7 +124,7 @@ func (t *TrustStore) reload() error {
121 121
 	return nil
122 122
 }
123 123
 
124
-func (t *TrustStore) fetchBaseGraph(u *url.URL) (*trustgraph.Statement, error) {
124
+func (t *Store) fetchBaseGraph(u *url.URL) (*trustgraph.Statement, error) {
125 125
 	req := &http.Request{
126 126
 		Method:     "GET",
127 127
 		URL:        u,
... ...
@@ -148,7 +151,7 @@ func (t *TrustStore) fetchBaseGraph(u *url.URL) (*trustgraph.Statement, error) {
148 148
 
149 149
 // fetch retrieves updated base graphs.  This function cannot error, it
150 150
 // should only log errors
151
-func (t *TrustStore) fetch() {
151
+func (t *Store) fetch() {
152 152
 	t.Lock()
153 153
 	defer t.Unlock()
154 154