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

Add Create/Delete/Update methods to PolicyConditionService #14

Merged
merged 2 commits into from
Aug 29, 2023

Conversation

takumakume
Copy link

Hi!

The following implementation was added to PolicyConditionService:

  • Add Create/Delete/Update
  • Add const variable PolicyConditionOperator/PolicyConditionSubject

Confirmation that the following works with local DependencyTrack-v4.8.2:

import (
	"context"

	dtrack "github.com/DependencyTrack/client-go"
)

func main() {
	ctx := context.Background()
	client, err := dtrack.NewClient("http://localhost:8081", dtrack.WithAPIKey("..."))
	if err != nil {
		panic(err)
	}

	policy, err := client.Policy.Create(ctx, dtrack.Policy{
		Name:           "test",
		Operator:       dtrack.PolicyOperatorAny,
		ViolationState: dtrack.PolicyViolationStateFail,
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("created policy: %+v\n", policy)

	condition, err := client.PolicyCondition.Create(ctx, policy.UUID, dtrack.PolicyCondition{
		Subject:  dtrack.PolicyConditionSubjectVulnerabilityID,
		Operator: dtrack.PolicyConditionOperatorIs,
		Value:    "CVE-2023-1234",
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("created condition: %+v\n", condition)

	condition.Value = "CVE-2023-1235"

	conditionUpdated, err := client.PolicyCondition.Update(ctx, condition)
	if err != nil {
		panic(err)
	}
	fmt.Printf("updated condition %s: %+v\n", conditionUpdated.UUID, conditionUpdated.Value)

	if err := client.PolicyCondition.Delete(ctx, conditionUpdated.UUID); err != nil {
		panic(err)
	}
}
created policy: {UUID:fe07f3c6-6dca-4369-9800-192200d4a9f8 Name:test Operator:ANY ViolationState:INFO PolicyConditions:[] IncludeChildren:false Global:true Projects:[] Tags:[]}
created condition: {UUID:708d0f07-9484-4136-bacf-5b8a003e2917 Policy:<nil> Operator:IS Subject:VULNERABILITY_ID Value:CVE-2023-1234}
updated condition 708d0f07-9484-4136-bacf-5b8a003e2917: CVE-2023-1235

Signed-off-by: 久米 拓馬 <takuma.kume@pepabo.com>
Signed-off-by: 久米 拓馬 <takuma.kume@pepabo.com>
Copy link
Member

@nscuro nscuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @takumakume! 🙌

@nscuro nscuro merged commit f3504fe into DependencyTrack:main Aug 29, 2023
4 checks passed
@takumakume takumakume deleted the add-policy-condition-methods branch September 8, 2023 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants