jira

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unresolved       = ResolutionTag("")
	ResolvedApproved = ResolutionTag("approved")
	ResolvedDenied   = ResolutionTag("denied")
	ResolvedExpired  = ResolutionTag("expired")
	ResolvedPromoted = ResolutionTag("promoted")
)
View Source
const (
	DefaultDir = "/var/lib/teleport/plugins/jira"
)
View Source
const (
	RequestIDPropertyKey = "teleportAccessRequestId"
)

Variables

This section is empty.

Functions

func EncodePluginData

func EncodePluginData(data PluginData) map[string]string

EncodePluginData serializes a PluginData struct into a string map.

func GetRequestID

func GetRequestID(issue Issue) (string, error)

GetRequestID extracts a request id from issue properties.

Types

type App

type App struct {
	*lib.Process
	// contains filtered or unexported fields
}

App contains global application state.

func NewApp

func NewApp(conf Config) (*App, error)

func (*App) Err

func (a *App) Err() error

Err returns the error app finished with.

func (*App) PublicURL

func (a *App) PublicURL() *url.URL

PublicURL returns a webhook base URL.

func (*App) Run

func (a *App) Run(ctx context.Context) error

Run initializes and runs a watcher and a callback server

func (*App) WaitReady

func (a *App) WaitReady(ctx context.Context) (bool, error)

WaitReady waits for http and watcher service to start up.

type ChangeDetails

type ChangeDetails struct {
	Field      string `json:"field"`
	FieldType  string `json:"fieldtype"`
	FieldID    string `json:"fieldId"`
	From       string `json:"from"`
	FromString string `json:"fromString"`
	To         string `json:"to"`
	ToString   string `json:"toString"`
}

type Changelog

type Changelog struct {
	ID      string          `json:"id"`
	Author  UserDetails     `json:"author"`
	Created string          `json:"created"`
	Items   []ChangeDetails `json:"items"`
}

type Comment

type Comment struct {
	Self    string      `json:"self"`
	ID      string      `json:"id"`
	Author  UserDetails `json:"author"`
	Body    string      `json:"body"`
	Created string      `json:"created"`
}

type CommentInput

type CommentInput struct {
	Body       string           `json:"body,omitempty"`
	Properties []EntityProperty `json:"properties,omitempty"`
}

type Config

type Config struct {
	Teleport lib.TeleportConfig `toml:"teleport"`
	Jira     JiraConfig         `toml:"jira"`
	HTTP     lib.HTTPConfig     `toml:"http"`
	Log      logger.Config      `toml:"log"`

	// Teleport is a handle to the client to use when communicating with
	// the Teleport auth server. The Jira app will create a gRPC-based
	// client on startup if this is not set.
	Client teleport.Client

	// StatusSink receives any status updates from the plugin for
	// further processing. Status updates will be ignored if not set.
	StatusSink common.StatusSink

	// DisableWebhook flags that the plugin should *not* run a
	// webhook server to receive notifications back from the Jira
	// serve. The default behavior is to run one.
	DisableWebhook bool
}

func (*Config) CheckAndSetDefaults

func (c *Config) CheckAndSetDefaults() error

func (*Config) LoadTLSConfig

func (c *Config) LoadTLSConfig() (*tls.Config, error)

LoadTLSConfig loads client crt/key files and root authorities, and generates a tls.Config suitable for use with a gRPC client.

type CreatedIssue

type CreatedIssue struct {
	ID   string `json:"id"`
	Key  string `json:"key"`
	Self string `json:"self"`
}

type EntityProperty

type EntityProperty struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type ErrorResult

type ErrorResult struct {
	ErrorMessages []string `url:"errorMessages"`
	Errors        []string `url:"errors"`
}

type GetIssueCommentQueryOptions

type GetIssueCommentQueryOptions struct {
	StartAt    int      `url:"startAt,omitempty"`
	MaxResults int      `url:"maxResults,omitempty"`
	OrderBy    string   `url:"orderBy,omitempty"`
	Expand     []string `url:"expand,comma,omitempty"`
}

type GetIssueQueryOptions

type GetIssueQueryOptions struct {
	Fields     []string `url:"fields,comma,omitempty"`
	Expand     []string `url:"expand,comma,omitempty"`
	Properties []string `url:"properties,comma,omitempty"`
}

