Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 121df5d

Browse files
v1.0.6 Expose Clients as Interfaces + Add Mocks (#42)
* Expose clients as interfaces * Add client mocks that properly handle iterators and wrapped long-running operations. * Client initialization option is added to allow for insecure transport
1 parent 0160990 commit 121df5d

File tree

54 files changed

+4639
-278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4639
-278
lines changed

clients/options.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type WaaSClientConfig struct {
1717
APIKey *auth.APIKey
1818
HTTPClient *http.Client
1919
ClientOptions []option.ClientOption
20+
Insecure bool
2021
}
2122

2223
// WaaSClientOption is a function that applies changes to a clientConfig.
@@ -36,6 +37,14 @@ func WithAPIKey(apiKey *auth.APIKey) WaaSClientOption {
3637
}
3738
}
3839

40+
// WithInsecure returns an option to set the insecure flag.
41+
// If insecure is set to true, the client will not use transport authentication.
42+
func WithInsecure(insecure bool) WaaSClientOption {
43+
return func(c *WaaSClientConfig) {
44+
c.Insecure = insecure
45+
}
46+
}
47+
3948
// WithHTTPClient returns an option to set the HTTP Client.
4049
func WithHTTPClient(httpClient *http.Client) WaaSClientOption {
4150
return func(c *WaaSClientConfig) {
@@ -114,7 +123,7 @@ func GetHTTPClient(serviceName string, config *WaaSClientConfig) (*http.Client,
114123
httpClient = &http.Client{}
115124
}
116125

117-
if config.APIKey != nil {
126+
if config.Insecure == false {
118127
if httpClient.Transport == nil {
119128
httpClient.Transport = http.DefaultTransport
120129
}

clients/v1/blockchain.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ const (
1919
blockchainServiceEndpoint = "https://api.developer.coinbase.com/waas/blockchain"
2020
)
2121

22-
// BlockchainServiceClient is the client to use to access WaaS BlockchainService APIs.
23-
type BlockchainServiceClient struct {
22+
// blockchainServiceClient is the client to use to access WaaS BlockchainService APIs.
23+
type blockchainServiceClient struct {
2424
client *innerClient.BlockchainClient
2525
}
2626

2727
// NewBlockchainServiceClient returns a BlockchainServiceClient based on the given inputs.
2828
func NewBlockchainServiceClient(
2929
ctx context.Context,
3030
waasOpts ...clients.WaaSClientOption,
31-
) (*BlockchainServiceClient, error) {
31+
) (BlockchainServiceClient, error) {
3232
config, err := clients.GetConfig(blockchainServiceName, blockchainServiceEndpoint, waasOpts...)
3333
if err != nil {
3434
return nil, err
@@ -44,27 +44,27 @@ func NewBlockchainServiceClient(
4444
return nil, err
4545
}
4646

47-
return &BlockchainServiceClient{
47+
return &blockchainServiceClient{
4848
client: innerClient,
4949
}, nil
5050
}
5151

5252
// Close closes the connection to the API service. The user should invoke this when
5353
// the client is no longer required.
54-
func (p *BlockchainServiceClient) Close() error {
55-
return p.client.Close()
54+
func (b *blockchainServiceClient) Close() error {
55+
return b.client.Close()
5656
}
5757

5858
// Connection returns a connection to the API service.
5959
//
6060
// Deprecated: Connections are now pooled so this method does not always
6161
// return the same resource.
62-
func (p *BlockchainServiceClient) Connection() *grpc.ClientConn {
63-
return p.client.Connection()
62+
func (b *blockchainServiceClient) Connection() *grpc.ClientConn {
63+
return b.client.Connection()
6464
}
6565

6666
// GetNetwork gets a Network.
67-
func (b *BlockchainServiceClient) GetNetwork(
67+
func (b *blockchainServiceClient) GetNetwork(
6868
ctx context.Context,
6969
req *blockchainpb.GetNetworkRequest,
7070
opts ...gax.CallOption) (*blockchainpb.Network, error) {
@@ -118,15 +118,15 @@ func (n *networkIteratorImpl) Response() *blockchainpb.ListNetworksResponse {
118118
}
119119

120120
// ListNetworks lists the Networks supported by WaaS APIs.
121-
func (b *BlockchainServiceClient) ListNetworks(
121+
func (b *blockchainServiceClient) ListNetworks(
122122
ctx context.Context,
123123
req *blockchainpb.ListNetworksRequest,
124124
opts ...gax.CallOption) NetworkIterator {
125125
return &networkIteratorImpl{iter: b.client.ListNetworks(ctx, req, opts...)}
126126
}
127127

128128
// GetAsset retrieves an Asset by resource name.
129-
func (b *BlockchainServiceClient) GetAsset(
129+
func (b *blockchainServiceClient) GetAsset(
130130
ctx context.Context,
131131
req *blockchainpb.GetAssetRequest,
132132
opts ...gax.CallOption) (*blockchainpb.Asset, error) {
@@ -155,40 +155,40 @@ type assetIteratorImpl struct {
155155
}
156156

157157
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
158-
func (n *assetIteratorImpl) PageInfo() *iterator.PageInfo {
159-
return n.iter.PageInfo()
158+
func (a *assetIteratorImpl) PageInfo() *iterator.PageInfo {
159+
return a.iter.PageInfo()
160160
}
161161

162162
// Next returns the next result. Its second return value is iterator.Done if there are no more
163163
// results. Once Next returns Done, all subsequent calls will return Done.
164-
func (n *assetIteratorImpl) Next() (*blockchainpb.Asset, error) {
165-
asset, err := n.iter.Next()
164+
func (a *assetIteratorImpl) Next() (*blockchainpb.Asset, error) {
165+
asset, err := a.iter.Next()
166166

167167
return asset, clients.UnwrapError(err)
168168
}
169169

170170
// Response is the raw response for the current page.
171171
// Calling Next() or InternalFetch() updates this value.
172-
func (n *assetIteratorImpl) Response() *blockchainpb.ListAssetsResponse {
173-
if n.iter.Response == nil {
172+
func (a *assetIteratorImpl) Response() *blockchainpb.ListAssetsResponse {
173+
if a.iter.Response == nil {
174174
return nil
175175
}
176176

177-
response := n.iter.Response.(*blockchainpb.ListAssetsResponse)
177+
response := a.iter.Response.(*blockchainpb.ListAssetsResponse)
178178

179179
return response
180180
}
181181

182182
// ListAssets lists the Assets supported by WaaS APIs.
183-
func (b *BlockchainServiceClient) ListAssets(
183+
func (b *blockchainServiceClient) ListAssets(
184184
ctx context.Context,
185185
req *blockchainpb.ListAssetsRequest,
186186
opts ...gax.CallOption) AssetIterator {
187187
return &assetIteratorImpl{b.client.ListAssets(ctx, req, opts...)}
188188
}
189189

190190
// BatchGetAssets returns the list of Assets indicated by the given request.
191-
func (b *BlockchainServiceClient) BatchGetAssets(
191+
func (b *blockchainServiceClient) BatchGetAssets(
192192
ctx context.Context,
193193
req *blockchainpb.BatchGetAssetsRequest,
194194
opts ...gax.CallOption) (*blockchainpb.BatchGetAssetsResponse, error) {

clients/v1/gen_BlockchainServiceClient.go

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/v1/gen_MPCKeyServiceClient.go

+98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/v1/gen_MPCTransactionServiceClient.go

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)