nexuswebhook

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2020 License: Apache-2.0 Imports: 10 Imported by: 1

README

Nexus Webhook Collection Example - NOW IN GOLANG!

What is this?

A go library for colecting Webhooks from a Sonatype Nexus IQ server. It is useful to be able to collect the outcoming Webhooks and then extend them to forward them to other services like ELK, Splunk or Slack (examples to come!)

The Fine Print

It is worth noting that this is NOT SUPPORTED by Sonatype, and is a contribution of ours to the open source community (read: you!)

Remember:

  • Use this contribution at the risk tolerance that you have
  • Do NOT file Sonatype support tickets for support in regard to this example
  • DO file issues here on GitHub, so that the community can pitch in

Phew, that was easier than I thought. Last but not least of all:

Have fun creating and using this plugin and the Nexus platform, we are glad to have you here!

Getting help

Looking to contribute to our code but need some help? There's a few ways to get information:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse")
	ErrInvalidHTTPMethod        = errors.New("invalid HTTP Method")
	ErrEventNotFound            = errors.New("event not defined to be parsed")
	ErrParsingPayload           = errors.New("error parsing payload")
	ErrMissingWebhookIdHeader   = errors.New("missing X-Nexus-Webhook-Id Header")
	ErrMissingSignatureHeader   = errors.New("missing X-Nexus-Webhook-Signature Header")
	ErrHMACVerificationFailed   = errors.New("HMAC verification failed")
)

parse errors

View Source
var Options = WebhookOptions{}

Options is a namespace var for configuration options

Functions

This section is empty.

Types

type ApplicationEvaluationPayload

type ApplicationEvaluationPayload struct {
	//Timestamp time.Time `json:"timestamp"`
	Timestamp             string `json:"timestamp"`
	Initiator             string `json:"initiator"`
	Id                    string `json:"id"`
	ApplicationEvaluation struct {
		PolicyEvaluationId string `json:"policyEvaluationId"`
		Stage              string `json:"stage"`
		OwnerId            string `json:"ownerId"`
		//EvaluationDate SonatypeDate `json:"evaluationDate"`
		EvaluationDate         string `json:"evaluationDate"`
		AffectedComponentCount int64  `json:"affectedComponentCount"`
		CriticalComponentCount int64  `json:"criticalComponentCount"`
		SevereComponentCount   int64  `json:"severeComponentCount"`
		ModerateComponentCount int64  `json:"moderateComponentCount"`
		Outcome                string `json:"outcome"`
	} `json:"applicationEvaluation"`
}

ApplicationEvaluation contains the information for Sonatype IQ server Application Evaluation hook event

type Event

type Event string

Event defines hook event type

const (
	PolicyManagement                        Event = "iq:policyManagement"
	ApplicationEvaluation                   Event = "iq:applicationEvaluation"
	LicenseOverrideManagement               Event = "iq:licenseOverrideManagement"
	SecurityVulnerabilityOverrideManagement Event = "iq:securityVulnerabilityOverrideManagement"
)

Hook types

type LicenseOverrideManagementPayload

type LicenseOverrideManagementPayload struct {
	//Timestamp time.Time `json:"timestamp"`
	Timestamp       string `json:"timestamp"`
	Initiator       string `json:"initiator"`
	Id              string `json:"id"`
	LicenseOverride struct {
		Id                  string   `json:"id"`
		OwnerId             string   `json:"ownerId"`
		Status              string   `json:"status"`
		Comment             string   `json:"comment"`
		LicenseIds          []string `json:"licenseIds"`
		ComponentIdentifier struct {
			Format      string `json:"format"`
			Coordinates struct {
				ArtifactId string `json:"artifactId"`
				Classifier string `json:"classifier"`
				Extension  string `json:"extension"`
				GroupId    string `json:"groupId"`
				Version    string `json:"version"`
			} `json:"coordinates"`
		} `json:"componentIdentifier"`
	} `json:"licenseOverride"`
}

LicenseOverrideManagementPayload contains the information for Sonatype IQ server License Override Management hook event

type Option

type Option func(*Webhook) error

Option is a configuration option for the webhook

type PolicyManagementPayload

type PolicyManagementPayload struct {
	//Timestamp time.Time `json:"timestamp"`
	Timestamp string `json:"timestamp"`
	Initiator string `json:"initiator"`
	Id        string `json:"id"`
	Owner     struct {
		Id            string `json:"id"`
		PublicId      string `json:"publicId"`
		Name          string `json:"name"`
		ParentOwnerId string `json:"parentOwnerId"`
		Type          string `json:"type"`
		Tags          []struct {
			Id          string `json:"id"`
			Name        string `json:"name"`
			Description string `json:"description"`
			Color       string `json:"color"`
		} `json:"tags,omitempty"`
		Labels []struct {
			Id          string `json:"id"`
			Name        string `json:"name"`
			Description string `json:"description"`
			Color       string `json:"color"`
		} `json:"labes,omitempty"`
		LicenseThreatGroups []struct {
			Id          string `json:"id"`
			Name        string `json:"name"`
			ThreatLevel int64  `json:"threatLevel"`
		} `json:"licenseThreatGroups"`
		Policies []struct {
			Id          string `json:"id"`
			Name        string `json:"name"`
			ThreatLevel int64  `json:"threatLevel"`
		} `json:"policies"`
		Access []struct {
			Id      string `json:"id"`
			Name    string `json:"name"`
			Members []struct {
				Type string `json:"type"`
				Name string `json:"name"`
			} `json:"licenseThreatGroups"`
		} `json:"members"`
	} `json:"owner"`
}

PolicyManagementPayload contains the information for Sonatype IQ server Policy Management hook event

type SecurityVulnerabilityOverrideManagementPayload

type SecurityVulnerabilityOverrideManagementPayload struct {
	//Timestamp time.Time `json:"timestamp"`
	Timestamp                     string `json:"timestamp"`
	Initiator                     string `json:"initiator"`
	Id                            string `json:"id"`
	SecurityVulnerabilityOverride struct {
		Id          string `json:"id"`
		OwnerId     string `json:"ownerId"`
		Hash        string `json:"hash"`
		Source      string `json:"source"`
		ReferenceId string `json:"referenceId"`
		Status      string `json:"status"`
		Comment     string `json:"comment"`
	} `json:"securityVulnerabilityOverride"`
}

SecurityVulnerabilityOverrideManagementPayload contains the information for Sonatype IQ server Security Vulnerability Override Management Event hook event

type SonatypeDate

type SonatypeDate struct {
	time.Time
}

func (*SonatypeDate) UnmarshalJSON

func (sd *SonatypeDate) UnmarshalJSON(input []byte) error

type Webhook

type Webhook struct {
	// contains filtered or unexported fields
}

Webhook instance contains all methods needed to process events

func New

func New(options ...Option) (*Webhook, error)

New creates and returns a WebHook instance denoted by the Provider type

func (Webhook) Parse

func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)

Parse verifies and parses the events specified and returns the payload object or an error

type WebhookOptions

type WebhookOptions struct{}

WebhookOptions is a namespace for configuration option methods

func (WebhookOptions) Secret

func (WebhookOptions) Secret(secret string) Option

Secret registers the Sonatype secret

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL