Skip to content

Commit

Permalink
Merge pull request #286 from jfrog/GH-285-fix-incorrect-request-field…
Browse files Browse the repository at this point in the history
…-name-for-ignore-rule

Fix incorrect request field name for ignore rule
  • Loading branch information
alexhung authored Dec 5, 2024
2 parents 4cd4411 + 5cb2cdd commit c963545
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 126 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
helm repo add jfrog https://charts.jfrog.io/
helm repo update
RT_HELM_CHART_VERSION=$(helm search repo | grep "jfrog/artifactory " | awk '{$1=$1};1' | cut -f2 -d " ")
echo "RT_HELM_CHART_VERSION=$RT_HELM_CHART_VERSION" >> "$GITHUB_ENV"
ARTIFACTORY_VERSION=$(helm search repo | grep "jfrog/artifactory " | awk '{$1=$1};1' | cut -f3 -d " ")
echo "rt_version=$ARTIFACTORY_VERSION" >> "$GITHUB_OUTPUT"
XRAY_HELM_CHART_VERSION=${XRAY_HELM_CHART_VERSION:=$(helm search repo | grep "jfrog/xray" | awk '{$1=$1};1' | cut -f2 -d " ")}
Expand Down Expand Up @@ -100,6 +101,7 @@ jobs:
echo "::add-mask::$JOIN_KEY"
echo "JOIN_KEY=$JOIN_KEY" >> "$GITHUB_ENV"
helm upgrade --install artifactory jfrog/artifactory \
--version $RT_HELM_CHART_VERSION \
--set artifactory.masterKey=$MASTER_KEY \
--set artifactory.joinKey=$JOIN_KEY \
--set artifactory.license.secret=artifactory-license \
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 3.0.2 (December 4, 2024). Tested on Artifactory 7.98.9 and Xray 3.107.16 with Terraform 1.10.1 and OpenTofu 1.8.7

BUG FIXES:

* resource/xray_ignore_rule: Fix incorrect API request field name for `release_bundle` attribute. Issue: [#285](https://github.com/jfrog/terraform-provider-xray/issues/285) PR: [#286](https://github.com/jfrog/terraform-provider-xray/issues/286)

IMPROVEMENTS:

* resource/xray_binary_manager_repos: Update validation attribute `package_type` to match Xray API. PR: [#286](https://github.com/jfrog/terraform-provider-xray/issues/286)

## 3.0.1 (November 19, 2024)

BUG FIXES:
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ attach:

acceptance: fmt
export TF_ACC=true && \
go test -cover -coverprofile=coverage.txt -ldflags="-X '${PKG_VERSION_PATH}/provider.Version=${NEXT_VERSION}-test'" -v -p 1 -parallel 20 -timeout 35m ./pkg/...
go test -cover -coverprofile=coverage.txt -ldflags="-X '${PKG_VERSION_PATH}/provider.Version=${NEXT_VERSION}-test'" -v -p 1 -parallel 20 -timeout 45m ./pkg/...

# To generate coverage.txt run `make acceptance` first
coverage:
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/binary_manager_repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ resource "xray_binary_manager_repos" "my-indexed-repos" {
Required:

- `name` (String) Name of the repository
- `package_type` (String) Artifactory package type. Valid value: Alpine, Bower, Cargo, Composer, Conan, Conda, Cran, Debian, Docker, Generic, Go, Gradle, Huggingface, Ivy, Maven, Npm, Nuget, Oci, Pypi, Rpm, Rubygems, Sbt, Terraformbe
- `package_type` (String) Artifactory package type. Valid value: Alpine Linux, Bower, Cargo, Composer, CocoaPods, Conan, Conda, CRAN, Debian, Docker, Gems, Generic, Go, Gradle, HuggingFaceML, Ivy, Maven, npm, NuGet, OCI, Pypi, RPM, SBT, TerraformBackend
- `type` (String) Repository type. Valid value: local, remote, federated


Expand Down
29 changes: 29 additions & 0 deletions pkg/acctest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"strings"
"sync"
"testing"

"github.com/go-resty/resty/v2"
Expand All @@ -23,6 +24,14 @@ var ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, erro
"xray": providerserver.NewProtocol6WithError(xray.NewProvider()()),
}

// testAccProviderConfigure ensures Provider is only configured once
//
// The PreCheck(t) function is invoked for every test and this prevents
// extraneous reconfiguration to the same values each time. However, this does
// not prevent reconfiguration that may happen should the address of
// Provider be errantly reused in ProviderFactories.
var testAccProviderConfigure sync.Once

func init() {
Provider = xray.NewProvider()()

Expand All @@ -31,6 +40,26 @@ func init() {
}
}

// PreCheck This function should be present in every acceptance test.
func PreCheck(t *testing.T) {
// Since we are outside the scope of the Terraform configuration we must
// call Configure() to properly initialize the provider configuration.
testAccProviderConfigure.Do(func() {
restyClient := GetTestResty(t)

artifactoryUrl := testutil.GetEnvVarWithFallback(t, "JFROG_URL", "ARTIFACTORY_URL")
// Set custom base URL so repos that relies on it will work
// https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-UpdateCustomURLBase
_, err := restyClient.R().
SetBody(artifactoryUrl).
SetHeader("Content-Type", "text/plain").
Put("/artifactory/api/system/configuration/baseUrl")
if err != nil {
t.Fatalf("failed to set custom base URL: %v", err)
}
})
}

type CheckFun func(id string, request *resty.Request) (*resty.Response, error)

func VerifyDeleted(id, identifierAttribute string, check CheckFun) func(*terraform.State) error {
Expand Down
36 changes: 28 additions & 8 deletions pkg/xray/resource/resource_xray_binary_manager_repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
utilfw "github.com/jfrog/terraform-provider-shared/util/fw"
validatorfw_string "github.com/jfrog/terraform-provider-shared/validator/fw/string"
"github.com/samber/lo"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

const BinaryManagerReposEndpoint = "xray/api/v1/binMgr/{id}/repos"
Expand Down Expand Up @@ -145,10 +143,32 @@ type BinaryManagerRepoAPIModel struct {
PackageType string `json:"pkg_type"`
}

var validTitledPackageTypes = lo.Map(validPackageTypes, func(packageType string, _ int) string {
caser := cases.Title(language.AmericanEnglish, cases.NoLower)
return caser.String(packageType)
})
var validBinMgrPackageTypes = []string{
"Alpine Linux",
"Bower",
"Cargo",
"Composer",
"CocoaPods",
"Conan",
"Conda",
"CRAN",
"Debian",
"Docker",
"Gems",
"Generic",
"Go",
"Gradle",
"HuggingFaceML",
"Ivy",
"Maven",
"npm",
"NuGet",
"OCI",
"Pypi",
"RPM",
"SBT",
"TerraformBackend",
}

func (r *BinaryManagerReposResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Expand Down Expand Up @@ -190,9 +210,9 @@ func (r *BinaryManagerReposResource) Schema(ctx context.Context, req resource.Sc
"package_type": schema.StringAttribute{
Required: true,
Validators: []validator.String{
stringvalidator.OneOf(validTitledPackageTypes...),
stringvalidator.OneOf(validBinMgrPackageTypes...),
},
Description: fmt.Sprintf("Artifactory package type. Valid value: %s", strings.Join(validTitledPackageTypes, ", ")),
Description: fmt.Sprintf("Artifactory package type. Valid value: %s", strings.Join(validBinMgrPackageTypes, ", ")),
},
},
},
Expand Down
Loading

0 comments on commit c963545

Please sign in to comment.