Skip to content

Commit

Permalink
chore: bump duty & artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Dec 21, 2023
1 parent 1aa9de3 commit e438bd9
Show file tree
Hide file tree
Showing 27 changed files with 393 additions and 842 deletions.
10 changes: 5 additions & 5 deletions api/v1/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ type Bucket struct {
}

type S3Check struct {
Description `yaml:",inline" json:",inline"`
connection.AWSConnection `yaml:",inline" json:",inline"`
BucketName string `yaml:"bucketName" json:"bucketName,omitempty"`
Description `yaml:",inline" json:",inline"`
connection.S3Connection `yaml:",inline" json:",inline"`
BucketName string `yaml:"bucketName" json:"bucketName,omitempty"`
}

func (c S3Check) GetEndpoint() string {
Expand Down Expand Up @@ -803,8 +803,8 @@ type FolderCheck struct {
Recursive bool `yaml:"recursive,omitempty" json:"recursive,omitempty"`
Filter FolderFilter `yaml:"filter,omitempty" json:"filter,omitempty"`
FolderTest `yaml:",inline" json:",inline"`
*connection.AWSConnection `yaml:"awsConnection,omitempty" json:"awsConnection,omitempty"`
*connection.GCPConnection `yaml:"gcpConnection,omitempty" json:"gcpConnection,omitempty"`
*connection.S3Connection `yaml:"awsConnection,omitempty" json:"awsConnection,omitempty"`
*connection.GCSConnection `yaml:"gcpConnection,omitempty" json:"gcpConnection,omitempty"`
*connection.SMBConnection `yaml:"smbConnection,omitempty" json:"smbConnection,omitempty"`
*connection.SFTPConnection `yaml:"sftpConnection,omitempty" json:"sftpConnection,omitempty"`
}
Expand Down
14 changes: 7 additions & 7 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions checks/folder_gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@ func CheckGCSBucket(ctx *context.Context, check v1.FolderCheck) pkg.Results {
var results pkg.Results
results = append(results, result)

if check.GCPConnection == nil {
return results.ErrorMessage(errors.New("missing GCP connection"))
if check.GCSConnection == nil {
return results.ErrorMessage(errors.New("missing GCS connection"))
}

var bucket string
bucket, check.Path = parseGCSPath(check.Path)

connection, err := ctx.HydrateConnectionByURL(check.GCPConnection.ConnectionName)
if err != nil {
return results.Failf("failed to populate GCP connection: %v", err)
return results.Failf("failed to populate GCS connection: %v", err)
} else if connection == nil {
connection = &models.Connection{}
connection, err = connection.Merge(ctx, check.GCPConnection)
connection = &models.Connection{Type: models.ConnectionTypeGCS}
if check.GCSConnection.Bucket == "" {
check.GCSConnection.Bucket = bucket
}

connection, err = connection.Merge(ctx, check.GCSConnection)
if err != nil {
return results.Failf("failed to populate GCP connection: %v", err)
return results.Failf("failed to populate GCS connection: %v", err)
}
}

Expand All @@ -42,13 +49,6 @@ func CheckGCSBucket(ctx *context.Context, check v1.FolderCheck) pkg.Results {
return results.ErrorMessage(err)
}

// check.Path will be in the format gcs://bucket_name/<actual_path>
fullPath := getGCSBucketName(check.Path)
splits := strings.SplitN(fullPath, "/", 2)
if len(splits) > 1 {
check.Path = splits[1]
}

folders, err := genericFolderCheckWithoutPrecheck(fs, check.Path, check.Recursive, check.Filter)
if err != nil {
return results.ErrorMessage(err)
Expand All @@ -62,14 +62,14 @@ func CheckGCSBucket(ctx *context.Context, check v1.FolderCheck) pkg.Results {
return results
}

// getGCSBucketName returns the actual path stripping of the gcs:// prefix and the bucket name.
// parseGCSPath returns the bucket name and the actual path stripping of the gcs:// prefix and the bucket name.
// The path is expected to be in the format "gcs://bucket_name/<actual_path>"
func getGCSBucketName(path string) string {
trimmed := strings.TrimPrefix(path, "gcs://")
func parseGCSPath(fullpath string) (bucket, path string) {
trimmed := strings.TrimPrefix(fullpath, "gcs://")
splits := strings.SplitN(trimmed, "/", 2)
if len(splits) != 2 {
return ""
return splits[0], ""
}

return splits[1]
return splits[0], splits[1]
}
24 changes: 15 additions & 9 deletions checks/folder_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@ func CheckS3Bucket(ctx *context.Context, check v1.FolderCheck) pkg.Results {
var results pkg.Results
results = append(results, result)

if check.AWSConnection == nil {
if check.S3Connection == nil {
return results.ErrorMessage(errors.New("missing AWS connection"))
}

var bucket string
bucket, check.Path = parseS3Path(check.Path)

connection, err := ctx.HydrateConnectionByURL(check.AWSConnection.ConnectionName)
if err != nil {
return results.Failf("failed to populate AWS connection: %v", err)
} else if connection == nil {
connection = &models.Connection{}
connection, err = connection.Merge(ctx, check.AWSConnection)
connection = &models.Connection{Type: models.ConnectionTypeS3}
if check.S3Connection.Bucket == "" {
check.S3Connection.Bucket = bucket
}

connection, err = connection.Merge(ctx, check.S3Connection)
if err != nil {
return results.Failf("failed to populate AWS connection: %v", err)
}
Expand All @@ -44,7 +51,6 @@ func CheckS3Bucket(ctx *context.Context, check v1.FolderCheck) pkg.Results {
return results.ErrorMessage(err)
}

check.Path = getS3Path(check.Path)
folders, err := genericFolderCheckWithoutPrecheck(fs, check.Path, check.Recursive, check.Filter)
if err != nil {
return results.ErrorMessage(err)
Expand All @@ -58,14 +64,14 @@ func CheckS3Bucket(ctx *context.Context, check v1.FolderCheck) pkg.Results {
return results
}

// getS3Path returns the actual path stripping of the s3:// prefix and the bucket name.
// parseS3Path returns the bucket name and the actual path stripping of the s3:// prefix and the bucket name.
// The path is expected to be in the format "s3://bucket_name/<actual_path>"
func getS3Path(path string) string {
trimmed := strings.TrimPrefix(path, "s3://")
func parseS3Path(fullpath string) (bucket, path string) {
trimmed := strings.TrimPrefix(fullpath, "s3://")
splits := strings.SplitN(trimmed, "/", 2)
if len(splits) != 2 {
return ""
return splits[0], ""
}

return splits[1]
return splits[0], splits[1]
}
30 changes: 30 additions & 0 deletions checks/folder_s3_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build !fast

package checks

import "testing"

func Test_parseS3Path(t *testing.T) {
tests := []struct {
name string
fullpath string
wantBucket string
wantPath string
}{
{name: "basic", fullpath: "s3://mybucket/developers", wantBucket: "mybucket", wantPath: "developers"},
{name: "basic", fullpath: "s3://mybucket", wantBucket: "mybucket", wantPath: ""},
{name: "basic", fullpath: "mybucket", wantBucket: "mybucket", wantPath: ""},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotBucket, gotPath := parseS3Path(tt.fullpath)
if gotBucket != tt.wantBucket {
t.Errorf("parseS3Path() gotBucket = %v, want %v", gotBucket, tt.wantBucket)
}
if gotPath != tt.wantPath {
t.Errorf("parseS3Path() gotPath = %v, want %v", gotPath, tt.wantPath)
}
})
}
}
2 changes: 1 addition & 1 deletion checks/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *S3Checker) Check(ctx *context.Context, extConfig external.Check) pkg.Re
}

client := s3.NewFromConfig(cfg, func(o *s3.Options) {
o.UsePathStyle = check.AWSConnection.UsePathStyle
o.UsePathStyle = check.S3Connection.UsePathStyle
})

listTimer := NewTimer()
Expand Down
Loading

0 comments on commit e438bd9

Please sign in to comment.