Skip to content

Commit

Permalink
Merge pull request #120 from jfrog/GH-118-remove-file-exists-validation
Browse files Browse the repository at this point in the history
Remove validation on file path.
  • Loading branch information
chb0github authored Sep 9, 2021
2 parents 15603f8 + eef9a5c commit 73dc4c0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0
github.com/jfrog/jfrog-client-go v0.23.1
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20210510120138-977fb7262007
golang.org/x/tools v0.1.5 // indirect
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
23 changes: 14 additions & 9 deletions pkg/artifactory/datasource_artifactory_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func dataSourceArtifactoryFile() *schema.Resource {
"output_path": {
Type: schema.TypeString,
Required: true,
ValidateFunc: fileExist,
},
"force_overwrite": {
Type: schema.TypeBool,
Expand All @@ -116,11 +115,17 @@ func dataSourceFileRead(d *schema.ResourceData, m interface{}) error {
}

fileExists := FileExists(outputPath)
chksMatches, _ := VerifySha256Checksum(outputPath, fileInfo.Checksums.Sha256)
if !chksMatches {
return fmt.Errorf("local file differs from upstream version")
chksMatches, err := VerifySha256Checksum(outputPath, fileInfo.Checksums.Sha256)

if err != nil {
return err
}
if !fileExists || (!chksMatches && forceOverwrite) {

if fileExists {
if !chksMatches && !forceOverwrite {
return fmt.Errorf("local file differs from upstream version and no overwrite is permitted")
}
} else {
outFile, err := os.Create(outputPath)
if err != nil {
return err
Expand All @@ -129,11 +134,11 @@ func dataSourceFileRead(d *schema.ResourceData, m interface{}) error {
defer func(outFile *os.File) {
_ = outFile.Close()
}(outFile)
}

_, err = m.(*resty.Client).R().SetOutput(outputPath).Get(fileInfo.DownloadUri)
if err != nil {
return err
}
_, err = m.(*resty.Client).R().SetOutput(outputPath).Get(fileInfo.DownloadUri)
if err != nil {
return err
}

return packFileInfo(fileInfo, d)
Expand Down
8 changes: 4 additions & 4 deletions pkg/artifactory/resource_xray_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type PolicyRuleCriteria struct {
CVSSRange *PolicyCVSSRange `json:"cvss_range,omitempty"`

// License Criteria
AllowUnkown *bool `json:"allow_unknown,omitempty"`
AllowUnknown *bool `json:"allow_unknown,omitempty"`
BannedLicenses *[]string `json:"banned_licenses,omitempty"`
AllowedLicenses *[]string `json:"allowed_licenses,omitempty"`
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func expandCriteria(l []interface{}, policyType *string) (*PolicyRuleCriteria, e
}

// If these are both the default values, we must be using license criteria
criteria.AllowUnkown = allowUnk // "Unkown" is a typo in xray-oss
criteria.AllowUnknown = allowUnk
criteria.BannedLicenses = banned
criteria.AllowedLicenses = allowed
} else {
Expand Down Expand Up @@ -412,8 +412,8 @@ func flattenCriteria(criteria *PolicyRuleCriteria) []interface{} {
if criteria.MinimumSeverity != nil {
m["min_severity"] = *criteria.MinimumSeverity
}
if criteria.AllowUnkown != nil {
m["allow_unknown"] = *criteria.AllowUnkown // Same typo in the library
if criteria.AllowUnknown != nil {
m["allow_unknown"] = *criteria.AllowUnknown // Same typo in the library
}
if criteria.BannedLicenses != nil {
m["banned_licenses"] = *criteria.BannedLicenses
Expand Down
5 changes: 2 additions & 3 deletions pkg/artifactory/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package artifactory

import (
"fmt"
"github.com/gorhill/cronexpr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"net/mail"
"os"
"regexp"
"strings"

"github.com/gorhill/cronexpr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

Expand Down

0 comments on commit 73dc4c0

Please sign in to comment.