Skip to content

Commit 0ea746f

Browse files
committed
refactor: Remove unnecessary pointer
1 parent 6bacf2d commit 0ea746f

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

pkg/deploy/automation.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ func (c *dummyAutomationClient) Upsert(_ context.Context, _ automation.ResourceT
3838
return &automation.Response{ID: id}, nil
3939
}
4040

41-
func deployAutomation(ctx context.Context, client automationClient, properties parameter.Properties, renderedConfig string, c *config.Config) (*parameter.ResolvedEntity, error) {
41+
func deployAutomation(ctx context.Context, client automationClient, properties parameter.Properties, renderedConfig string, c *config.Config) (parameter.ResolvedEntity, error) {
4242
t, ok := c.Type.(config.AutomationType)
4343
if !ok {
44-
return &parameter.ResolvedEntity{}, newConfigDeployErr(c, fmt.Sprintf("config was not of expected type %q, but %q", config.AutomationType{}.ID(), c.Type.ID()))
44+
return parameter.ResolvedEntity{}, newConfigDeployErr(c, fmt.Sprintf("config was not of expected type %q, but %q", config.AutomationType{}.ID(), c.Type.ID()))
4545
}
4646

4747
var id string
@@ -54,13 +54,13 @@ func deployAutomation(ctx context.Context, client automationClient, properties p
5454

5555
resourceType, err := automationutils.ClientResourceTypeFromConfigType(t.Resource)
5656
if err != nil {
57-
return nil, newConfigDeployErr(c, fmt.Sprintf("failed to upsert automation object of type %s with id %s", t.Resource, id)).withError(err)
57+
return parameter.ResolvedEntity{}, newConfigDeployErr(c, fmt.Sprintf("failed to upsert automation object of type %s with id %s", t.Resource, id)).withError(err)
5858
}
5959

6060
var resp *automation.Response
6161
resp, err = client.Upsert(ctx, resourceType, id, []byte(renderedConfig))
6262
if resp == nil || err != nil {
63-
return nil, newConfigDeployErr(c, fmt.Sprintf("failed to upsert automation object of type %s with id %s", t.Resource, id)).withError(err)
63+
return parameter.ResolvedEntity{}, newConfigDeployErr(c, fmt.Sprintf("failed to upsert automation object of type %s with id %s", t.Resource, id)).withError(err)
6464
}
6565

6666
name := fmt.Sprintf("[UNKNOWN NAME]%s", resp.ID)
@@ -77,6 +77,6 @@ func deployAutomation(ctx context.Context, client automationClient, properties p
7777
Properties: properties,
7878
Skip: false,
7979
}
80-
return &resolved, nil
80+
return resolved, nil
8181

8282
}

pkg/deploy/automation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestDeployAutomation_ClientUpsertFails(t *testing.T) {
6969
Parameters: toParameterMap([]parameter.NamedParameter{}),
7070
}
7171
res, err := deployAutomation(context.TODO(), client, nil, "", conf)
72-
assert.Nil(t, res)
72+
assert.Equal(t, parameter.ResolvedEntity{}, res)
7373
assert.Error(t, err)
7474
})
7575
t.Run("TestDeployAutomation - BusinessCalendar Upsert fails", func(t *testing.T) {
@@ -84,7 +84,7 @@ func TestDeployAutomation_ClientUpsertFails(t *testing.T) {
8484
Parameters: toParameterMap([]parameter.NamedParameter{}),
8585
}
8686
res, err := deployAutomation(context.TODO(), client, nil, "", conf)
87-
assert.Nil(t, res)
87+
assert.Equal(t, parameter.ResolvedEntity{}, res)
8888
assert.Error(t, err)
8989
})
9090
t.Run("TestDeployAutomation - Scheduling Rule Upsert fails", func(t *testing.T) {
@@ -99,7 +99,7 @@ func TestDeployAutomation_ClientUpsertFails(t *testing.T) {
9999
Parameters: toParameterMap([]parameter.NamedParameter{}),
100100
}
101101
res, err := deployAutomation(context.TODO(), client, nil, "", conf)
102-
assert.Nil(t, res)
102+
assert.Equal(t, parameter.ResolvedEntity{}, res)
103103
assert.Error(t, err)
104104
})
105105
}

