Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribution Update And Operational Risk Related Fix #208

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/terraform-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
steps:
- name: Checkout the code
uses: actions/checkout@v3
- name: Replace "master" with "main" in ATTRIBUTION.md
run: sed -i 's/\/master/\/main/g' about/ATTRIBUTION.md
- name: Run the forbidden words scan
uses: dell/common-github-actions/code-sanitizer@main
with:
Expand Down
479 changes: 447 additions & 32 deletions about/ATTRIBUTION.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func NewOpenAPIClient(ctx context.Context, endpoint string, insecure bool, user
OperationServers: map[string]powerscale.ServerConfigurations{},
}
cfg.DefaultHeader = getHeaders()
fmt.Printf("config %+v header %+v\n", cfg, cfg.DefaultHeader)
//fmt.Printf("config %+v header %+v\n", cfg, cfg.DefaultHeader)

if authType == BasicAuthType {
httpclient.Transport = transport
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ require (
github.com/hashicorp/terraform-plugin-go v0.23.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-testing v1.9.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.9.0
golang.org/x/net v0.28.0
golang.org/x/sync v0.8.0
)

require (
Expand Down Expand Up @@ -68,6 +66,7 @@ require (
github.com/zclconf/go-cty v1.14.4 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down
40 changes: 38 additions & 2 deletions powerscale/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package provider

import (
"bufio"
"context"
"crypto/tls"
powerscale "dell/powerscale-go-client"
Expand All @@ -40,7 +41,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/joho/godotenv"
"github.com/stretchr/testify/assert"
)

Expand All @@ -64,7 +64,7 @@ var BasicAuthProviderErrorConfig = ""
var FunctionMocker *mockey.Mocker

func init() {
err := godotenv.Load("powerscale.env")
_, err := loadEnvFile("powerscale.env")
if err != nil {
log.Fatal("Error loading .env file: ", err)
return
Expand Down Expand Up @@ -410,3 +410,39 @@ func TestInsecureClientWithInsecureParam(t *testing.T) {
}
assert.NotNil(t, openAPIClient)
}

// loadEnvFile used to read env file and set params
func loadEnvFile(path string) (map[string]string, error) {
envMap := make(map[string]string)

file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if len(line) == 0 || line[0] == '#' {
continue
}
parts := strings.SplitN(line, "=", 2)
if len(parts) != 2 {
continue
}
key := strings.TrimSpace(parts[0])
value := strings.TrimSpace(parts[1])
envMap[key] = value
// Set the environment variable for system access
if err := os.Setenv(key, value); err != nil {
return nil, fmt.Errorf("error setting environment variable %s: %w", key, err)
}
}

if err := scanner.Err(); err != nil {
return nil, err
}

return envMap, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ func (d *SyncIQPeerCertificateDataSource) Read(ctx context.Context, req datasour
// Apply the Name Filter if it is set
if data.PeerCertificateFilter != nil && data.PeerCertificateFilter.Name.ValueString() != "" {
nameFilter := data.PeerCertificateFilter.Name.ValueString()
fmt.Println("nameFilter:", nameFilter)
config.Certificates = slices.DeleteFunc(config.Certificates, func(i powerscale.V16CertificatesSyslogCertificate) bool { return i.Name != nameFilter })
if len(config.Certificates) == 0 {
resp.Diagnostics.AddError("Error reading syncIQ peer certificate", fmt.Sprintf("Could not find syncIQ peer certificate with name %s", nameFilter))
Expand Down
12 changes: 4 additions & 8 deletions powerscale/provider/user_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"golang.org/x/sync/errgroup"
)

// Ensure provider defined types fully satisfy framework interfaces.
Expand Down Expand Up @@ -346,26 +345,23 @@ func (d *UserDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
}

// start goroutine to cache all roles
var eg errgroup.Group
var roles []powerscale.V1AuthRoleExtended
var roleErr error
var zoneID string
if state.Filter != nil && !state.Filter.Zone.IsNull() {
zoneID = state.Filter.Zone.ValueString()
}
eg.Go(func() error {
roles, roleErr = helper.GetAllRolesWithZone(ctx, d.client, zoneID)
return roleErr
})

users, err := helper.GetUsersWithFilter(ctx, d.client, state.Filter)
if err != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale Users.", err.Error())
return
}

if err := eg.Wait(); err != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale Roles", err.Error())
roles, roleErr = helper.GetAllRolesWithZone(ctx, d.client, zoneID)
if roleErr != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale Users.", roleErr.Error())
return
}

// parse user response to state user model
Expand Down
16 changes: 5 additions & 11 deletions powerscale/provider/user_group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"golang.org/x/sync/errgroup"
)

// Ensure provider defined types fully satisfy framework interfaces.
Expand Down Expand Up @@ -263,29 +262,24 @@ func (d *UserGroupDataSource) Read(ctx context.Context, req datasource.ReadReque
return
}

// start goroutine to cache all roles
var egRole errgroup.Group
var roles []powerscale.V1AuthRoleExtended
var roleErr error
var zoneID string
if state.Filter != nil && !state.Filter.Zone.IsNull() {
zoneID = state.Filter.Zone.ValueString()
}
egRole.Go(func() error {
roles, roleErr = helper.GetAllRolesWithZone(ctx, d.client, zoneID)
return roleErr
})
roles, roleErr = helper.GetAllRolesWithZone(ctx, d.client, zoneID)
if roleErr != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale Roles.", roleErr.Error())
return
}

groupsResponse, err := helper.GetUserGroupsWithFilter(ctx, d.client, state.Filter)
if err != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale User Groups.", err.Error())
return
}

if err := egRole.Wait(); err != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale Roles", err.Error())
}