type GetMyPermissionsQueryOptions

type GetMyPermissionsQueryOptions struct {
	ProjectKey  string   `url:"projectKey,omitempty"`
	Permissions []string `url:"permissions,comma,omitempty"`
}

type Issue

type Issue struct {
	Expand      string                 `json:"expand"`
	Self        string                 `json:"self"`
	ID          string                 `json:"id"`
	Key         string                 `json:"key"`
	Fields      IssueFields            `json:"fields"`
	Changelog   PageOfChangelogs       `json:"changelog"`
	Properties  map[string]interface{} `json:"properties"`
	Transitions []IssueTransition      `json:"transitions"`
}

type IssueFields

type IssueFields struct {
	Status      StatusDetails  `json:"status"`
	Comment     PageOfComments `json:"comment"`
	Project     Project        `json:"project"`
	Type        IssueType      `json:"issuetype"`
	Summary     string         `json:"summary,omitempty"`
	Description string         `json:"description,omitempty"`
}

type IssueFieldsInput

type IssueFieldsInput struct {
	Type        *IssueType `json:"issuetype,omitempty"`
	Project     *Project   `json:"project,omitempty"`
	Summary     string     `json:"summary,omitempty"`
	Description string     `json:"description,omitempty"`
}

type IssueInput

type IssueInput struct {
	Fields     IssueFieldsInput `json:"fields,omitempty"`
	Properties []EntityProperty `json:"properties,omitempty"`
}

type IssueTransition

type IssueTransition struct {
	ID   string        `json:"id,omitempty"`
	Name string        `json:"name,omitempty"`
	To   StatusDetails `json:"to,omitempty"`
}

func GetTransition

func GetTransition(issue Issue, status string) (IssueTransition, error)

GetTransition returns an issue transition by a status name.

type IssueTransitionInput

type IssueTransitionInput struct {
	Transition IssueTransition `json:"transition"`
}

type IssueType

type IssueType struct {
	Self        string `json:"self,omitempty"`
	ID          string `json:"id,omitempty"`
	Description string `json:"description,omitempty"`
	IconURL     string `json:"iconUrl,omitempty"`
	Name        string `json:"name,omitempty"`
}

type IssueUpdate

type IssueUpdate struct {
	Status string
	Author UserDetails
}

IssueUpdate is an info of who updated the issue status.

func GetLastUpdate

func GetLastUpdate(issue Issue, status string) (IssueUpdate, error)

GetLastUpdate returns a last issue update by a status name.

type Jira

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

Jira is a wrapper around resty.Client.

func NewJiraClient

func NewJiraClient(conf JiraConfig, clusterName, teleportProxyAddr string, statusSink common.StatusSink) (*Jira, error)

NewJiraClient builds a new Jira client.

func (*Jira) AddIssueReviewComment

func (j *Jira) AddIssueReviewComment(ctx context.Context, id string, review types.AccessReview) error

AddIssueReviewComment posts an issue comment about access review added to a request.

func (*Jira) AddResolutionComment

func (j *Jira) AddResolutionComment(ctx context.Context, id string, resolution Resolution) error

AddResolutionComment posts an issue comment about request resolution.

func (*Jira) CreateIssue

func (j *Jira) CreateIssue(ctx context.Context, reqID string, reqData RequestData) (JiraData, error)

CreateIssue creates an issue with "Pending" status

func (*Jira) GetIssue

func (j *Jira) GetIssue(ctx context.Context, id string) (Issue, error)

GetIssue loads the issue with all necessary nested data.

func (*Jira) HealthCheck

func (j *Jira) HealthCheck(ctx context.Context) error

HealthCheck checks Jira endpoint for validity and also checks the project permissions.

func (*Jira) RangeIssueCommentsDescending

func (j *Jira) RangeIssueCommentsDescending(ctx context.Context, id string, fn func(PageOfComments) bool) error

RangeIssueCommentsDescending iterates over pages of comments of an issue.

func (*Jira) ResolveIssue

func (j *Jira) ResolveIssue(ctx context.Context, issueID string, resolution Resolution) error

ResolveIssue sets a final status e.g. "approved", "denied" or "expired" to the issue and posts the comment.

func (*Jira) TransitionIssue

func (j *Jira) TransitionIssue(ctx context.Context, issueID, transitionID string) error

