Skip to content

Commit

Permalink
fix: remove check for available permission ids
Browse files Browse the repository at this point in the history
The openAPI spec has been changed and doesn't give us this information anymore.
Hence, this check, which gives the user a hint of what values are allowed is removed.
  • Loading branch information
warber committed Jul 1, 2024
1 parent f09ea99 commit fa985a8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 265 deletions.
9 changes: 1 addition & 8 deletions cmd/monaco/account/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package account

import (
"context"
"errors"
"fmt"
"github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/cmdutils"
Expand All @@ -33,7 +32,6 @@ import (
"github.com/spf13/afero"
"github.com/spf13/cobra"
"golang.org/x/exp/maps"
"net/http"
"path/filepath"
)

Expand Down Expand Up @@ -125,16 +123,11 @@ func deploy(fs afero.Fs, opts deployOpts) error {
return fmt.Errorf("failed to create account clients: %w", err)
}

supportedPermissions, err := deployer.FetchAvailablePermissionIDs(context.Background(), &http.Client{}, "https://api.dynatrace.com/spec-json")
if err != nil {
return fmt.Errorf("failed to fetch supportedPermissions: %w", err)
}

maxConcurrentDeploys := environment.GetEnvValueInt(environment.ConcurrentRequestsEnvKey)

for accInfo, accClient := range accountClients {
logger := log.WithFields(field.F("account", accInfo.Name))
accountDeployer := deployer.NewAccountDeployer(deployer.NewClient(accInfo, accClient, supportedPermissions), deployer.WithMaxConcurrentDeploys(maxConcurrentDeploys))
accountDeployer := deployer.NewAccountDeployer(deployer.NewClient(accInfo, accClient), deployer.WithMaxConcurrentDeploys(maxConcurrentDeploys))
logger.Info("Deploying configuration for account: %s", accInfo.Name)
logger.Info("Number of users to deploy: %d", len(resources.Users))
logger.Info("Number of groups to deploy: %d", len(resources.Groups))
Expand Down
18 changes: 5 additions & 13 deletions pkg/account/deployer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/go-logr/logr"
"io"
"net/http"
"slices"
)

type (
Expand All @@ -37,17 +36,15 @@ type (
ManagementZone = accountmanagement.ManagementZoneResourceDto

accountManagementClient struct {
accountInfo account.AccountInfo
supportedPermissions []remoteId
client *accounts.Client
accountInfo account.AccountInfo
client *accounts.Client
}
)

func NewClient(info account.AccountInfo, client *accounts.Client, supportedPermissions []remoteId) *accountManagementClient {
func NewClient(info account.AccountInfo, client *accounts.Client) *accountManagementClient {
return &accountManagementClient{
accountInfo: info,
client: client,
supportedPermissions: supportedPermissions,
accountInfo: info,
client: client,
}
}

Expand Down Expand Up @@ -260,11 +257,6 @@ func (d *accountManagementClient) updatePermissions(ctx context.Context, groupId
permissions = []accountmanagement.PermissionsDto{}
}

for _, p := range permissions {
if !slices.Contains(d.supportedPermissions, p.PermissionName) {
return fmt.Errorf("unsupported permission %s. Must be one of: %v", p.PermissionName, d.supportedPermissions)
}
}
resp, err := d.client.PermissionManagementAPI.OverwriteGroupPermissions(ctx, d.accountInfo.AccountUUID, groupId).PermissionsDto(permissions).Execute()
defer closeResponseBody(resp)
if err = d.handleClientResponseError(resp, err, "unable to update permissions of group with UUID "+groupId); err != nil {
Expand Down
Loading

0 comments on commit fa985a8

Please sign in to comment.