var groups []models.UserGroupModel
for _, group := range groupsResponse {
model := models.UserGroupModel{}
Expand Down
16 changes: 5 additions & 11 deletions powerscale/provider/user_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"golang.org/x/sync/errgroup"
)

// Ensure provider defined types fully satisfy framework interfaces.
Expand Down Expand Up @@ -365,14 +364,13 @@ func (r *UserGroupResource) ImportState(ctx context.Context, req resource.Import
zoneID = strings.Trim(params[0], " ")
}

// start goroutine to cache all roles
var eg errgroup.Group
var roles []powerscale.V1AuthRoleExtended
var roleErr error
eg.Go(func() error {
roles, roleErr = helper.GetAllRolesWithZone(ctx, r.client, zoneID)
return roleErr
})
roles, roleErr = helper.GetAllRolesWithZone(ctx, r.client, zoneID)
if roleErr != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale Roles.", roleErr.Error())
return
}

result, err := helper.GetUserGroupWithZone(ctx, r.client, groupName, zoneID)
if err != nil {
Expand All @@ -385,10 +383,6 @@ func (r *UserGroupResource) ImportState(ctx context.Context, req resource.Import
resp.Diagnostics.AddError(fmt.Sprintf("Error getting the list of PowerScale Group Members of %s", groupName), err.Error())
}

if err := eg.Wait(); err != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale Roles", err.Error())
}

// parse user response to state user group model
helper.UpdateUserGroupResourceState(&state, result.Groups[0], members, roles)
if zoneID != "" {
Expand Down
16 changes: 5 additions & 11 deletions powerscale/provider/user_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"golang.org/x/sync/errgroup"
)

// Ensure provider defined types fully satisfy framework interfaces.
Expand Down Expand Up @@ -511,14 +510,13 @@ func (r *UserResource) ImportState(ctx context.Context, req resource.ImportState
zoneID = strings.Trim(params[0], " ")
}

// start goroutine to cache all roles
var eg errgroup.Group
var roles []powerscale.V1AuthRoleExtended
var roleErr error
eg.Go(func() error {
roles, roleErr = helper.GetAllRolesWithZone(ctx, r.client, zoneID)
return roleErr
})
roles, roleErr = helper.GetAllRolesWithZone(ctx, r.client, zoneID)
if roleErr != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale Roles.", roleErr.Error())
return
}

result, err := helper.GetUserWithZone(ctx, r.client, userName, zoneID)
if err != nil {
Expand All @@ -529,10 +527,6 @@ func (r *UserResource) ImportState(ctx context.Context, req resource.ImportState
return
}

if err := eg.Wait(); err != nil {
resp.Diagnostics.AddError("Error getting the list of PowerScale Roles", err.Error())
}

// parse user response to state user model
helper.UpdateUserResourceState(&state, result.Users[0], roles)
if zoneID != "" {
Expand Down
Loading