github

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CIDR

type CIDR string

type Client

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

func NewAuthenticatedGitHubClient

func NewAuthenticatedGitHubClient(ctx context.Context, token string, opts ...ClientOption) *Client

NewAuthenticatedGitHubClient creates a new authenticated client (using Personal Access Token (classic)) with given ClientOptions

func NewGitHubClient

func NewGitHubClient(httpClient *http.Client, opts ...ClientOption) *Client

NewGitHubClient creates a new client with a given http.Client and ClientOptions. This client does not handle authorization nor authentication, instead relies on http.Client implementation.

func (*Client) CreateIPAllowListEntry

func (c *Client) CreateIPAllowListEntry(ctx context.Context, ownerID string, name string, value CIDR, isActive bool) (*IPAllowListEntry, error)

CreateIPAllowListEntry uses createIpAllowListEntry GraphQL mutation to create a new IP allow list entry for a given ownerID (organization or enterprise). Returns the newly created entry.

func (*Client) DeleteIPAllowListEntry

func (c *Client) DeleteIPAllowListEntry(ctx context.Context, entryID string) (string, error)

DeleteIPAllowListEntry uses deleteIpAllowListEntry GraphQL mutation to delete an IP allow list entry with a given entryID. Returns entryID of the deleted entry.

func (*Client) GetEnterpriseID

func (c *Client) GetEnterpriseID(ctx context.Context, enterpriseName string) (string, error)

GetEnterpriseID fetches GitHub GraphQL API node_id for given enterpriseName.

func (*Client) GetEnterpriseIPAllowListEntries

func (c *Client) GetEnterpriseIPAllowListEntries(ctx context.Context, enterpriseName string) ([]*IPAllowListEntry, error)

GetEnterpriseIPAllowListEntries retrieves IP allow list entries for a given enterpriseName.

func (*Client) GetOrganizationID

func (c *Client) GetOrganizationID(ctx context.Context, organizationName string) (string, error)

GetOrganizationID fetches GitHub GraphQL API node_id for given organizationName.

func (*Client) GetOrganizationIPAllowListEntries

func (c *Client) GetOrganizationIPAllowListEntries(ctx context.Context, organizationName string) ([]*IPAllowListEntry, error)

GetOrganizationIPAllowListEntries retrieves IP allow list entries for a given organizationName. Returns a slice of pointers to an entry as the API returns nil for entries managed on an enterprise level.

func (*Client) UpdateIPAllowListEntry

func (c *Client) UpdateIPAllowListEntry(ctx context.Context, entryID string, params IPAllowListEntryParameters) (*IPAllowListEntry, error)

UpdateIPAllowListEntry uses updateIpAllowListEntry GraphQL mutation to set attributes an IP allow list entry with a given entryID to params. Returns the updated entry.

type ClientOption

type ClientOption func(options *ClientOptions)

func WithConcurrency

func WithConcurrency(concurrency int64) ClientOption

WithConcurrency determines maximum number of concurrent requests to the GitHub GraphQL API. Used to control rate limiting. concurrency must be >= 1, otherwise the option is ignored.

func WithEntriesCaching

func WithEntriesCaching() ClientOption

WithEntriesCaching enables an entries cache. It reduces number of calls to GitHub's GraphQL API reducing rate limiting pressure.

func WithGraphQLAPIURL

func WithGraphQLAPIURL(graphQLAPIURL string) ClientOption

WithGraphQLAPIURL sets GitHub's base GraphQL API URL.

func WithHeaders

func WithHeaders(headers map[string]string) ClientOption

WithHeaders adds additional HTTP headers

func WithoutEntriesCaching

func WithoutEntriesCaching() ClientOption

WithoutEntriesCaching disables an entries cache. Without caching client will perform multiple calls to GitHub's GraphQL API for each entry listing function call like GetOrganizationIPAllowListEntries. Also, it might put pressure on yours GitHub rate limit.

type ClientOptions

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

type CreateIPAllowListEntryMutationResponse

type CreateIPAllowListEntryMutationResponse struct {
	CreateIPAllowListEntry struct {
		IPAllowListEntry IPAllowListEntry `json:"ipAllowListEntry"`
	} `json:"createIpAllowListEntry"`
}

type DeleteUpAllowListEntryMutationResponse

type DeleteUpAllowListEntryMutationResponse struct {
	DeleteIPAllowListEntry struct {
		IPAllowListEntry struct {
			ID string `json:"id"`
		} `json:"ipAllowListEntry"`
	} `json:"deleteIpAllowListEntry"`
}

type Error

type Error struct {
	Message   string `json:"message"`
	Locations []struct {
		Line   int `json:"line"`
		Column int `json:"column"`
	} `json:"locations"`
	Path []string `json:"path"`
}

type ErrorWithStatusCode

type ErrorWithStatusCode struct {
	StatusCode int
	// contains filtered or unexported fields
}

func (ErrorWithStatusCode) Error

func (e ErrorWithStatusCode) Error() string

type GetEnterpriseIDQueryResponse

type GetEnterpriseIDQueryResponse struct {
	Enterprise struct {
		ID string `json:"id"`
	} `json:"enterprise"`
}

type GetEnterpriseIPAllowListQueryResponse

type GetEnterpriseIPAllowListQueryResponse struct {
	Enterprise struct {
		OwnerInfo struct {
			IPAllowListEntries struct {
				Nodes    []*IPAllowListEntry `json:"nodes"`
				PageInfo PageInfo            `json:"pageInfo"`
			} `json:"ipAllowListEntries"`
		} `json:"ownerInfo"`
	} `json:"enterprise"`
}

type GetOrganizationIDQueryResponse

type GetOrganizationIDQueryResponse struct {
	Organization struct {
		ID string `json:"id"`
	} `json:"organization"`
}

type GetOrganizationIPAllowListQueryResponse

type GetOrganizationIPAllowListQueryResponse struct {
	Organization struct {
		IPAllowListEntries struct {
			Nodes    []*IPAllowListEntry `json:"nodes"`
			PageInfo PageInfo            `json:"pageInfo"`
		} `json:"ipAllowListEntries"`
	} `json:"organization"`
}

type GraphQLRequest

type GraphQLRequest struct {
	Query     string    `json:"query"`
	Variables Variables `json:"variables"`
}

type GraphQLResponse

type GraphQLResponse struct {
	Data   json.RawMessage `json:"data"`
	Errors []Error         `json:"errors"`
}

type IPAllowListEntry

type IPAllowListEntry struct {
	ID             string    `json:"id"`
	AllowListValue CIDR      `json:"allowListValue"`
	Name           string    `json:"name"`
	IsActive       bool      `json:"isActive"`
	CreatedAt      time.Time `json:"createdAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
}

type IPAllowListEntryParameters

type IPAllowListEntryParameters struct {
	Name     string
	Value    CIDR
	IsActive bool
}

type PageInfo

type PageInfo struct {
	HasNextPage bool   `json:"hasNextPage"`
	EndCursor   string `json:"endCursor"`
}

type UpdateIPAllowListEntryMutationResponse

type UpdateIPAllowListEntryMutationResponse struct {
	UpdateIPAllowListEntry struct {
		IPAllowListEntry IPAllowListEntry `json:"ipAllowListEntry"`
	} `json:"updateIpAllowListEntry"`
}

type Variables

type Variables map[string]any

Jump to

Keyboard shortcuts

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