TransitionIssue moves an issue by transition ID.

type JiraConfig

type JiraConfig struct {
	URL       string `toml:"url"`
	Username  string `toml:"username"`
	APIToken  string `toml:"api_token"`
	Project   string `toml:"project"`
	IssueType string `toml:"issue_type"`
}

func (*JiraConfig) CheckAndSetDefaults

func (c *JiraConfig) CheckAndSetDefaults() error

type JiraData

type JiraData struct {
	IssueID  string
	IssueKey string
}

type PageOfChangelogs

type PageOfChangelogs struct {
	StartAt    int         `json:"startAt"`
	MaxResults int         `json:"maxResults"`
	Total      int         `json:"total"`
	Histories  []Changelog `json:"histories"`
}

type PageOfComments

type PageOfComments struct {
	StartAt    int       `json:"startAt"`
	MaxResults int       `json:"maxResults"`
	Total      int       `json:"total"`
	Comments   []Comment `json:"comments"`
}

type Permission

type Permission struct {
	ID             string `json:"id"`
	Key            string `json:"key"`
	Name           string `json:"name"`
	Type           string `json:"type"`
	Description    string `json:"description"`
	HavePermission bool   `json:"havePermission"`
}

type Permissions

type Permissions struct {
	Permissions map[string]Permission `json:"permissions"`
}

type PluginData

type PluginData struct {
	RequestData
	JiraData
}

PluginData is a data associated with access request that we store in Teleport using UpdatePluginData API.

func DecodePluginData

func DecodePluginData(dataMap map[string]string) (data PluginData)

DecodePluginData deserializes a string map to PluginData struct.

type Project

type Project struct {
	Expand      string `json:"expand,omitempty"`
	Self        string `json:"self,omitempty"`
	ID          string `json:"id,omitempty"`
	Key         string `json:"key,omitempty"`
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
	Email       string `json:"email,omitempty"`
	Name        string `json:"name,omitempty"`
}

type RequestData

type RequestData struct {
	User          string
	Roles         []string
	Created       time.Time
	RequestReason string
	ReviewsCount  int
	Resolution    Resolution
}

type Resolution

type Resolution struct {
	Tag    ResolutionTag
	Reason string
}

type ResolutionTag

type ResolutionTag string

type StatusDetails

type StatusDetails struct {
	Self        string `json:"self"`
	Description string `json:"description"`
	IconURL     string `json:"iconUrl"`
	Name        string `json:"name"`
	ID          string `json:"id"`
}

type UserDetails

type UserDetails struct {
	Self         string `json:"self"`
	AccountID    string `json:"accountId"`
	EmailAddress string `json:"emailAddress"`
	DisplayName  string `json:"displayName"`
	Active       bool   `json:"active"`
	TimeZone     string `json:"timeZone"`
	AccountType  string `json:"accountType"`
}

type Webhook

type Webhook struct {
	Timestamp          int    `json:"timestamp"`
	WebhookEvent       string `json:"webhookEvent"`
	IssueEventTypeName string `json:"issue_event_type_name"`
	User               *struct {
		Self        string `json:"self"`
		AccountID   string `json:"accountId"`
		AccountType string `json:"accountType"`
		DisplayName string `json:"displayName"`
		Active      bool   `json:"active"`
	} `json:"user"`
	Issue *WebhookIssue `json:"issue"`
}

type WebhookFunc

type WebhookFunc func(ctx context.Context, webhook Webhook) error

type WebhookIssue

type WebhookIssue struct {
	ID     string      `json:"id"`
	Self   string      `json:"self"`
	Key    string      `json:"key"`
	Fields IssueFields `json:"fields"`
}

type WebhookServer

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

WebhookServer is a wrapper around http.Server that processes Jira webhook events. It verifies incoming requests and calls onWebhook for valid ones

func NewWebhookServer

func NewWebhookServer(conf lib.HTTPConfig, onWebhook WebhookFunc) (*WebhookServer, error)

func (*WebhookServer) BaseURL

func (s *WebhookServer) BaseURL() *url.URL

func (*WebhookServer) EnsureCert

func (s *WebhookServer) EnsureCert() error

func (*WebhookServer) ServiceJob

func (s *WebhookServer) ServiceJob() lib.ServiceJob

Jump to

Keyboard shortcuts

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