-
Notifications
You must be signed in to change notification settings - Fork 6
/
client.go
1027 lines (871 loc) · 36.1 KB
/
client.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package openstack
import (
"fmt"
"net/url"
"reflect"
"regexp"
"strings"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud/openstack/identity/v3/domains"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud/openstack/identity/v3/projects"
tokens3 "github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud/openstack/identity/v3/tokens"
)
const (
// v2 represents Keystone v2.
// It should never increase beyond 2.0.
v2 = "v2.0"
// v3 represents Keystone v3.
// The version can be anything from v3 to v3.x.
v3 = "v3"
// provider represents the suffix of endpoint url
provider = "myhuaweicloud.com"
)
/*
NewClient prepares an unauthenticated ProviderClient instance.
Most users will probably prefer using the AuthenticatedClient function
instead.
This is useful if you wish to explicitly control the version of the identity
service that's used for authentication explicitly, for example.
A basic example of using this would be:
ao, err := openstack.AuthOptionsFromEnv()
provider, err := openstack.NewClient(ao.IdentityEndpoint)
client, err := openstack.NewIdentityV3(provider, golangsdk.EndpointOpts{})
*/
func NewClient(endpoint string) (*golangsdk.ProviderClient, error) {
u, err := url.Parse(endpoint)
if err != nil {
return nil, err
}
u.RawQuery, u.Fragment = "", ""
var base string
versionRe := regexp.MustCompile("v[0-9.]+/?")
if version := versionRe.FindString(u.Path); version != "" {
base = strings.Replace(u.String(), version, "", -1)
} else {
base = u.String()
}
endpoint = golangsdk.NormalizeURL(endpoint)
base = golangsdk.NormalizeURL(base)
p := new(golangsdk.ProviderClient)
p.IdentityBase = base
p.IdentityEndpoint = endpoint
p.UseTokenLock()
return p, nil
}
/*
AuthenticatedClient logs in to an OpenStack cloud found at the identity endpoint
specified by the options, acquires a token, and returns a Provider Client
instance that's ready to operate.
If the full path to a versioned identity endpoint was specified (example:
http://example.com:5000/v3), that path will be used as the endpoint to query.
If a versionless endpoint was specified (example: http://example.com:5000/),
the endpoint will be queried to determine which versions of the identity service
are available, then chooses the most recent or most supported version.
Example:
ao, err := openstack.AuthOptionsFromEnv()
provider, err := openstack.AuthenticatedClient(ao)
client, err := openstack.NewNetworkV2(client, golangsdk.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
*/
func AuthenticatedClient(options golangsdk.AuthOptions) (*golangsdk.ProviderClient, error) {
client, err := NewClient(options.IdentityEndpoint)
if err != nil {
return nil, err
}
err = Authenticate(client, options)
if err != nil {
return nil, err
}
return client, nil
}
// Authenticate or re-authenticate against the most recent identity service
// supported at the provided endpoint.
func Authenticate(client *golangsdk.ProviderClient, options golangsdk.AuthOptionsProvider) error {
normalize := func(endpoint string) string {
if !strings.HasSuffix(endpoint, "/") {
return endpoint + "/"
}
return endpoint
}
endpoint := normalize(client.IdentityEndpoint)
authOptions, isTokenAuthOptions := options.(golangsdk.AuthOptions)
if isTokenAuthOptions {
//switch chosen.ID {
//case v2:
// return v2auth(client, endpoint, authOptions, golangsdk.EndpointOpts{})
//case v3:
if authOptions.AgencyDomainName != "" && authOptions.AgencyName != "" {
return v3authWithAgency(client, endpoint, &authOptions, golangsdk.EndpointOpts{})
}
return v3auth(client, endpoint, &authOptions, golangsdk.EndpointOpts{})
//default:
// // The switch statement must be out of date from the versions list.
// return fmt.Errorf("Unrecognized identity version: %s", chosen.ID)
//}
} else {
akskAuthOptions, isAkSkOptions := options.(golangsdk.AKSKAuthOptions)
if isAkSkOptions {
if akskAuthOptions.AgencyDomainName != "" && akskAuthOptions.AgencyName != "" {
return authWithAgencyByAKSK(client, endpoint, akskAuthOptions, golangsdk.EndpointOpts{})
}
return v3AKSKAuth(client, endpoint, akskAuthOptions, golangsdk.EndpointOpts{})
}
return fmt.Errorf("Unrecognized auth options provider: %s", reflect.TypeOf(options))
}
}
// AuthenticateV2 explicitly authenticates against the identity v2 endpoint.
func AuthenticateV2(client *golangsdk.ProviderClient, options golangsdk.AuthOptions, eo golangsdk.EndpointOpts) error {
return v2auth(client, "", options, eo)
}
func v2auth(client *golangsdk.ProviderClient, endpoint string, options golangsdk.AuthOptions, eo golangsdk.EndpointOpts) error {
v2Client, err := NewIdentityV2(client, eo)
if err != nil {
return err
}
if endpoint != "" {
v2Client.Endpoint = endpoint
}
return nil
}
// AuthenticateV3 explicitly authenticates against the identity v3 service.
func AuthenticateV3(client *golangsdk.ProviderClient, options tokens3.AuthOptionsBuilder, eo golangsdk.EndpointOpts) error {
return v3auth(client, "", options, eo)
}
func v3auth(client *golangsdk.ProviderClient, endpoint string, opts tokens3.AuthOptionsBuilder, eo golangsdk.EndpointOpts) error {
// Override the generated service endpoint with the one returned by the version endpoint.
v3Client, err := NewIdentityV3(client, eo)
if err != nil {
return err
}
if endpoint != "" {
v3Client.Endpoint = endpoint
}
result := tokens3.Create(v3Client, opts)
token, err := result.ExtractToken()
if err != nil {
return err
}
project, err := result.ExtractProject()
if err != nil {
return err
}
catalog, err := result.ExtractServiceCatalog()
if err != nil {
return err
}
client.TokenID = token.ID
if project != nil {
client.ProjectID = project.ID
client.DomainID = project.Domain.ID
}
if opts.CanReauth() {
client.ReauthFunc = func() error {
client.TokenID = ""
return v3auth(client, endpoint, opts, eo)
}
}
client.EndpointLocator = func(opts golangsdk.EndpointOpts) (string, error) {
return V3EndpointURL(catalog, opts)
}
return nil
}
func v3authWithAgency(client *golangsdk.ProviderClient, endpoint string, opts *golangsdk.AuthOptions, eo golangsdk.EndpointOpts) error {
if opts.TokenID == "" {
err := v3auth(client, endpoint, opts, eo)
if err != nil {
return err
}
} else {
client.TokenID = opts.TokenID
}
opts1 := golangsdk.AgencyAuthOptions{
AgencyName: opts.AgencyName,
AgencyDomainName: opts.AgencyDomainName,
DelegatedProject: opts.DelegatedProject,
}
return v3auth(client, endpoint, &opts1, eo)
}
func getEntryByServiceId(entries []tokens3.CatalogEntry, serviceId string) *tokens3.CatalogEntry {
if entries == nil {
return nil
}
for idx := range entries {
if entries[idx].ID == serviceId {
return &entries[idx]
}
}
return nil
}
func getProjectID(client *golangsdk.ServiceClient, name string) (string, error) {
opts := projects.ListOpts{
Name: name,
}
allPages, err := projects.List(client, opts).AllPages()
if err != nil {
return "", err
}
projects, err := projects.ExtractProjects(allPages)
if err != nil {
return "", err
}
if len(projects) < 1 {
err := &golangsdk.ErrResourceNotFound{}
err.ResourceType = "IAM project ID"
err.Name = name
return "", err
}
return projects[0].ID, nil
}
func v3AKSKAuth(client *golangsdk.ProviderClient, endpoint string, options golangsdk.AKSKAuthOptions, eo golangsdk.EndpointOpts) error {
v3Client, err := NewIdentityV3(client, eo)
if err != nil {
return err
}
// Override the generated service endpoint with the one returned by the version endpoint.
if endpoint != "" {
v3Client.Endpoint = endpoint
}
// update AKSKAuthOptions of ProviderClient
// ProviderClient(client) is a reference to the ServiceClient(v3Client)
defer func() {
client.AKSKAuthOptions.ProjectId = options.ProjectId
client.AKSKAuthOptions.DomainID = options.DomainID
}()
client.AKSKAuthOptions = options
client.AKSKAuthOptions.DomainID = ""
if options.ProjectId == "" && options.ProjectName != "" {
id, err := getProjectID(v3Client, options.ProjectName)
if err != nil {
return err
}
options.ProjectId = id
client.AKSKAuthOptions.ProjectId = options.ProjectId
}
if options.DomainID == "" && options.Domain != "" {
id, err := getDomainID(v3Client, options.Domain)
if err != nil {
return err
}
options.DomainID = id
}
if options.BssDomainID == "" && options.BssDomain != "" {
id, err := getDomainID(v3Client, options.BssDomain)
if err != nil {
return err
}
options.BssDomainID = id
}
client.ProjectID = options.ProjectId
client.DomainID = options.BssDomainID
if !options.WithUserCatalog {
var entries = make([]tokens3.CatalogEntry, 0, 1)
client.EndpointLocator = func(opts golangsdk.EndpointOpts) (string, error) {
return V3EndpointURL(&tokens3.ServiceCatalog{
Entries: entries,
}, opts)
}
}
return nil
}
func authWithAgencyByAKSK(client *golangsdk.ProviderClient, endpoint string, opts golangsdk.AKSKAuthOptions, eo golangsdk.EndpointOpts) error {
err := v3AKSKAuth(client, endpoint, opts, eo)
if err != nil {
return err
}
v3Client, err := NewIdentityV3(client, eo)
if err != nil {
return err
}
if v3Client.AKSKAuthOptions.DomainID == "" {
return fmt.Errorf("Must config domain name")
}
opts2 := golangsdk.AgencyAuthOptions{
AgencyName: opts.AgencyName,
AgencyDomainName: opts.AgencyDomainName,
DelegatedProject: opts.DelegatedProject,
}
result := tokens3.Create(v3Client, &opts2)
token, err := result.ExtractToken()
if err != nil {
return err
}
project, err := result.ExtractProject()
if err != nil {
return err
}
catalog, err := result.ExtractServiceCatalog()
if err != nil {
return err
}
client.TokenID = token.ID
if project != nil {
client.ProjectID = project.ID
}
client.ReauthFunc = func() error {
client.TokenID = ""
return authWithAgencyByAKSK(client, endpoint, opts, eo)
}
client.EndpointLocator = func(opts golangsdk.EndpointOpts) (string, error) {
return V3EndpointURL(catalog, opts)
}
client.AKSKAuthOptions.AccessKey = ""
return nil
}
func getDomainID(client *golangsdk.ServiceClient, name string) (string, error) {
old := client.Endpoint
defer func() { client.Endpoint = old }()
// the List request does not support query options
allPages, err := domains.List(client, nil).AllPages()
if err != nil {
return "", fmt.Errorf("List domains failed, err=%s", err)
}
all, err := domains.ExtractDomains(allPages)
if err != nil {
return "", fmt.Errorf("Extract domains failed, err=%s", err)
}
count := len(all)
switch count {
case 0:
err := &golangsdk.ErrResourceNotFound{}
err.ResourceType = "IAM domain ID"
err.Name = name
return "", err
case 1:
if name != "" && name != all[0].Name {
err := &golangsdk.ErrResourceNotFound{}
err.ResourceType = "IAM domain ID"
err.Name = name
return "", err
}
return all[0].ID, nil
default:
err := &golangsdk.ErrMultipleResourcesFound{}
err.ResourceType = "IAM domain ID"
err.Name = name
err.Count = count
return "", err
}
}
// NewIdentityV2 creates a ServiceClient that may be used to interact with the
// v2 identity service.
func NewIdentityV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
endpoint := client.IdentityBase + "v2.0/"
clientType := "identity"
var err error
if !reflect.DeepEqual(eo, golangsdk.EndpointOpts{}) {
eo.ApplyDefaults(clientType)
endpoint, err = client.EndpointLocator(eo)
if err != nil {
return nil, err
}
}
return &golangsdk.ServiceClient{
ProviderClient: client,
Endpoint: endpoint,
Type: clientType,
}, nil
}
// NewIdentityV3 creates a ServiceClient that may be used to access the v3
// identity service.
func NewIdentityV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
endpoint := client.IdentityBase + "v3/"
clientType := "identity"
var err error
if !reflect.DeepEqual(eo, golangsdk.EndpointOpts{}) {
eo.ApplyDefaults(clientType)
endpoint, err = client.EndpointLocator(eo)
if err != nil {
return nil, err
}
}
// Ensure endpoint still has a suffix of v3.
// This is because EndpointLocator might have found a versionless
// endpoint and requests will fail unless targeted at /v3.
if !strings.HasSuffix(endpoint, "v3/") {
endpoint = endpoint + "v3/"
}
return &golangsdk.ServiceClient{
ProviderClient: client,
Endpoint: endpoint,
Type: clientType,
}, nil
}
func initClientOpts(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts, clientType string) (*golangsdk.ServiceClient, error) {
sc := new(golangsdk.ServiceClient)
eo.ApplyDefaults(clientType)
url, err := client.EndpointLocator(eo)
if err != nil {
return sc, err
}
sc.ProviderClient = client
sc.Endpoint = url
sc.Type = clientType
return sc, nil
}
// initcommonServiceClient create a ServiceClient which can not get from clientType directly.
// firstly, we initialize a service client by "volumev2" type, the endpoint likes https://evs.{region}.{xxx.com}/v2/{project_id}
// then we replace the endpoint with the specified srv and version.
func initcommonServiceClient(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts, srv string, version string) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "volumev2")
if err != nil {
return nil, err
}
e := strings.Replace(sc.Endpoint, "v2", version, 1)
sc.Endpoint = strings.Replace(e, "evs", srv, 1)
sc.ResourceBase = sc.Endpoint
return sc, err
}
// InitServiceClientByName create a ServiceClient which was assembled by service and region name for huaweicloud.
// the endpoint likes https://{eo.Name}.{eo.Region}.myhuaweicloud.com/{apiVersion}/{project_id}
func InitServiceClientByName(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts, apiVersion string) (*golangsdk.ServiceClient, error) {
if eo.Name == "" || apiVersion == "" {
return nil, fmt.Errorf("must specify the service name and api version")
}
sc := new(golangsdk.ServiceClient)
sc.ProviderClient = client
sc.Endpoint = fmt.Sprintf("https://%s.%s.%s", eo.Name, eo.Region, provider)
sc.ResourceBase = fmt.Sprintf("%s/%s/%s/", sc.Endpoint, apiVersion, client.ProjectID)
return sc, nil
}
func NewSDKClient(c *golangsdk.ProviderClient, eo golangsdk.EndpointOpts, serviceType string) (*golangsdk.ServiceClient, error) {
switch serviceType {
case "mls":
return NewMLSV1(c, eo)
case "dws":
return NewDWSClient(c, eo)
case "nat":
return NewNatV2(c, eo)
}
return initClientOpts(c, eo, serviceType)
}
// ApiGateWayV1 creates a service client that is used for Huawei cloud for API gateway.
// TODO: Need to change to apig client type from apig once available
func ApiGateWayV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "apig", 1)
sc.ResourceBase = sc.Endpoint + "v1.0/apigw/"
return sc, err
}
// NewComputeV2 creates a ServiceClient that may be used with the openstack nova compute v2 package.
func NewComputeV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
return initClientOpts(client, eo, "compute")
}
// NewComputeV1 creates a ServiceClient that may be used with the ecs v1 package.
// Deprecated: use NewEcsV1 instead
func NewComputeV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "ecs", 1)
sc.Endpoint = sc.Endpoint + "v1/"
sc.ResourceBase = sc.Endpoint + client.ProjectID + "/"
return sc, err
}
// NewEcsV1 creates a ServiceClient that may be used with the ecs v1 package.
func NewEcsV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "ecs")
return sc, err
}
// NewComputeV11 creates a ServiceClient that may be used with the ecs v1.1 package.
func NewComputeV11(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "ecsv1.1")
return sc, err
}
// NewNetworkV2 creates a ServiceClient that may be used with the openstack neutron v2.0 package.
func NewNetworkV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.ResourceBase = sc.Endpoint + "v2.0/"
return sc, err
}
// NewNetworkV1 creates a ServiceClient that may be used with the vpc v1 package.
func NewNetworkV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.ResourceBase = sc.Endpoint + "v1/"
return sc, err
}
// NewVPCV1 creates a ServiceClient that may be used with the vpc v1 package.
func NewVPCV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "vpc")
return sc, err
}
// NewBlockStorageV1 creates a ServiceClient that may be used to access the v1
// block storage service.
func NewBlockStorageV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
return initClientOpts(client, eo, "volume")
}
// NewBlockStorageV2 creates a ServiceClient that may be used to access the v2
// block storage service.
func NewBlockStorageV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
return initClientOpts(client, eo, "volumev2")
}
// NewBlockStorageV3 creates a ServiceClient that may be used to access the v3 block storage service.
func NewBlockStorageV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
return initClientOpts(client, eo, "volumev3")
}
// NewSharedFileSystemV2 creates a ServiceClient that may be used to access the v2 shared file system service.
func NewSharedFileSystemV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
return initClientOpts(client, eo, "sharev2")
}
// NewHwSFSV2 creates a service client that is used for Huawei cloud for SFS, it replaces the EVS type.
// TODO: Need to change to sfs client type from evs once available
func NewHwSFSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "sfs", 1)
sc.ResourceBase = sc.Endpoint + "v2/" + client.ProjectID + "/"
return sc, err
}
// NewHwSFSTurboV1 creates a service client that is used for Huawei cloud for SFS Turbo.
func NewHwSFSTurboV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "sfs-turbo", 1)
sc.ResourceBase = sc.Endpoint + "v1/" + client.ProjectID + "/"
return sc, err
}
// NewObjectStorageV1 creates a ServiceClient that may be used with the v1
// object storage package.
func NewObjectStorageV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
return initClientOpts(client, eo, "object-store")
}
// NewOBSService creates a ServiceClient that may be used to access the Object Storage Service.
func NewOBSService(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "object")
return sc, err
}
// NewImageServiceV1 creates a ServiceClient that may be used to access the v1
// image service.
func NewImageServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "image")
sc.ResourceBase = sc.Endpoint + "v1/"
return sc, err
}
// NewImageServiceV2 creates a ServiceClient that may be used to access the v2
// image service.
func NewImageServiceV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "image")
sc.ResourceBase = sc.Endpoint + "v2/"
return sc, err
}
// NewLoadBalancerV2 creates a ServiceClient that may be used to access the v2
// load balancer service.
func NewLoadBalancerV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "load-balancer")
sc.ResourceBase = sc.Endpoint + "v2.0/"
return sc, err
}
// NewElbV1 creates a ServiceClient that may be used with the v1 network package.
func NewElbV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts, otctype string) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "compute")
sc.Endpoint = strings.Replace(strings.Replace(sc.Endpoint, "ecs", otctype, 1), "/v2/", "/v1.0/", 1)
sc.ResourceBase = sc.Endpoint
sc.Type = otctype
return sc, err
}
// NewELBV1 creates a ServiceClient that may be used to access the ELB service.
func NewELBV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "elbv1")
return sc, err
}
func NewElasticLoadBalancer(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
if err != nil {
return sc, err
}
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "elb", 1)
sc.Endpoint = strings.Replace(sc.Endpoint, "myhwclouds", "myhuaweicloud", 1)
sc.ResourceBase = sc.Endpoint + "v1.0/"
return sc, err
}
// NewDBV1 creates a ServiceClient that may be used to access the v1 DB service.
func NewDBV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
return initClientOpts(client, eo, "database")
}
// NewRDSV1 creates a ServiceClient that may be used to access the RDS service.
func NewRDSV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "rdsv1")
if err != nil {
return initcommonServiceClient(client, eo, "rds", "rds/v1")
}
return sc, nil
}
// NewRDSV3 creates a ServiceClient that may be used to access the RDS service.
func NewRDSV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "rdsv3")
return sc, err
}
// NewRdsServiceV1 creates the a ServiceClient that may be used to access the v1
// rds service which is a service of db instances management.
func NewRdsServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
newsc, err := initClientOpts(client, eo, "compute")
rdsendpoint := strings.Replace(strings.Replace(newsc.Endpoint, "ecs", "rds", 1), "/v2/", "/rds/v1/", 1)
newsc.Endpoint = rdsendpoint
newsc.ResourceBase = rdsendpoint
newsc.Type = "rds"
return newsc, err
}
func NewRdsTagV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "rds", 1)
sc.Endpoint = sc.Endpoint + "v1/"
sc.ResourceBase = sc.Endpoint + client.ProjectID + "/rds/"
return sc, err
}
// NewCESClient creates a ServiceClient that may be used with the v1 CES service.
func NewCESClient(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "cesv1")
if err != nil {
return initcommonServiceClient(client, eo, "ces", "V1.0")
}
return sc, nil
}
// NewDRSServiceV2 creates a ServiceClient that may be used to access the v2 Data Replication Service.
func NewDRSServiceV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "volumev2")
return sc, err
}
// NewAutoScalingService creates a ServiceClient that may be used to access the
// auto-scaling service of huawei public cloud
func NewAutoScalingService(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "asv1")
if err != nil {
return initcommonServiceClient(client, eo, "as", "autoscaling-api/v1")
}
return sc, nil
}
// NewKMSV1 creates a ServiceClient that may be used to access the KMS service.
func NewKMSV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "kms")
return sc, err
}
// NewKmsKeyV1 creates a ServiceClient that may be used to access the kms key service.
// **only used for HCS**
func NewKmsKeyV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "compute")
sc.Endpoint = strings.Replace(sc.Endpoint, "ecs", "kms", 1)
sc.Endpoint = sc.Endpoint[:strings.LastIndex(sc.Endpoint, "v2")+3]
sc.Endpoint = strings.Replace(sc.Endpoint, "v2", "v1.0", 1)
sc.ResourceBase = sc.Endpoint
sc.Type = "kms"
return sc, err
}
// NewOrchestrationV1 creates a ServiceClient that may be used to access the v1
// orchestration service.
func NewOrchestrationV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
return initClientOpts(client, eo, "orchestration")
}
// NewDNSV2 creates a ServiceClient that may be used to access the v2 DNS
// service.
func NewDNSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "dns")
sc.ResourceBase = sc.Endpoint + "v2/"
return sc, err
}
// NewNatV2 creates a ServiceClient that may be used with the v2 nat package.
func NewNatV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "nat", 1)
sc.Endpoint = strings.Replace(sc.Endpoint, "myhwclouds", "myhuaweicloud", 1)
sc.ResourceBase = sc.Endpoint + "v2.0/"
return sc, err
}
// MapReduceV1 creates a ServiceClient that may be used with the v1 MapReduce service.
func MapReduceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "mrs", 1)
sc.Endpoint = sc.Endpoint + "v1.1/"
sc.ResourceBase = sc.Endpoint + client.ProjectID + "/"
return sc, err
}
// NewMapReduceV1 creates a ServiceClient that may be used with the v1 MapReduce service.
func NewMapReduceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "mrs")
sc.ResourceBase = sc.Endpoint + client.ProjectID + "/"
return sc, err
}
// NewAntiDDoSV1 creates a ServiceClient that may be used with the v1 Anti DDoS Service package.
func NewAntiDDoSV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "antiddos")
if err != nil {
return initcommonServiceClient(client, eo, "antiddos", "v1")
}
return sc, nil
}
// NewAntiDDoSV2 creates a ServiceClient that may be used with the v2 Anti DDoS Service package.
func NewAntiDDoSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "antiddos")
sc.ResourceBase = sc.Endpoint + "v2/" + client.ProjectID + "/"
return sc, err
}
// NewCCE creates a ServiceClient that may be used to access the CCE service.
func NewCCE(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "ccev2.0")
sc.ResourceBase = sc.Endpoint + "api/v3/projects/" + client.ProjectID + "/"
return sc, err
}
func NewCCEV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "cce", 1)
sc.Endpoint = strings.Replace(sc.Endpoint, "myhwclouds", "myhuaweicloud", 1)
sc.ResourceBase = sc.Endpoint + "api/v3/projects/" + client.ProjectID + "/"
return sc, err
}
func NewCCEAddonV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "cce", 1)
sc.Endpoint = strings.Replace(sc.Endpoint, "myhwclouds", "myhuaweicloud", 1)
sc.ResourceBase = sc.Endpoint + "api/v3/"
return sc, err
}
// NewDMSServiceV1 creates a ServiceClient that may be used to access the v1 Distributed Message Service.
func NewDMSServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "dms", 1)
sc.ResourceBase = sc.Endpoint + "v1.0/" + client.ProjectID + "/"
return sc, err
}
// NewDCSServiceV1 creates a ServiceClient that may be used to access the v1 Distributed Cache Service.
func NewDCSServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "dcs", 1)
sc.ResourceBase = sc.Endpoint + "v1.0/" + client.ProjectID + "/"
return sc, err
}
func NewBMSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "compute")
e := strings.Replace(sc.Endpoint, "v2", "v2.1", 1)
sc.Endpoint = e
sc.ResourceBase = e
return sc, err
}
// NewDeHServiceV1 creates a ServiceClient that may be used to access the v1 Dedicated Hosts service.
func NewDeHServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "deh")
return sc, err
}
// NewCSBSService creates a ServiceClient that can be used to access the Cloud Server Backup service.
func NewCSBSService(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "data-protect")
return sc, err
}
// NewHwCSBSServiceV1 creates a ServiceClient that may be used to access the Huawei Cloud Server Backup service.
func NewHwCSBSServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "compute")
sc.Endpoint = strings.Replace(sc.Endpoint, "ecs", "csbs", 1)
e := strings.Replace(sc.Endpoint, "v2", "v1", 1)
sc.Endpoint = e
sc.ResourceBase = e
return sc, err
}
func NewMLSV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "mls", 1)
sc.ResourceBase = sc.Endpoint + "v1.0/" + client.ProjectID + "/"
return sc, err
}
func NewDWSClient(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initcommonServiceClient(client, eo, "dws", "v1.0")
return sc, err
}
// NewVBSV2 creates a ServiceClient that may be used to access the VBS service
func NewVBSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "vbsv2")
if err != nil {
return initcommonServiceClient(client, eo, "vbs", "v2")
}
return sc, nil
}
// NewCTSService creates a ServiceClient that can be used to access the Cloud Trace service.
func NewCTSService(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "cts")
return sc, err
}
// NewSMNV2 creates a ServiceClient that may be used to access the SMN service.
func NewSMNV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "smnv2")
if err != nil {
sc, err = initcommonServiceClient(client, eo, "smn", "v2")
}
sc.ResourceBase = sc.Endpoint + "notifications/"
return sc, err
}
// NewWAFV1 creates a ServiceClient that may be used to access the WAF service.
func NewWAFV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "waf")
sc.ResourceBase = sc.Endpoint + "v1/" + client.ProjectID + "/waf/"
return sc, err
}
// NewSDRSV1 creates a ServiceClient that may be used to access the SDRS service.
func NewSDRSV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "sdrs")
if err != nil {
return initcommonServiceClient(client, eo, "sdrs", "v1")
}
return sc, nil
}
// CCIV1 creates a ServiceClient that may be used with the v1 CCI service.
func CCIV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "cci", 1)
sc.Endpoint = sc.Endpoint + "apis/networking.cci.io/v1beta1/"
sc.ResourceBase = sc.Endpoint
return sc, err
}
// NewBSSV1 creates a ServiceClient that may be used to access the BSS service.
func NewBSSV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "bssv1")
return sc, err
}
// NewDDSV3 creates a ServiceClient that may be used to access the DDS service.
func NewDDSV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "ddsv3")
return sc, err
}
// NewLTSV2 creates a ServiceClient that may be used to access the LTS service.
func NewLTSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initcommonServiceClient(client, eo, "lts", "v2.0")
return sc, err
}
// NewHuaweiLTSV2 creates a ServiceClient that may be used to access the Huawei Cloud LTS service.
func NewHuaweiLTSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initcommonServiceClient(client, eo, "lts", "v2")
return sc, err
}
// NewFGSV2 creates a ServiceClient that may be used with the v2 as
// package.
func NewFGSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "fgsv2")
return sc, err
}
// NewMAASV1 creates a ServiceClient that may be used to access the MAAS service.
func NewMAASV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "maasv1")
return sc, err
}
// MAASV1 creates a ServiceClient that may be used with the v1 MAAS service.
func MAASV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = "https://oms.myhuaweicloud.com/v1/"
sc.ResourceBase = sc.Endpoint + client.ProjectID + "/"
return sc, err
}