...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package client
19
20
21
22
23 import (
24 "github.com/go-openapi/runtime"
25 httptransport "github.com/go-openapi/runtime/client"
26 "github.com/go-openapi/strfmt"
27
28 "github.com/sigstore/timestamp-authority/pkg/generated/client/timestamp"
29 )
30
31
32 var Default = NewHTTPClient(nil)
33
34 const (
35
36
37 DefaultHost string = "timestamp.sigstore.dev"
38
39
40 DefaultBasePath string = "/"
41 )
42
43
44 var DefaultSchemes = []string{"http"}
45
46
47 func NewHTTPClient(formats strfmt.Registry) *TimestampAuthority {
48 return NewHTTPClientWithConfig(formats, nil)
49 }
50
51
52
53 func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *TimestampAuthority {
54
55 if cfg == nil {
56 cfg = DefaultTransportConfig()
57 }
58
59
60 transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
61 return New(transport, formats)
62 }
63
64
65 func New(transport runtime.ClientTransport, formats strfmt.Registry) *TimestampAuthority {
66
67 if formats == nil {
68 formats = strfmt.Default
69 }
70
71 cli := new(TimestampAuthority)
72 cli.Transport = transport
73 cli.Timestamp = timestamp.New(transport, formats)
74 return cli
75 }
76
77
78
79 func DefaultTransportConfig() *TransportConfig {
80 return &TransportConfig{
81 Host: DefaultHost,
82 BasePath: DefaultBasePath,
83 Schemes: DefaultSchemes,
84 }
85 }
86
87
88
89 type TransportConfig struct {
90 Host string
91 BasePath string
92 Schemes []string
93 }
94
95
96
97 func (cfg *TransportConfig) WithHost(host string) *TransportConfig {
98 cfg.Host = host
99 return cfg
100 }
101
102
103
104 func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig {
105 cfg.BasePath = basePath
106 return cfg
107 }
108
109
110
111 func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
112 cfg.Schemes = schemes
113 return cfg
114 }
115
116
117 type TimestampAuthority struct {
118 Timestamp timestamp.ClientService
119
120 Transport runtime.ClientTransport
121 }
122
123
124 func (c *TimestampAuthority) SetTransport(transport runtime.ClientTransport) {
125 c.Transport = transport
126 c.Timestamp.SetTransport(transport)
127 }
128
View as plain text