pkg/deploy/bucket.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ type bucketClient interface {
3131

3232
var _ bucketClient = (*bucket.Client)(nil)
3333

34-
func deployBucket(ctx context.Context, client bucketClient, properties parameter.Properties, renderedConfig string, c *config.Config) (*parameter.ResolvedEntity, error) {
34+
func deployBucket(ctx context.Context, client bucketClient, properties parameter.Properties, renderedConfig string, c *config.Config) (parameter.ResolvedEntity, error) {
3535
bucketName := BucketId(c.Coordinate)
3636

3737
_, err := client.Upsert(ctx, bucketName, []byte(renderedConfig))
3838
if err != nil {
39-
return &parameter.ResolvedEntity{}, newConfigDeployErr(c, fmt.Sprintf("failed to upsert bucket with bucketName %q", bucketName)).withError(err)
39+
return parameter.ResolvedEntity{}, newConfigDeployErr(c, fmt.Sprintf("failed to upsert bucket with bucketName %q", bucketName)).withError(err)
4040
}
4141

4242
properties[config.IdParameter] = bucketName
4343

44-
return &parameter.ResolvedEntity{
44+
return parameter.ResolvedEntity{
4545
EntityName: bucketName,
4646
Coordinate: c.Coordinate,
4747
Properties: properties,

pkg/deploy/classic.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ import (
2727
"github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/config/parameter"
2828
)
2929

30-
func deployClassicConfig(ctx context.Context, configClient dtclient.ConfigClient, apis api.APIs, entityMap *entityMap, properties parameter.Properties, renderedConfig string, conf *config.Config) (*parameter.ResolvedEntity, error) {
30+
func deployClassicConfig(ctx context.Context, configClient dtclient.ConfigClient, apis api.APIs, entityMap *entityMap, properties parameter.Properties, renderedConfig string, conf *config.Config) (parameter.ResolvedEntity, error) {
3131
t, ok := conf.Type.(config.ClassicApiType)
3232
if !ok {
33-
return &parameter.ResolvedEntity{}, fmt.Errorf("config was not of expected type %q, but %q", config.ClassicApiTypeId, conf.Type.ID())
33+
return parameter.ResolvedEntity{}, fmt.Errorf("config was not of expected type %q, but %q", config.ClassicApiTypeId, conf.Type.ID())
3434
}
3535

3636
apiToDeploy, found := apis[t.Api]
3737
if !found {
38-
return &parameter.ResolvedEntity{}, fmt.Errorf("unknown api `%s`. this is most likely a bug", t.Api)
38+
return parameter.ResolvedEntity{}, fmt.Errorf("unknown api `%s`. this is most likely a bug", t.Api)
3939
}
4040

4141
configName, err := extractConfigName(conf, properties)
4242
if err != nil {
43-
return &parameter.ResolvedEntity{}, err
43+
return parameter.ResolvedEntity{}, err
4444
}
4545
if entityMap.contains(apiToDeploy.ID, configName) && !apiToDeploy.NonUniqueName {
46-
return &parameter.ResolvedEntity{}, newConfigDeployErr(conf, fmt.Sprintf("duplicated config name `%s`", configName))
46+
return parameter.ResolvedEntity{}, newConfigDeployErr(conf, fmt.Sprintf("duplicated config name `%s`", configName))
4747
}
4848

4949
if apiToDeploy.DeprecatedBy != "" {
@@ -58,13 +58,13 @@ func deployClassicConfig(ctx context.Context, configClient dtclient.ConfigClient
5858
}
5959

6060
if err != nil {
61-
return &parameter.ResolvedEntity{}, newConfigDeployErr(conf, err.Error()).withError(err)
61+
return parameter.ResolvedEntity{}, newConfigDeployErr(conf, err.Error()).withError(err)
6262
}
6363

6464
properties[config.IdParameter] = entity.Id
6565
properties[config.NameParameter] = entity.Name
6666

67-
return &parameter.ResolvedEntity{
67+
return parameter.ResolvedEntity{
6868
EntityName: entity.Name,
6969
Coordinate: conf.Coordinate,
7070
Properties: properties,

pkg/deploy/deploy.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func DeployConfigs(clientSet ClientSet, apis api.APIs, sortedConfigs []config.Co
8383
return errs
8484
}
8585
} else {
86-
entityMap.put(*entity)
86+
entityMap.put(entity)
8787
}
8888
}
8989

@@ -272,7 +272,7 @@ func (c *componentDeployer) deployNode(ctx context.Context, n graph.ConfigNode)
272272
return nil
273273
}
274274

275-
c.resolvedEntities.put(*entity)
275+
c.resolvedEntities.put(entity)
276276
log.WithCtxFields(ctx).Info("Deployment successful")
277277
return nil
278278
}
@@ -318,39 +318,39 @@ func deployComponent(ctx context.Context, component graph.SortedComponent, clien
318318
}
319319

320320
// deployFunc kinda just is a smarter deploy... TODO refactor!
321-
func deployFunc(ctx context.Context, c *config.Config, clientSet ClientSet, apis api.APIs, entityMap *entityMap) (*parameter.ResolvedEntity, error) {
321+
func deployFunc(ctx context.Context, c *config.Config, clientSet ClientSet, apis api.APIs, entityMap *entityMap) (parameter.ResolvedEntity, error) {
322322
if c.Skip {
323323
log.WithCtxFields(ctx).Info("Skipping deployment of config %s", c.Coordinate)
324-
return nil, skipError //fake resolved entity that "old" deploy creates is never needed, as we don't even try to deploy dependencies of skipped configs (so no reference will ever be attempted to resolve)
324+
return parameter.ResolvedEntity{}, skipError //fake resolved entity that "old" deploy creates is never needed, as we don't even try to deploy dependencies of skipped configs (so no reference will ever be attempted to resolve)
325325
}
326326

327327
entity, deploymentErrors := deploy(ctx, clientSet, apis, entityMap, c)
328328

329329
if len(deploymentErrors) > 0 {
330-
return nil, fmt.Errorf("failed to deploy config %s: %w", c.Coordinate, errors.Join(deploymentErrors...))
330+
return parameter.ResolvedEntity{}, fmt.Errorf("failed to deploy config %s: %w", c.Coordinate, errors.Join(deploymentErrors...))
331331
}
332332

333333
return entity, nil
334334
}
335335

336-
func deploy(ctx context.Context, clientSet ClientSet, apis api.APIs, em *entityMap, c *config.Config) (*parameter.ResolvedEntity, []error) {
336+
func deploy(ctx context.Context, clientSet ClientSet, apis api.APIs, em *entityMap, c *config.Config) (parameter.ResolvedEntity, []error) {
337337
if c.Skip {
338338
log.WithCtxFields(ctx).Info("Skipping deployment of config %s", c.Coordinate)
339-
return &parameter.ResolvedEntity{EntityName: c.Coordinate.ConfigId, Coordinate: c.Coordinate, Properties: parameter.Properties{}, Skip: true}, nil
339+
return parameter.ResolvedEntity{EntityName: c.Coordinate.ConfigId, Coordinate: c.Coordinate, Properties: parameter.Properties{}, Skip: true}, nil
340340
}
341341

342342
properties, errs := resolveProperties(c, em.get())
343343
if len(errs) > 0 {
344-
return &parameter.ResolvedEntity{}, errs
344+
return parameter.ResolvedEntity{}, errs
345345
}
346346

347347
renderedConfig, err := c.Render(properties)
348348
if err != nil {
349-
return &parameter.ResolvedEntity{}, []error{err}
349+
return parameter.ResolvedEntity{}, []error{err}
350350
}
351351

352352
log.WithCtxFields(ctx).Info("Deploying config")
353-
var res *parameter.ResolvedEntity
353+
var res parameter.ResolvedEntity
354354
var deployErr error
355355
switch c.Type.(type) {
356356
case config.SettingsType:
@@ -376,7 +376,7 @@ func deploy(ctx context.Context, clientSet ClientSet, apis api.APIs, em *entityM
376376
} else {
377377
log.WithCtxFields(ctx).WithFields(field.Error(deployErr)).Error("Failed to deploy config %s: %s", c.Coordinate, deployErr.Error())
378378
}
379-
return nil, []error{deployErr}
379+
return parameter.ResolvedEntity{}, []error{deployErr}
380380
}
381381
return res, nil
382382

pkg/deploy/deploy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func TestDeploySetting(t *testing.T) {
269269

270270
got, errors := deploy(context.TODO(), ClientSet{Settings: c}, nil, newEntityMap(testApiMap), &tt.given.config)
271271
if !tt.wantErr {
272-
assert.Equal(t, got, &tt.want)
272+
assert.Equal(t, got, tt.want)
273273
assert.Emptyf(t, errors, "errors: %v)", errors)
274274
} else {
275275
assert.NotEmptyf(t, errors, "errors: %v)", errors)

pkg/deploy/settings.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import (
2727
"github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/config/parameter"
2828
)
2929

30-
func deploySetting(ctx context.Context, settingsClient dtclient.SettingsClient, properties parameter.Properties, renderedConfig string, c *config.Config) (*parameter.ResolvedEntity, error) {
30+
func deploySetting(ctx context.Context, settingsClient dtclient.SettingsClient, properties parameter.Properties, renderedConfig string, c *config.Config) (parameter.ResolvedEntity, error) {
3131
t, ok := c.Type.(config.SettingsType)
3232
if !ok {
33-
return &parameter.ResolvedEntity{}, newConfigDeployErr(c, fmt.Sprintf("config was not of expected type %q, but %q", config.SettingsTypeId, c.Type.ID()))
33+
return parameter.ResolvedEntity{}, newConfigDeployErr(c, fmt.Sprintf("config was not of expected type %q, but %q", config.SettingsTypeId, c.Type.ID()))
3434
}
3535

3636
scope, err := extractScope(properties)
3737
if err != nil {
38-
return &parameter.ResolvedEntity{}, err
38+
return parameter.ResolvedEntity{}, err
3939
}
4040

4141
entity, err := settingsClient.UpsertSettings(ctx, dtclient.SettingsObject{
@@ -47,7 +47,7 @@ func deploySetting(ctx context.Context, settingsClient dtclient.SettingsClient,
4747
OriginObjectId: c.OriginObjectId,
4848
})
4949
if err != nil {
50-
return &parameter.ResolvedEntity{}, newConfigDeployErr(c, err.Error()).withError(err)
50+
return parameter.ResolvedEntity{}, newConfigDeployErr(c, err.Error()).withError(err)
5151
}
5252

5353
name := fmt.Sprintf("[UNKNOWN NAME]%s", entity.Id)
@@ -59,12 +59,12 @@ func deploySetting(ctx context.Context, settingsClient dtclient.SettingsClient,
5959

6060
properties[config.IdParameter], err = getEntityID(c, entity)
6161
if err != nil {
62-
return &parameter.ResolvedEntity{}, newConfigDeployErr(c, err.Error()).withError(err)
62+
return parameter.ResolvedEntity{}, newConfigDeployErr(c, err.Error()).withError(err)
6363
}
6464

6565
properties[config.NameParameter] = name
6666

67-
return &parameter.ResolvedEntity{
67+
return parameter.ResolvedEntity{
6868
EntityName: name,
6969
Coordinate: c.Coordinate,
7070
Properties: properties,

0 commit comments

Comments
 (0)