1
- // Copyright © 2018 Jasmin Gacic <[email protected] >
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in
11
- // all copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- // THE SOFTWARE.
20
-
21
1
package cli
22
2
23
3
import (
@@ -30,7 +10,6 @@ import (
30
10
"strings"
31
11
32
12
metal "github.com/equinix/equinix-sdk-go/services/metalv1"
33
- "github.com/packethost/packngo"
34
13
"github.com/spf13/cobra"
35
14
"github.com/spf13/pflag"
36
15
"github.com/spf13/viper"
@@ -45,8 +24,7 @@ const (
45
24
)
46
25
47
26
type Client struct {
48
- // apiClient client
49
- apiClient * packngo.Client
27
+ // metalApiClient client
50
28
metalApiClient * metal.APIClient
51
29
52
30
includes * []string // nolint:unused
@@ -86,23 +64,10 @@ func NewClient(consumerToken, apiURL, Version string) *Client {
86
64
}
87
65
}
88
66
89
- // This function provides backwards compatibility for the packngo
90
- // debug environment variable while allowing us to introduce a new
91
- // debug variable in the future that is not tied to packngo
92
67
func checkEnvForDebug () bool {
93
68
return os .Getenv (debugVar ) != ""
94
69
}
95
70
96
- func (c * Client ) apiConnect (httpClient * http.Client ) error {
97
- client , err := packngo .NewClientWithBaseURL (c .consumerToken , c .metalToken , httpClient , c .apiURL )
98
- if err != nil {
99
- return fmt .Errorf ("could not create client: %w" , err )
100
- }
101
- client .UserAgent = fmt .Sprintf ("metal-cli/%s %s" , c .Version , client .UserAgent )
102
- c .apiClient = client
103
- return nil
104
- }
105
-
106
71
func (c * Client ) metalApiConnect (httpClient * http.Client ) error {
107
72
configuration := metal .NewConfiguration ()
108
73
configuration .Debug = checkEnvForDebug ()
@@ -179,26 +144,6 @@ func bindFlags(cmd *cobra.Command, v *viper.Viper) {
179
144
})
180
145
}
181
146
182
- func (c * Client ) API (cmd * cobra.Command ) * packngo.Client {
183
- if c .metalToken == "" {
184
- log .Fatal ("Equinix Metal authentication token not provided. Please set the 'METAL_AUTH_TOKEN' environment variable or create a configuration file using 'metal init'." )
185
- }
186
-
187
- if c .apiClient == nil {
188
- httpClient := & http.Client {
189
- Transport : & headerTransport {
190
- header : getAdditionalHeaders (cmd ),
191
- },
192
- }
193
-
194
- err := c .apiConnect (httpClient )
195
- if err != nil {
196
- log .Fatal (err )
197
- }
198
- }
199
- return c .apiClient
200
- }
201
-
202
147
func (c * Client ) MetalAPI (cmd * cobra.Command ) * metal.APIClient {
203
148
if c .metalToken == "" {
204
149
log .Fatal ("Equinix Metal authentication token not provided. Please set the 'METAL_AUTH_TOKEN' environment variable or create a configuration file using 'metal init'." )
@@ -344,43 +289,6 @@ func (c *Client) Filters() map[string]string {
344
289
return mapFilt
345
290
}
346
291
347
- // ListOptions creates a packngo.ListOptions using the includes and excludes persistent
348
- // flags. When not defined, the defaults given will be supplied.
349
- func (c * Client ) ListOptions (defaultIncludes , defaultExcludes []string ) * packngo.ListOptions {
350
- listOptions := & packngo.ListOptions {
351
- Includes : defaultIncludes ,
352
- Excludes : defaultExcludes ,
353
- }
354
- if c .rootCmd .Flags ().Changed ("include" ) {
355
- listOptions .Includes = * c .includes
356
- }
357
- if c .rootCmd .Flags ().Changed ("exclude" ) {
358
- listOptions .Excludes = * c .excludes
359
- }
360
- if c .rootCmd .Flags ().Changed ("filter" ) {
361
- for _ , kv := range * c .filters {
362
- var k , v string
363
- tokens := strings .SplitN (kv , "=" , 2 )
364
- k = strings .TrimSpace (tokens [0 ])
365
- if len (tokens ) != 1 {
366
- v = strings .TrimSpace (tokens [1 ])
367
- }
368
- listOptions = listOptions .Filter (k , v )
369
- }
370
- }
371
- if c .rootCmd .Flags ().Changed ("search" ) {
372
- listOptions .Search = c .search
373
- }
374
- if c .rootCmd .Flags ().Changed ("sort-by" ) {
375
- listOptions .SortBy = c .sortBy
376
- }
377
- if c .rootCmd .Flags ().Changed ("sort-dir" ) {
378
- listOptions .SortDirection = packngo .ListSortDirection (c .sortDir )
379
- }
380
-
381
- return listOptions
382
- }
383
-
384
292
// initConfig reads in config file and ENV variables if set.
385
293
func (c * Client ) Init (cmd * cobra.Command ) {
386
294
// v := c.Config(cmd)
0 commit comments