Skip to content

Commit

Permalink
Merge pull request #3 from raito-io/RAITO-1572-use-simpler-export-fie…
Browse files Browse the repository at this point in the history
…lds-in-cli-and-plugins

Replace deprecated fields to new CLI version
  • Loading branch information
rmennes authored Sep 15, 2023
2 parents 5061ef2 + 603859a commit b3aabfc
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 191 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: '1.18'
go-version: '1.21'
cache: true

- name: Configure git for private modules
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.48.0
version: v1.54.2

#- name: Test
# run: make test
Expand Down
18 changes: 13 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ linters-settings:
gosec:
excludes:
- G404 # To be checked: Insecure random number source (rand)
- G602

stylecheck:
checks: [ "all", "-ST1003"] # ST1003: No underscores in package names should be fixed and removed?
Expand All @@ -54,14 +55,22 @@ linters-settings:
ignored-functions:
- 'math.*' # Magic number generation, should be fixed and removed?

cyclop:
max-complexity: 20
skip-tests: true
package-average: 0.0

linters:
disable-all: true
enable:
- asasalint
- bodyclose
- deadcode
- depguard
# - cyclop #To be enabled in the future
#- depguard #We should create a correct config to enabe depguard
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- exportloopref
- exhaustive
Expand All @@ -71,7 +80,7 @@ linters:
- gofmt
- goimports
#- gomnd # Magic numbers should be fixed and enable gomnd,
#- gocyclo
- gocyclo
- gosec
- gosimple
- govet
Expand All @@ -83,14 +92,13 @@ linters:
- predeclared
- revive
- staticcheck
- structcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- varcheck
- unused
- whitespace
# - wrapcheck # 3th party errors should be wrapped to not lose context
- wsl
Expand Down
17 changes: 14 additions & 3 deletions azure/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package azure
import (
"context"

"github.com/raito-io/cli-plugin-azure/azure/storage"
ds "github.com/raito-io/cli/base/data_source"

"github.com/raito-io/cli-plugin-azure/azure/storage"

"github.com/raito-io/cli/base/util/config"
"github.com/raito-io/cli/base/wrappers"
)
Expand Down Expand Up @@ -42,8 +43,9 @@ func (s *DataSourceSyncer) GetDataSourceMetaData(ctx context.Context) (*ds.MetaD
logger.Debug("Returning meta data for Azure data source")

meta := &ds.MetaData{
Type: "azure",
SupportedFeatures: []string{},
Type: "azure",
SupportedFeatures: []string{},
SupportsApInheritance: false,
DataObjectTypes: []*ds.DataObjectType{
{
Name: ds.Datasource,
Expand All @@ -61,6 +63,15 @@ func (s *DataSourceSyncer) GetDataSourceMetaData(ctx context.Context) (*ds.MetaD
},
},
},
AccessProviderTypes: []*ds.AccessProviderType{
{
Type: storage.RoleAssignments,
Label: "Role Assignment",
IsNamedEntity: false,
CanBeCreated: true,
CanBeAssumed: false,
},
},
}

for _, syncer := range s.serviceSyncers {
Expand Down
5 changes: 4 additions & 1 deletion azure/storage/constants.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package storage

const AzApiNamespace = "Microsoft.Storage"
const (
AzApiNamespace = "Microsoft.Storage"
RoleAssignments = "roleAssignments"
)
14 changes: 11 additions & 3 deletions azure/storage/data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2"
"github.com/raito-io/cli-plugin-azure/global"
"github.com/aws/smithy-go/ptr"
"github.com/raito-io/cli/base/data_source"
"github.com/raito-io/cli/base/wrappers"

"github.com/raito-io/cli-plugin-azure/global"

"github.com/raito-io/cli/base/access_provider/sync_from_target"
importer "github.com/raito-io/cli/base/access_provider/sync_to_target"
"github.com/raito-io/cli/base/util/config"
Expand Down Expand Up @@ -60,19 +62,23 @@ func (a *DataAccessSyncer) SyncAccessProvidersFromTarget(ctx context.Context, ia
doFullname = strings.Replace(doFullname, "resourcegroups", "", 1)
doFullname = strings.Replace(doFullname, "storageAccounts", "", 1)
doFullname = strings.Replace(doFullname, "storageaccounts", "", 1)
doFullname = strings.Replace(doFullname, "blobServices/default/containers", "", 1)
doFullname = strings.Replace(doFullname, "containers", "", 1)
doFullname = strings.Replace(doFullname, "//", "/", -1)

apName = fmt.Sprintf("%s-%s-%s", doType, scopeSplit[len(scopeSplit)-1], strings.ReplaceAll(assignment.RoleName, " ", "-"))
}

logger.Debug(fmt.Sprintf("Rewrite scope: %q to doFullName: %q", assignment.Scope, doFullname))

if _, f := apMap[apName]; !f {
apMap[apName] = &sync_from_target.AccessProvider{
ExternalId: apName,
Name: apName,
NamingHint: apName,
ActualName: apName,
Action: sync_from_target.Grant,
Type: ptr.String(RoleAssignments),
Who: &sync_from_target.WhoItem{
Users: []string{},
Groups: []string{},
Expand Down Expand Up @@ -157,6 +163,8 @@ func convertAccessProviderToIamRoleAssignments(ctx context.Context, accessProvid
fullNameParts := strings.Split(what.DataObject.FullName, "/")

switch what.DataObject.Type {
case "subscription":
scope = fmt.Sprintf("/subscriptions/%s", fullNameParts[0])
case "resourcegroup":
if len(fullNameParts) < 2 {
break
Expand All @@ -171,7 +179,7 @@ func convertAccessProviderToIamRoleAssignments(ctx context.Context, accessProvid
if len(fullNameParts) < 4 {
break
}
scope = fmt.Sprintf("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Storage/storageAccounts/%s/containers/%s", fullNameParts[0], fullNameParts[1], fullNameParts[2], fullNameParts[3])
scope = fmt.Sprintf("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Storage/storageAccounts/%s/blobServices/default/containers/%s", fullNameParts[0], fullNameParts[1], fullNameParts[2], fullNameParts[3])
}

if scope == "" {
Expand All @@ -195,7 +203,7 @@ func convertAccessProviderToIamRoleAssignments(ctx context.Context, accessProvid
continue
}

for _, u := range append(accessProvider.Who.Users, accessProvider.Who.UsersInherited...) {
for _, u := range accessProvider.Who.Users {
bindings[i] = append(bindings[i], global.IAMRoleAssignment{
Scope: scope,
RoleName: permission,
Expand Down
3 changes: 2 additions & 1 deletion azure/storage/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (

ds "github.com/raito-io/cli/base/data_source"

"github.com/raito-io/cli-plugin-azure/global"
"github.com/raito-io/cli/base/util/config"
"github.com/raito-io/cli/base/wrappers"

"github.com/raito-io/cli-plugin-azure/global"
)

type DataSourceSyncer struct {
Expand Down
111 changes: 53 additions & 58 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,93 +1,88 @@
module github.com/raito-io/cli-plugin-azure

go 1.18

require (
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.3.0
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.0.0
github.com/hashicorp/go-hclog v1.5.0
github.com/raito-io/cli v0.42.0
github.com/raito-io/cli-plugin-azure-ad v0.3.0
github.com/vektra/mockery/v2 v2.27.1
)
go 1.21

require (
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.1
github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery v1.1.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.1.1
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.10.1
github.com/google/uuid v1.3.0
github.com/stretchr/testify v1.8.3
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.4.0
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.1.0
github.com/google/uuid v1.3.1
github.com/hashicorp/go-hclog v1.5.0
github.com/raito-io/cli v0.47.0-dev1
github.com/raito-io/cli-plugin-azure-ad v0.3.1
github.com/stretchr/testify v1.8.4
github.com/vektra/mockery/v2 v2.33.2
)

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0-beta.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.25 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.24 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.22.10 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/aws/aws-sdk-go-v2 v1.21.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.38 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.36 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.42 // indirect
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.13.6 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 // indirect
github.com/aws/smithy-go v1.14.2 // indirect
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df // indirect
github.com/bcicen/jstream v1.0.1 // indirect
github.com/chigopher/pathlib v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.9 // indirect
github.com/hashicorp/go-plugin v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/hasura/go-graphql-client v0.9.3 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hasura/go-graphql-client v0.10.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/zerolog v1.29.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/rs/zerolog v1.30.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.12.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit b3aabfc

Please sign in to comment.