|
|
@ -25,6 +25,8 @@ type options struct { |
|
|
|
ctx context.Context |
|
|
|
ctx context.Context |
|
|
|
rootPath string |
|
|
|
rootPath string |
|
|
|
timeout time.Duration |
|
|
|
timeout time.Duration |
|
|
|
|
|
|
|
user string |
|
|
|
|
|
|
|
password string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WithContext with registry context.
|
|
|
|
// WithContext with registry context.
|
|
|
@ -42,6 +44,14 @@ func WithTimeout(timeout time.Duration) Option { |
|
|
|
return func(o *options) { o.timeout = timeout } |
|
|
|
return func(o *options) { o.timeout = timeout } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// WithDigestACL with registry password.
|
|
|
|
|
|
|
|
func WithDigestACL(user string, password string) Option { |
|
|
|
|
|
|
|
return func(o *options) { |
|
|
|
|
|
|
|
o.user = user |
|
|
|
|
|
|
|
o.password = password |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Registry is consul registry
|
|
|
|
// Registry is consul registry
|
|
|
|
type Registry struct { |
|
|
|
type Registry struct { |
|
|
|
opts *options |
|
|
|
opts *options |
|
|
@ -63,6 +73,12 @@ func New(zkServers []string, opts ...Option) (*Registry, error) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if len(options.user) > 0 && len(options.password) > 0 { |
|
|
|
|
|
|
|
err = conn.AddAuth("digest", []byte(options.user+":"+options.password)) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return &Registry{ |
|
|
|
return &Registry{ |
|
|
|
opts: options, |
|
|
|
opts: options, |
|
|
|
conn: conn, |
|
|
|
conn: conn, |
|
|
@ -182,7 +198,12 @@ func (r *Registry) ensureName(path string, data []byte, flags int32) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
if !exists { |
|
|
|
if !exists { |
|
|
|
_, err := r.conn.Create(path, data, flags, zk.WorldACL(zk.PermAll)) |
|
|
|
var err error |
|
|
|
|
|
|
|
if len(r.opts.user) > 0 && len(r.opts.password) > 0 { |
|
|
|
|
|
|
|
_, err = r.conn.Create(path, data, flags, zk.DigestACL(zk.PermAll, r.opts.user, r.opts.password)) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_, err = r.conn.Create(path, data, flags, zk.WorldACL(zk.PermAll)) |
|
|
|
|
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|