-
-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathoci.go
51 lines (41 loc) · 1.18 KB
/
oci.go
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
40
41
42
43
44
45
46
47
48
49
50
51
package incus
import (
"fmt"
"net/http"
)
// ProtocolOCI implements an OCI registry API client.
type ProtocolOCI struct {
http *http.Client
httpHost string
httpUserAgent string
httpCertificate string
// Cache for images.
cache map[string]ociInfo
}
// Disconnect is a no-op for OCI.
func (r *ProtocolOCI) Disconnect() {
}
// GetConnectionInfo returns the basic connection information used to interact with the server.
func (r *ProtocolOCI) GetConnectionInfo() (*ConnectionInfo, error) {
info := ConnectionInfo{}
info.Addresses = []string{r.httpHost}
info.Certificate = r.httpCertificate
info.Protocol = "oci"
info.URL = r.httpHost
return &info, nil
}
// GetHTTPClient returns the http client used for the connection. This can be used to set custom http options.
func (r *ProtocolOCI) GetHTTPClient() (*http.Client, error) {
if r.http == nil {
return nil, fmt.Errorf("HTTP client isn't set, bad connection")
}
return r.http, nil
}
// DoHTTP performs a Request.
func (r *ProtocolOCI) DoHTTP(req *http.Request) (*http.Response, error) {
// Set the user agent.
if r.httpUserAgent != "" {
req.Header.Set("User-Agent", r.httpUserAgent)
}
return r.http.Do(req)
}