Skip to content

Commit 6f5e77e

Browse files
committed
Refactor client registration logic to avoid expanding client struct
1 parent 7a15061 commit 6f5e77e

File tree

708 files changed

+2740
-2039
lines changed

Some content is hidden

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

708 files changed

+2740
-2039
lines changed

oci/analytics_analytics_instance_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func AnalyticsAnalyticsInstanceDataSource() *schema.Resource {
2525
func readSingularAnalyticsAnalyticsInstance(d *schema.ResourceData, m interface{}) error {
2626
sync := &AnalyticsAnalyticsInstanceDataSourceCrud{}
2727
sync.D = d
28-
sync.Client = m.(*OracleClients).analyticsClient
28+
sync.Client = m.(*OracleClients).analyticsClient()
2929

3030
return ReadResource(sync)
3131
}

oci/analytics_analytics_instance_resource.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func AnalyticsAnalyticsInstanceResource() *schema.Resource {
141141
func createAnalyticsAnalyticsInstance(d *schema.ResourceData, m interface{}) error {
142142
sync := &AnalyticsAnalyticsInstanceResourceCrud{}
143143
sync.D = d
144-
sync.Client = m.(*OracleClients).analyticsClient
144+
sync.Client = m.(*OracleClients).analyticsClient()
145145

146146
var powerOff = false
147147
if powerState, ok := sync.D.GetOkExists("state"); ok {
@@ -201,15 +201,15 @@ func (s *AnalyticsAnalyticsInstanceResourceCrud) StopOacInstance() error {
201201
func readAnalyticsAnalyticsInstance(d *schema.ResourceData, m interface{}) error {
202202
sync := &AnalyticsAnalyticsInstanceResourceCrud{}
203203
sync.D = d
204-
sync.Client = m.(*OracleClients).analyticsClient
204+
sync.Client = m.(*OracleClients).analyticsClient()
205205

206206
return ReadResource(sync)
207207
}
208208

209209
func updateAnalyticsAnalyticsInstance(d *schema.ResourceData, m interface{}) error {
210210
sync := &AnalyticsAnalyticsInstanceResourceCrud{}
211211
sync.D = d
212-
sync.Client = m.(*OracleClients).analyticsClient
212+
sync.Client = m.(*OracleClients).analyticsClient()
213213

214214
// switch to power on
215215
powerOn, powerOff := false, false
@@ -247,7 +247,7 @@ func updateAnalyticsAnalyticsInstance(d *schema.ResourceData, m interface{}) err
247247
func deleteAnalyticsAnalyticsInstance(d *schema.ResourceData, m interface{}) error {
248248
sync := &AnalyticsAnalyticsInstanceResourceCrud{}
249249
sync.D = d
250-
sync.Client = m.(*OracleClients).analyticsClient
250+
sync.Client = m.(*OracleClients).analyticsClient()
251251
sync.DisableNotFoundRetries = true
252252

253253
return DeleteResource(d, sync)

oci/analytics_analytics_instance_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func TestAnalyticsAnalyticsInstanceResource_basic(t *testing.T) {
426426

427427
func testAccCheckAnalyticsAnalyticsInstanceDestroy(s *terraform.State) error {
428428
noResourceFound := true
429-
client := testAccProvider.Meta().(*OracleClients).analyticsClient
429+
client := testAccProvider.Meta().(*OracleClients).analyticsClient()
430430
for _, rs := range s.RootModule().Resources {
431431
if rs.Type == "oci_analytics_analytics_instance" {
432432
noResourceFound = false
@@ -478,7 +478,7 @@ func init() {
478478
}
479479

480480
func sweepAnalyticsAnalyticsInstanceResource(compartment string) error {
481-
analyticsClient := GetTestClients(&schema.ResourceData{}).analyticsClient
481+
analyticsClient := GetTestClients(&schema.ResourceData{}).analyticsClient()
482482
analyticsInstanceIds, err := getAnalyticsInstanceIds(compartment)
483483
if err != nil {
484484
return err
@@ -509,7 +509,7 @@ func getAnalyticsInstanceIds(compartment string) ([]string, error) {
509509
}
510510
var resourceIds []string
511511
compartmentId := compartment
512-
analyticsClient := GetTestClients(&schema.ResourceData{}).analyticsClient
512+
analyticsClient := GetTestClients(&schema.ResourceData{}).analyticsClient()
513513

514514
listAnalyticsInstancesRequest := oci_analytics.ListAnalyticsInstancesRequest{}
515515
listAnalyticsInstancesRequest.CompartmentId = &compartmentId
@@ -536,7 +536,7 @@ func analyticsInstanceSweepWaitCondition(response common.OCIOperationResponse) b
536536
}
537537

538538
func analyticsInstanceSweepResponseFetchOperation(client *OracleClients, resourceId *string, retryPolicy *common.RetryPolicy) error {
539-
_, err := client.analyticsClient.GetAnalyticsInstance(context.Background(), oci_analytics.GetAnalyticsInstanceRequest{
539+
_, err := client.analyticsClient().GetAnalyticsInstance(context.Background(), oci_analytics.GetAnalyticsInstanceRequest{
540540
AnalyticsInstanceId: resourceId,
541541
RequestMetadata: common.RequestMetadata{
542542
RetryPolicy: retryPolicy,

oci/analytics_analytics_instances_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func AnalyticsAnalyticsInstancesDataSource() *schema.Resource {
5050
func readAnalyticsAnalyticsInstances(d *schema.ResourceData, m interface{}) error {
5151
sync := &AnalyticsAnalyticsInstancesDataSourceCrud{}
5252
sync.D = d
53-
sync.Client = m.(*OracleClients).analyticsClient
53+
sync.Client = m.(*OracleClients).analyticsClient()
5454

5555
return ReadResource(sync)
5656
}

oci/analytics_clients.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
3+
package oci
4+
5+
import (
6+
oci_analytics "github.com/oracle/oci-go-sdk/analytics"
7+
8+
oci_common "github.com/oracle/oci-go-sdk/common"
9+
)
10+
11+
func init() {
12+
RegisterOracleClient("oci_analytics.AnalyticsClient", &OracleClient{initClientFn: initAnalyticsAnalyticsClient})
13+
}
14+
15+
func initAnalyticsAnalyticsClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient) (interface{}, error) {
16+
client, err := oci_analytics.NewAnalyticsClientWithConfigurationProvider(configProvider)
17+
if err != nil {
18+
return nil, err
19+
}
20+
err = configureClient(&client.BaseClient)
21+
if err != nil {
22+
return nil, err
23+
}
24+
return &client, nil
25+
}
26+
27+
func (m *OracleClients) analyticsClient() *oci_analytics.AnalyticsClient {
28+
return m.GetClient("oci_analytics.AnalyticsClient").(*oci_analytics.AnalyticsClient)
29+
}

oci/apigateway_clients.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
3+
package oci
4+
5+
import (
6+
oci_apigateway "github.com/oracle/oci-go-sdk/apigateway"
7+
8+
oci_common "github.com/oracle/oci-go-sdk/common"
9+
)
10+
11+
func init() {
12+
RegisterOracleClient("oci_apigateway.DeploymentClient", &OracleClient{initClientFn: initApigatewayDeploymentClient})
13+
RegisterOracleClient("oci_apigateway.GatewayClient", &OracleClient{initClientFn: initApigatewayGatewayClient})
14+
}
15+
16+
func initApigatewayDeploymentClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient) (interface{}, error) {
17+
client, err := oci_apigateway.NewDeploymentClientWithConfigurationProvider(configProvider)
18+
if err != nil {
19+
return nil, err
20+
}
21+
err = configureClient(&client.BaseClient)
22+
if err != nil {
23+
return nil, err
24+
}
25+
return &client, nil
26+
}
27+
28+
func (m *OracleClients) deploymentClient() *oci_apigateway.DeploymentClient {
29+
return m.GetClient("oci_apigateway.DeploymentClient").(*oci_apigateway.DeploymentClient)
30+
}
31+
32+
func initApigatewayGatewayClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient) (interface{}, error) {
33+
client, err := oci_apigateway.NewGatewayClientWithConfigurationProvider(configProvider)
34+
if err != nil {
35+
return nil, err
36+
}
37+
err = configureClient(&client.BaseClient)
38+
if err != nil {
39+
return nil, err
40+
}
41+
return &client, nil
42+
}
43+
44+
func (m *OracleClients) gatewayClient() *oci_apigateway.GatewayClient {
45+
return m.GetClient("oci_apigateway.GatewayClient").(*oci_apigateway.GatewayClient)
46+
}

oci/apigateway_deployment_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func ApigatewayDeploymentDataSource() *schema.Resource {
2525
func readSingularApigatewayDeployment(d *schema.ResourceData, m interface{}) error {
2626
sync := &ApigatewayDeploymentDataSourceCrud{}
2727
sync.D = d
28-
sync.Client = m.(*OracleClients).deploymentClient
28+
sync.Client = m.(*OracleClients).deploymentClient()
2929

3030
return ReadResource(sync)
3131
}

oci/apigateway_deployment_resource.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ func ApigatewayDeploymentResource() *schema.Resource {
599599
func createApigatewayDeployment(d *schema.ResourceData, m interface{}) error {
600600
sync := &ApigatewayDeploymentResourceCrud{}
601601
sync.D = d
602-
sync.Client = m.(*OracleClients).deploymentClient
602+
sync.Client = m.(*OracleClients).deploymentClient()
603603
sync.WorkRequestsClient = m.(*OracleClients).gatewayWorkRequestsClient
604604

605605
return CreateResource(d, sync)
@@ -608,7 +608,7 @@ func createApigatewayDeployment(d *schema.ResourceData, m interface{}) error {
608608
func readApigatewayDeployment(d *schema.ResourceData, m interface{}) error {
609609
sync := &ApigatewayDeploymentResourceCrud{}
610610
sync.D = d
611-
sync.Client = m.(*OracleClients).deploymentClient
611+
sync.Client = m.(*OracleClients).deploymentClient()
612612
sync.WorkRequestsClient = m.(*OracleClients).gatewayWorkRequestsClient
613613

614614
return ReadResource(sync)
@@ -617,7 +617,7 @@ func readApigatewayDeployment(d *schema.ResourceData, m interface{}) error {
617617
func updateApigatewayDeployment(d *schema.ResourceData, m interface{}) error {
618618
sync := &ApigatewayDeploymentResourceCrud{}
619619
sync.D = d
620-
sync.Client = m.(*OracleClients).deploymentClient
620+
sync.Client = m.(*OracleClients).deploymentClient()
621621
sync.WorkRequestsClient = m.(*OracleClients).gatewayWorkRequestsClient
622622

623623
return UpdateResource(d, sync)
@@ -626,7 +626,7 @@ func updateApigatewayDeployment(d *schema.ResourceData, m interface{}) error {
626626
func deleteApigatewayDeployment(d *schema.ResourceData, m interface{}) error {
627627
sync := &ApigatewayDeploymentResourceCrud{}
628628
sync.D = d
629-
sync.Client = m.(*OracleClients).deploymentClient
629+
sync.Client = m.(*OracleClients).deploymentClient()
630630
sync.WorkRequestsClient = m.(*OracleClients).gatewayWorkRequestsClient
631631
sync.DisableNotFoundRetries = true
632632

oci/apigateway_deployment_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func TestApigatewayDeploymentResource_basic(t *testing.T) {
526526

527527
func testAccCheckApigatewayDeploymentDestroy(s *terraform.State) error {
528528
noResourceFound := true
529-
client := testAccProvider.Meta().(*OracleClients).deploymentClient
529+
client := testAccProvider.Meta().(*OracleClients).deploymentClient()
530530
for _, rs := range s.RootModule().Resources {
531531
if rs.Type == "oci_apigateway_deployment" {
532532
noResourceFound = false
@@ -578,7 +578,7 @@ func init() {
578578
}
579579

580580
func sweepApigatewayDeploymentResource(compartment string) error {
581-
deploymentClient := GetTestClients(&schema.ResourceData{}).deploymentClient
581+
deploymentClient := GetTestClients(&schema.ResourceData{}).deploymentClient()
582582
deploymentIds, err := getDeploymentIds(compartment)
583583
if err != nil {
584584
return err
@@ -609,7 +609,7 @@ func getDeploymentIds(compartment string) ([]string, error) {
609609
}
610610
var resourceIds []string
611611
compartmentId := compartment
612-
deploymentClient := GetTestClients(&schema.ResourceData{}).deploymentClient
612+
deploymentClient := GetTestClients(&schema.ResourceData{}).deploymentClient()
613613

614614
listDeploymentsRequest := oci_apigateway.ListDeploymentsRequest{}
615615
listDeploymentsRequest.CompartmentId = &compartmentId
@@ -636,7 +636,7 @@ func deploymentSweepWaitCondition(response common.OCIOperationResponse) bool {
636636
}
637637

638638
func deploymentSweepResponseFetchOperation(client *OracleClients, resourceId *string, retryPolicy *common.RetryPolicy) error {
639-
_, err := client.deploymentClient.GetDeployment(context.Background(), oci_apigateway.GetDeploymentRequest{
639+
_, err := client.deploymentClient().GetDeployment(context.Background(), oci_apigateway.GetDeploymentRequest{
640640
DeploymentId: resourceId,
641641
RequestMetadata: common.RequestMetadata{
642642
RetryPolicy: retryPolicy,

oci/apigateway_deployments_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func ApigatewayDeploymentsDataSource() *schema.Resource {
4747
func readApigatewayDeployments(d *schema.ResourceData, m interface{}) error {
4848
sync := &ApigatewayDeploymentsDataSourceCrud{}
4949
sync.D = d
50-
sync.Client = m.(*OracleClients).deploymentClient
50+
sync.Client = m.(*OracleClients).deploymentClient()
5151

5252
return ReadResource(sync)
5353
}

0 commit comments

Comments
 (0)