|
17 | 17 | package api
|
18 | 18 |
|
19 | 19 | import (
|
20 |
| - "errors" |
21 | 20 | "fmt"
|
22 | 21 | "io"
|
23 | 22 | "net/http"
|
@@ -84,25 +83,28 @@ type ErrResolve error
|
84 | 83 | // DNS Resolver
|
85 | 84 | func (self *Api) Resolve(uri *URI) (storage.Key, error) {
|
86 | 85 | log.Trace(fmt.Sprintf("Resolving : %v", uri.Addr))
|
| 86 | + |
| 87 | + var err error |
| 88 | + if !uri.Immutable() { |
| 89 | + if self.dns != nil { |
| 90 | + resolved, err := self.dns.Resolve(uri.Addr) |
| 91 | + if err == nil { |
| 92 | + return resolved[:], nil |
| 93 | + } |
| 94 | + } else { |
| 95 | + err = fmt.Errorf("no DNS to resolve name") |
| 96 | + } |
| 97 | + } |
87 | 98 | if hashMatcher.MatchString(uri.Addr) {
|
88 |
| - log.Trace(fmt.Sprintf("addr is a hash: %q", uri.Addr)) |
89 | 99 | return storage.Key(common.Hex2Bytes(uri.Addr)), nil
|
90 | 100 | }
|
91 |
| - if uri.Immutable() { |
92 |
| - return nil, errors.New("refusing to resolve immutable address") |
93 |
| - } |
94 |
| - if self.dns == nil { |
95 |
| - return nil, fmt.Errorf("unable to resolve addr %q, resolver not configured", uri.Addr) |
96 |
| - } |
97 |
| - hash, err := self.dns.Resolve(uri.Addr) |
98 | 101 | if err != nil {
|
99 |
| - log.Warn(fmt.Sprintf("DNS error resolving addr %q: %s", uri.Addr, err)) |
100 |
| - return nil, ErrResolve(err) |
| 102 | + return nil, fmt.Errorf("'%s' does not resolve: %v but is not a content hash", uri.Addr, err) |
101 | 103 | }
|
102 |
| - log.Trace(fmt.Sprintf("addr lookup: %v -> %v", uri.Addr, hash)) |
103 |
| - return hash[:], nil |
| 104 | + return nil, fmt.Errorf("'%s' is not a content hash", uri.Addr) |
104 | 105 | }
|
105 | 106 |
|
| 107 | + |
106 | 108 | // Put provides singleton manifest creation on top of dpa store
|
107 | 109 | func (self *Api) Put(content, contentType string) (storage.Key, error) {
|
108 | 110 | r := strings.NewReader(content)
|
|
0 commit comments