Skip to content

Commit

Permalink
Merge pull request #313 from hmlanigan/juju-4344
Browse files Browse the repository at this point in the history
fix leak of concerns from one package to another
  • Loading branch information
hmlanigan authored Sep 20, 2023
2 parents d14194e + 479d6cb commit 7c1971d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
26 changes: 11 additions & 15 deletions internal/juju/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package juju

import (
"fmt"
"strings"
"time"

"github.com/juju/errors"
Expand Down Expand Up @@ -86,9 +85,9 @@ type DestroyModelInput struct {
}

type DestroyAccessModelInput struct {
Model string
Revoke []string
Access string
ModelName string
Revoke []string
Access string
}

func newModelsClient(sc SharedClient) *modelsClient {
Expand Down Expand Up @@ -176,6 +175,9 @@ func (c *modelsClient) CreateModel(input CreateModelInput) (CreateModelResponse,
resp.Type = modelInfo.Type.String()
resp.UUID = modelInfo.UUID

// Add the model to the client cache of jujuModel
c.AddModel(modelInfo.Name, modelInfo.UUID, modelInfo.Type)

// set constraints when required
if input.Constraints.String() == "" {
return resp, nil
Expand All @@ -195,9 +197,6 @@ func (c *modelsClient) CreateModel(input CreateModelInput) (CreateModelResponse,
return resp, err
}

// Add the model to the client cache of jujuModel
c.AddModel(modelInfo.Name, modelInfo.UUID, modelInfo.Type)

return resp, nil
}

Expand Down Expand Up @@ -402,22 +401,19 @@ func (c *modelsClient) UpdateAccessModel(input UpdateAccessModelInput) error {
// If a user has had `write`, then removing that access would decrease their
// access to `read` and the user will remain part of the model access.
func (c *modelsClient) DestroyAccessModel(input DestroyAccessModelInput) error {
id := strings.Split(input.Model, ":")
model := id[0]

uuid, err := c.ModelUUID(model)
conn, err := c.GetConnection(nil)
if err != nil {
return err
}

conn, err := c.GetConnection(nil)
client := modelmanager.NewClient(conn)
defer func() { _ = client.Close() }()

uuid, err := c.ModelUUID(input.ModelName)
if err != nil {
return err
}

client := modelmanager.NewClient(conn)
defer client.Close()

for _, user := range input.Revoke {
err := client.RevokeModel(user, "read", uuid)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/resource_access_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ func (a *accessModelResource) Delete(ctx context.Context, req resource.DeleteReq
}

err := a.client.Models.DestroyAccessModel(juju.DestroyAccessModelInput{
Model: plan.ID.ValueString(),
Revoke: stateUsers,
Access: plan.Access.ValueString(),
ModelName: plan.Model.ValueString(),
Revoke: stateUsers,
Access: plan.Access.ValueString(),
})
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete access model resource, got error: %s", err))
Expand Down

0 comments on commit 7c1971d

Please sign in to comment.