Skip to content

Commit

Permalink
Merge pull request #174 from jfrog/migrate-xray-settings-resource
Browse files Browse the repository at this point in the history
Migrate xray_settings resource to Plugin Framework
  • Loading branch information
alexhung authored Apr 29, 2024
2 parents 5064961 + b806e8e commit 609e035
Show file tree
Hide file tree
Showing 18 changed files with 292 additions and 189 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.5.1 (April 29, 2024). Tested on Artifactory 7.77.10 and Xray 3.94.5

* resource/xray_settings: Migrate from SDKv2 to Plugin Framework. PR: [#174](https://github.com/jfrog/terraform-provider-xray/pull/174)

## 2.5.0 (March 29, 2024). Tested on Artifactory 7.77.8 and Xray 3.91.3

FEATURES:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/terraform-plugin-mux v0.15.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/hashicorp/terraform-plugin-testing v1.5.1
github.com/jfrog/terraform-provider-shared v1.22.1
github.com/jfrog/terraform-provider-shared v1.24.0
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jfrog/terraform-provider-shared v1.22.1 h1:tGety2oaxUiMB4yrpJ9S+770tDxSIlnD4qpL0y9p+z0=
github.com/jfrog/terraform-provider-shared v1.22.1/go.mod h1:OozwvfahZU4Q9u3kXdpQI3h/Etrs2DXoouQDrpxB1cQ=
github.com/jfrog/terraform-provider-shared v1.24.0 h1:VItpElBn9Jku8gtN7DhOURUIyoUYYw8R9erPBPgKwv8=
github.com/jfrog/terraform-provider-shared v1.24.0/go.mod h1:OozwvfahZU4Q9u3kXdpQI3h/Etrs2DXoouQDrpxB1cQ=
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/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down
2 changes: 1 addition & 1 deletion pkg/acctest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func VerifyDeleted(id string, check CheckFun) func(*terraform.State) error {
return fmt.Errorf("provider is not initialized. Please PreCheck() is included in your acceptance test")
}

providerMeta := Provider.Meta().(util.ProvderMetadata)
providerMeta := Provider.Meta().(util.ProviderMetadata)

resp, err := check(rs.Primary.ID, providerMeta.Client.R())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/xray/datasource/datasource_xray_artifacts_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewArtifactsScanDataSource() datasource.DataSource {
}

type XrayArtifactsScanDataSource struct {
ProviderData util.ProvderMetadata
ProviderData util.ProviderMetadata
}

type XrayArtifactsScanDataSourceModel struct {
Expand Down Expand Up @@ -232,7 +232,7 @@ func (d *XrayArtifactsScanDataSource) Configure(ctx context.Context, req datasou
return
}

d.ProviderData = req.ProviderData.(util.ProvderMetadata)
d.ProviderData = req.ProviderData.(util.ProviderMetadata)
}

var severitySchemaAttributes = map[string]schema.Attribute{
Expand Down
17 changes: 11 additions & 6 deletions pkg/xray/provider/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/jfrog/terraform-provider-shared/client"
"github.com/jfrog/terraform-provider-shared/util"
utilfw "github.com/jfrog/terraform-provider-shared/util/fw"
validatorfw_string "github.com/jfrog/terraform-provider-shared/validator/fw/string"
xray_datasource "github.com/jfrog/terraform-provider-xray/pkg/xray/datasource"
xray_resource "github.com/jfrog/terraform-provider-xray/pkg/xray/resource"
)

// Ensure the implementation satisfies the provider.Provider interface.
Expand Down Expand Up @@ -124,8 +124,11 @@ func (p *XrayProvider) Configure(ctx context.Context, req provider.ConfigureRequ
}

if config.CheckLicense.IsNull() || config.CheckLicense.ValueBool() {
if licenseDs := utilfw.CheckArtifactoryLicense(restyBase, "Enterprise", "Commercial", "Edge"); licenseDs != nil {
resp.Diagnostics.Append(licenseDs...)
if licenseDs := util.CheckArtifactoryLicense(restyBase, "Enterprise", "Commercial", "Edge"); licenseDs != nil {
resp.Diagnostics.AddError(
"Error checking license",
licenseDs.Error(),
)
return
}
}
Expand All @@ -142,13 +145,13 @@ func (p *XrayProvider) Configure(ctx context.Context, req provider.ConfigureRequ
featureUsage := fmt.Sprintf("Terraform/%s", req.TerraformVersion)
go util.SendUsage(ctx, restyBase, productId, featureUsage)

resp.DataSourceData = util.ProvderMetadata{
resp.DataSourceData = util.ProviderMetadata{
Client: restyBase,
ProductId: productId,
XrayVersion: version,
}

resp.ResourceData = util.ProvderMetadata{
resp.ResourceData = util.ProviderMetadata{
Client: restyBase,
ProductId: productId,
XrayVersion: version,
Expand All @@ -157,7 +160,9 @@ func (p *XrayProvider) Configure(ctx context.Context, req provider.ConfigureRequ

// Resources satisfies the provider.Provider interface for ArtifactoryProvider.
func (p *XrayProvider) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{}
return []func() resource.Resource{
xray_resource.NewSettingsResource,
}
}

// DataSources satisfies the provider.Provider interface for ArtifactoryProvider.
Expand Down
7 changes: 3 additions & 4 deletions pkg/xray/provider/sdkv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func SdkV2() *schema.Provider {
"xray_operational_risk_policy": xray.ResourceXrayOperationalRiskPolicy(),
"xray_watch": xray.ResourceXrayWatch(),
"xray_ignore_rule": xray.ResourceXrayIgnoreRule(),
"xray_settings": xray.ResourceXraySettings(),
"xray_workers_count": xray.ResourceXrayWorkersCount(),
"xray_repository_config": xray.ResourceXrayRepositoryConfig(),
"xray_vulnerabilities_report": xray.ResourceXrayVulnerabilitiesReport(),
Expand Down Expand Up @@ -99,9 +98,9 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, terraformVer

checkLicense := d.Get("check_license").(bool)
if checkLicense {
licenseErr := sdk.CheckArtifactoryLicense(restyBase, "Enterprise", "Commercial")
licenseErr := util.CheckArtifactoryLicense(restyBase, "Enterprise", "Commercial")
if licenseErr != nil {
return nil, licenseErr
return nil, diag.FromErr(licenseErr)
}
}

Expand All @@ -118,7 +117,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, terraformVer
featureUsage := fmt.Sprintf("Terraform/%s", terraformVersion)
go util.SendUsage(ctx, restyBase, productId, featureUsage)

return util.ProvderMetadata{
return util.ProviderMetadata{
Client: restyBase,
ArtifactoryVersion: artifactoryVersion,
XrayVersion: xrayVersion,
Expand Down
8 changes: 4 additions & 4 deletions pkg/xray/resource/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ func resourceXrayPolicyCreate(ctx context.Context, d *schema.ResourceData, m int
return diag.FromErr(err)
}

req, err := getRestyRequest(m.(util.ProvderMetadata).Client, policy.ProjectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, policy.ProjectKey)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -734,7 +734,7 @@ func resourceXrayPolicyRead(ctx context.Context, d *schema.ResourceData, m inter
var policy Policy

projectKey := d.Get("project_key").(string)
req, err := getRestyRequest(m.(util.ProvderMetadata).Client, projectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, projectKey)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -763,7 +763,7 @@ func resourceXrayPolicyUpdate(ctx context.Context, d *schema.ResourceData, m int
return diag.FromErr(err)
}

req, err := getRestyRequest(m.(util.ProvderMetadata).Client, policy.ProjectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, policy.ProjectKey)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -791,7 +791,7 @@ func resourceXrayPolicyDelete(ctx context.Context, d *schema.ResourceData, m int
return diag.FromErr(err)
}

req, err := getRestyRequest(m.(util.ProvderMetadata).Client, policy.ProjectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, policy.ProjectKey)
if err != nil {
return diag.FromErr(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/xray/resource/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func resourceXrayReportRead(ctx context.Context, d *schema.ResourceData, m inter
report := Report{}

projectKey := d.Get("project_key").(string)
req, err := getRestyRequest(m.(util.ProvderMetadata).Client, projectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, projectKey)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -644,7 +644,7 @@ func resourceXrayReportRead(ctx context.Context, d *schema.ResourceData, m inter

func resourceXrayReportDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
projectKey := d.Get("project_key").(string)
req, err := getRestyRequest(m.(util.ProvderMetadata).Client, projectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, projectKey)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -666,7 +666,7 @@ func resourceXrayReportDelete(_ context.Context, d *schema.ResourceData, m inter

func createReport(reportType string, d *schema.ResourceData, m interface{}) diag.Diagnostics {
report := unpackReport(d, reportType)
req, err := getRestyRequest(m.(util.ProvderMetadata).Client, report.ProjectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, report.ProjectKey)
if err != nil {
return diag.FromErr(err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/xray/resource/resource_xray_custom_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func ResourceXrayCustomIssue() *schema.Resource {
var resourceXrayCustomIssueRead = func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
customIssue := CustomIssue{}

req, err := getRestyRequest(m.(util.ProvderMetadata).Client, "")
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, "")
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -489,7 +489,7 @@ func ResourceXrayCustomIssue() *schema.Resource {
return diag.FromErr(err)
}

req, err := getRestyRequest(m.(util.ProvderMetadata).Client, "")
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, "")
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -515,7 +515,7 @@ func ResourceXrayCustomIssue() *schema.Resource {
return diag.FromErr(err)
}

req, err := getRestyRequest(m.(util.ProvderMetadata).Client, "")
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, "")
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -537,7 +537,7 @@ func ResourceXrayCustomIssue() *schema.Resource {
}

var resourceXrayCustomIssueDelete = func(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
req, err := getRestyRequest(m.(util.ProvderMetadata).Client, "")
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, "")
if err != nil {
return diag.FromErr(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/xray/resource/resource_xray_ignore_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func ResourceXrayIgnoreRule() *schema.Resource {
var ignoreRule IgnoreRule

projectKey := d.Get("project_key").(string)
req, err := getRestyRequest(m.(util.ProvderMetadata).Client, projectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, projectKey)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -504,7 +504,7 @@ func ResourceXrayIgnoreRule() *schema.Resource {
return diag.FromErr(err)
}

req, err := getRestyRequest(m.(util.ProvderMetadata).Client, ignoreRule.ProjectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, ignoreRule.ProjectKey)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -546,7 +546,7 @@ func ResourceXrayIgnoreRule() *schema.Resource {
return diag.FromErr(err)
}

req, err := getRestyRequest(m.(util.ProvderMetadata).Client, ignoreRule.ProjectKey)
req, err := getRestyRequest(m.(util.ProviderMetadata).Client, ignoreRule.ProjectKey)
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/xray/resource/resource_xray_repository_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func ResourceXrayRepositoryConfig() *schema.Resource {
repositoryConfig := RepositoryConfiguration{}
repoName := d.Id()

metadata := m.(util.ProvderMetadata)
metadata := m.(util.ProviderMetadata)

resp, err := metadata.Client.R().
SetResult(&repositoryConfig).
Expand All @@ -504,7 +504,7 @@ func ResourceXrayRepositoryConfig() *schema.Resource {
}

var resourceXrayRepositoryConfigCreate = func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
metadata := m.(util.ProvderMetadata)
metadata := m.(util.ProviderMetadata)
packageType, err := getPackageType(metadata.Client, d.Get("repo_name").(string))
if err != nil {
return diag.FromErr(err)
Expand Down
Loading

0 comments on commit 609e035

Please sign in to comment.