codehub

package
Version: v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BasicDateFormat     = "20060102T150405Z"
	Algorithm           = "SDK-HMAC-SHA256"
	HeaderXDate         = "X-Sdk-Date"
	HeaderHost          = "host"
	HeaderAuthorization = "Authorization"
	HeaderContentSha256 = "X-Sdk-Content-Sha256"
)
View Source
const (
	PushEvents             = "push_events"
	PullRequestEvent       = "merge_requests_events"
	BranchOrTagCreateEvent = "tag_push_events"
)

Variables

This section is empty.

Functions

func AuthHeaderValue

func AuthHeaderValue(signature, accessKey string, signedHeaders []string) string

Get the finalized value for the "Authorization" header. The signature parameter is the output from SignStringToSign

func CanonicalHeaders

func CanonicalHeaders(r *http.Request, signerHeaders []string) string

CanonicalHeaders

func CanonicalQueryString

func CanonicalQueryString(r *http.Request) string

CanonicalQueryString

func CanonicalRequest

func CanonicalRequest(r *http.Request, signedHeaders []string) (string, error)

Build a CanonicalRequest from a regular request string

CanonicalRequest =

HTTPRequestMethod + '\n' +
CanonicalURI + '\n' +
CanonicalQueryString + '\n' +
CanonicalHeaders + '\n' +
SignedHeaders + '\n' +
HexEncode(Hash(RequestPayload))

func CanonicalURI

func CanonicalURI(r *http.Request) string

CanonicalURI returns request uri

func HexEncodeSHA256Hash

func HexEncodeSHA256Hash(body []byte) (string, error)

HexEncodeSHA256Hash returns hexcode of sha256

func ParseHook

func ParseHook(eventType EventType, payload []byte) (event interface{}, err error)

func RequestPayload

func RequestPayload(r *http.Request) ([]byte, error)

RequestPayload

func SignStringToSign

func SignStringToSign(stringToSign string, signingKey []byte) (string, error)

Create the HWS Signature.

func SignedHeaders

func SignedHeaders(r *http.Request) []string

SignedHeaders

func StringToSign

func StringToSign(canonicalRequest string, t time.Time) (string, error)

Create a "String to Sign".

Types

type AddCodehubHookPayload

type AddCodehubHookPayload struct {
	HookURL    string   `json:"hook_url"`
	Service    string   `json:"service"`
	Token      string   `json:"token"`
	HookEvents []string `json:"hook_events"`
}

type AddCodehubHookResp

type AddCodehubHookResp struct {
	Result CodehubHook `json:"result"`
	Status string      `json:"status"`
}

type Author

type Author struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

type Branch

type Branch struct {
	Commit    *Commit `json:"commit"`
	Name      string  `json:"name"`
	Protected bool    `json:"protected"`
	Merged    bool    `json:"merged"`
}

type BranchList

type BranchList struct {
	Result struct {
		Total    int        `json:"total"`
		Branches []Branches `json:"branches"`
	} `json:"result"`
	Status string `json:"status"`
}

type Branches

type Branches struct {
	Commit             Commit `json:"commit"`
	Name               string `json:"name"`
	Protected          bool   `json:"protected"`
	DevelopersCanPush  bool   `json:"developers_can_push"`
	DevelopersCanMerge bool   `json:"developers_can_merge"`
	MasterCanPush      bool   `json:"master_can_push"`
	MasterCanMerge     bool   `json:"master_can_merge"`
	NoOneCanPush       bool   `json:"no_one_can_push"`
	NoOneCanMerge      bool   `json:"no_one_can_merge"`
}

type CodeHubClient

type CodeHubClient struct {
	AK     string `json:"ak"`
	SK     string `json:"sk"`
	Region string `json:"region"`
}

func NewCodeHubClient

func NewCodeHubClient(ak, sk, region string) *CodeHubClient

func (*CodeHubClient) AddWebhook

func (c *CodeHubClient) AddWebhook(repoOwner, repoName string, codehubHookPayload *AddCodehubHookPayload) (string, error)

func (*CodeHubClient) BranchList

func (c *CodeHubClient) BranchList(repoUUID string) ([]*Branch, error)

func (*CodeHubClient) DeleteCodehubWebhook

func (c *CodeHubClient) DeleteCodehubWebhook(repoOwner, repoName, hookID string) error

func (*CodeHubClient) FileContent

func (c *CodeHubClient) FileContent(repoUUID, branchName, path string) (*FileContent, error)

func (*CodeHubClient) FileTree

func (c *CodeHubClient) FileTree(repoUUID, branchName, path string) ([]*TreeNode, error)

func (*CodeHubClient) GetLatestRepositoryCommit

func (c *CodeHubClient) GetLatestRepositoryCommit(repoOwner, repoName, branchName string) (*Commit, error)

func (*CodeHubClient) GetRepoUUID

func (c *CodeHubClient) GetRepoUUID(repoName string) (string, error)

func (*CodeHubClient) GetYAMLContents

func (c *CodeHubClient) GetYAMLContents(repoUUID, branchName, path string, isDir, split bool) ([]string, error)

func (*CodeHubClient) ListCodehubWebhooks

func (c *CodeHubClient) ListCodehubWebhooks(repoOwner, repoName, hookID string) ([]CodehubHook, error)

func (*CodeHubClient) NamespaceList

func (c *CodeHubClient) NamespaceList() ([]*Namespace, error)

func (*CodeHubClient) RepoList

func (c *CodeHubClient) RepoList(projectUUID, search string, pageSize int) ([]*Project, error)

func (*CodeHubClient) TagList

func (c *CodeHubClient) TagList(repoID string) ([]*Tag, error)

type CodehubHook

type CodehubHook struct {
	ID                     int    `json:"id"`
	ProjectID              int    `json:"project_id"`
	CreatedAt              string `json:"created_at"`
	EnableSslVerification  bool   `json:"enable_ssl_verification"`
	PushEvents             bool   `json:"push_events"`
	TagPushEvents          bool   `json:"tag_push_events"`
	RepositoryUpdateEvents bool   `json:"repository_update_events"`
	MergeRequestsEvents    bool   `json:"merge_requests_events"`
	IssuesEvents           bool   `json:"issues_events"`
	NoteEvents             bool   `json:"note_events"`
	PipelineEvents         bool   `json:"pipeline_events"`
	WikiPageEvents         bool   `json:"wiki_page_events"`
}

type Commit

type Commit struct {
	ID            string `json:"id"`
	Message       string `json:"message"`
	AuthorName    string `json:"author_name"`
	CommittedDate string `json:"committed_date"`
	CommitterName string `json:"committer_name"`
}

type CommitListResp

type CommitListResp struct {
	Result CommitListResult `json:"result"`
	Status string           `json:"status"`
}

type CommitListResult

type CommitListResult struct {
	Total   int      `json:"total"`
	Commits []Commit `json:"commits"`
}

type DeleteCodehubWebhookResp

type DeleteCodehubWebhookResp struct {
	Result string `json:"result"`
	Status string `json:"status"`
}

type EventType

type EventType string

EventType represents a Codehub event type.

const (
	EventTypeMergeRequest EventType = "Merge Request Hook"
	EventTypePush         EventType = "Push Hook"
	EventTypeTagPush      EventType = "Tag Push Hook"
)

List of available event types.

func HookEventType

func HookEventType(r *http.Request) EventType

HookEventType returns the event type for the given request.

type FileContent

type FileContent struct {
	FileName string `json:"file_name"`
	FilePath string `json:"file_path"`
	Content  string `json:"content"`
}

type FileContentResp

type FileContentResp struct {
	Result FileContentResult `json:"result"`
	Status string            `json:"status"`
}

type FileContentResult

type FileContentResult struct {
	FileName string `json:"file_name"`
	FilePath string `json:"file_path"`
	Size     string `json:"size"`
	Encoding string `json:"encoding"`
	Ref      string `json:"ref"`
	BlobID   string `json:"blob_id"`
	FileType string `json:"file_type"`
	Content  string `json:"content"`
}

type FileTree

type FileTree struct {
	Result FileTreeResult `json:"result"`
	Status string         `json:"status"`
}

type FileTreeResult

type FileTreeResult struct {
	Trees []Trees `json:"trees"`
	Total int     `json:"total"`
}

type GetCodehubHookResp

type GetCodehubHookResp struct {
	Result GetCodehubHookResult `json:"result"`
	Status string               `json:"status"`
}

type GetCodehubHookResult

type GetCodehubHookResult struct {
	Hooks []CodehubHook `json:"hooks"`
}

type LastCommit

type LastCommit struct {
	ID        string    `json:"id"`
	Message   string    `json:"message"`
	Timestamp time.Time `json:"timestamp"`
	URL       string    `json:"url"`
	Author    Author    `json:"author"`
}

type MergeEvent

type MergeEvent struct {
	ObjectKind       string           `json:"object_kind"`
	EventType        string           `json:"event_type"`
	User             User             `json:"user"`
	Project          WebhookProject   `json:"project"`
	ObjectAttributes ObjectAttributes `json:"object_attributes"`
	Labels           []interface{}    `json:"labels"`
}

type MergeParams

type MergeParams struct {
	ForceRemoveSourceBranch bool `json:"force_remove_source_branch"`
}

type Namespace

type Namespace struct {
	Name        string `json:"name"`
	Path        string `json:"path"`
	Kind        string `json:"kind"`
	ProjectUUID string `json:"project_uuid,omitempty"`
	RepoUUID    string `json:"repo_uuid,omitempty"`
	RepoName    string `json:"repo_name,omitempty"`
}

type ObjectAttributes

type ObjectAttributes struct {
	AssigneeID                interface{} `json:"assignee_id"`
	AuthorID                  int         `json:"author_id"`
	CreatedAt                 string      `json:"created_at"`
	Description               string      `json:"description"`
	HeadPipelineID            interface{} `json:"head_pipeline_id"`
	ID                        int         `json:"id"`
	IID                       int         `json:"iid"`
	LastEditedAt              interface{} `json:"last_edited_at"`
	LastEditedByID            interface{} `json:"last_edited_by_id"`
	MergeCommitSha            interface{} `json:"merge_commit_sha"`
	MergeError                interface{} `json:"merge_error"`
	MergeParams               MergeParams `json:"merge_params"`
	MergeStatus               string      `json:"merge_status"`
	MergeUserID               interface{} `json:"merge_user_id"`
	MergeWhenPipelineSucceeds bool        `json:"merge_when_pipeline_succeeds"`
	MilestoneID               interface{} `json:"milestone_id"`
	SourceBranch              string      `json:"source_branch"`
	SourceProjectID           int         `json:"source_project_id"`
	State                     string      `json:"state"`
	TargetBranch              string      `json:"target_branch"`
	TargetProjectID           int         `json:"target_project_id"`
	TimeEstimate              int         `json:"time_estimate"`
	Title                     string      `json:"title"`
	UpdatedAt                 string      `json:"updated_at"`
	UpdatedByID               interface{} `json:"updated_by_id"`
	URL                       string      `json:"url"`
	Source                    Source      `json:"source"`
	Target                    Target      `json:"target"`
	LastCommit                LastCommit  `json:"last_commit"`
	WorkInProgress            bool        `json:"work_in_progress"`
	TotalTimeSpent            int         `json:"total_time_spent"`
	HumanTotalTimeSpent       interface{} `json:"human_total_time_spent"`
	HumanTimeEstimate         interface{} `json:"human_time_estimate"`
	Action                    string      `json:"action"`
}

type Project

type Project struct {
	ID            int    `json:"id"`
	Name          string `json:"name"`
	Description   string `json:"description"`
	DefaultBranch string `json:"defaultBranch"`
	Namespace     string `json:"namespace"`
	RepoUUID      string `json:"repo_uuid"`
	RepoID        string `json:"repo_id"`
}

type PushEvent

type PushEvent struct {
	ObjectKind        string            `json:"object_kind"`
	EventName         string            `json:"event_name"`
	Before            string            `json:"before"`
	After             string            `json:"after"`
	Ref               string            `json:"ref"`
	CheckoutSha       string            `json:"checkout_sha"`
	Message           interface{}       `json:"message"`
	UserID            int               `json:"user_id"`
	UserName          string            `json:"user_name"`
	UserUsername      string            `json:"user_username"`
	UserEmail         string            `json:"user_email"`
	UserAvatar        string            `json:"user_avatar"`
	ProjectID         int               `json:"project_id"`
	Project           WebhookProject    `json:"project"`
	Commits           []PushEventCommit `json:"commits"`
	TotalCommitsCount int               `json:"total_commits_count"`
}

type PushEventCommit

type PushEventCommit struct {
	ID        string    `json:"id"`
	Message   string    `json:"message"`
	Timestamp time.Time `json:"timestamp"`
	URL       string    `json:"url"`
	Author    Author    `json:"author"`
	Added     []string  `json:"added"`
	Modified  []string  `json:"modified"`
	Removed   []string  `json:"removed"`
}

type RepoInfo

type RepoInfo struct {
	Result RepoInfoResult `json:"result"`
	Status string         `json:"status"`
}

type RepoInfoResult

type RepoInfoResult struct {
	Total       int           `json:"total"`
	Repositorys []Repositorys `json:"repositorys"`
}

type RepoListInfo

type RepoListInfo struct {
	Result RepoListInfoResult `json:"result"`
	Status string             `json:"status"`
}

type RepoListInfoResult

type RepoListInfoResult struct {
	Total        int            `json:"total"`
	Repositories []Repositories `json:"repositories"`
}

type Repositories

type Repositories struct {
	Star             bool        `json:"star"`
	Status           int         `json:"status"`
	UserRole         interface{} `json:"userRole"`
	RepositoryUUID   string      `json:"repository_uuid"`
	RepositoryID     int         `json:"repository_id"`
	RepositoryName   string      `json:"repository_name"`
	SSHURL           string      `json:"ssh_url"`
	HTTPSURL         string      `json:"https_url"`
	GroupName        string      `json:"group_name"`
	WebURL           string      `json:"web_url"`
	VisibilityLevel  int         `json:"visibility_level"`
	CreatedAt        string      `json:"created_at"`
	UpdatedAt        string      `json:"updated_at"`
	RepositorySize   string      `json:"repository_size"`
	LfsSize          string      `json:"lfs_size"`
	CreatorName      string      `json:"creator_name"`
	DomainName       string      `json:"domain_name"`
	IsOwner          int         `json:"is_owner"`
	IamUserUUID      string      `json:"iam_user_uuid"`
	ProjectUUID      string      `json:"project_uuid"`
	ProjectIsDeleted string      `json:"project_is_deleted"`
}

type Repositorys

type Repositorys struct {
	ID              string `json:"id"`
	RepoID          string `json:"repoId"`
	Name            string `json:"name"`
	SSHURL          string `json:"sshUrl"`
	HTTPURL         string `json:"httpUrl"`
	GroupName       string `json:"groupName"`
	WebURL          string `json:"webUrl"`
	VisibilityLevel int    `json:"visibilityLevel"`
	CreateAt        string `json:"createAt"`
	ProjectID       string `json:"projectId"`
	ProjectIsDelete string `json:"projectIsDelete"`
}

type Signer

type Signer struct {
	AK string `json:"ak"`
	SK string `json:"sk"`
}

Signature HWS meta

func (*Signer) Sign

func (s *Signer) Sign(r *http.Request) error

SignRequest set Authorization header

type Source

type Source struct {
	ID                int         `json:"id"`
	Name              string      `json:"name"`
	Description       string      `json:"description"`
	WebURL            string      `json:"web_url"`
	AvatarURL         interface{} `json:"avatar_url"`
	GitSSHURL         string      `json:"git_ssh_url"`
	GitHTTPURL        string      `json:"git_http_url"`
	Namespace         string      `json:"namespace"`
	VisibilityLevel   int         `json:"visibility_level"`
	PathWithNamespace string      `json:"path_with_namespace"`
	DefaultBranch     string      `json:"default_branch"`
	CiConfigPath      interface{} `json:"ci_config_path"`
	Homepage          string      `json:"homepage"`
	URL               string      `json:"url"`
	SSHURL            string      `json:"ssh_url"`
	HTTPURL           string      `json:"http_url"`
}

type Tag

type Tag struct {
	Name       string `json:"name"`
	ZipballURL string `json:"zipball_url"`
	TarballURL string `json:"tarball_url"`
	Message    string `json:"message"`
}

type TagList

type TagList struct {
	Result TagListResult `json:"result"`
	Status string        `json:"status"`
}

type TagListResult

type TagListResult struct {
	Total int    `json:"total"`
	Tags  []Tags `json:"tags"`
}

type Tags

type Tags struct {
	Name         string `json:"name"`
	IsDoubleName bool   `json:"is_double_name"`
}

type Target

type Target struct {
	ID                int         `json:"id"`
	Name              string      `json:"name"`
	Description       string      `json:"description"`
	WebURL            string      `json:"web_url"`
	AvatarURL         interface{} `json:"avatar_url"`
	GitSSHURL         string      `json:"git_ssh_url"`
	GitHTTPURL        string      `json:"git_http_url"`
	Namespace         string      `json:"namespace"`
	VisibilityLevel   int         `json:"visibility_level"`
	PathWithNamespace string      `json:"path_with_namespace"`
	DefaultBranch     string      `json:"default_branch"`
	CiConfigPath      interface{} `json:"ci_config_path"`
	Homepage          string      `json:"homepage"`
	URL               string      `json:"url"`
	SSHURL            string      `json:"ssh_url"`
	HTTPURL           string      `json:"http_url"`
}

type TreeNode

type TreeNode struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Type string `json:"type"`
	Path string `json:"path"`
}

type Trees

type Trees struct {
	BlobID   string `json:"blob_id"`
	Commit   Commit `json:"commit"`
	FileName string `json:"file_name"`
	FilePath string `json:"file_path"`
	Type     string `json:"type"`
}

type User

type User struct {
	Name      string `json:"name"`
	Username  string `json:"username"`
	AvatarURL string `json:"avatar_url"`
}

type WebhookProject

type WebhookProject struct {
	ID                int         `json:"id"`
	Name              string      `json:"name"`
	Description       string      `json:"description"`
	WebURL            string      `json:"web_url"`
	AvatarURL         interface{} `json:"avatar_url"`
	GitSSHURL         string      `json:"git_ssh_url"`
	GitHTTPURL        string      `json:"git_http_url"`
	Namespace         string      `json:"namespace"`
	VisibilityLevel   int         `json:"visibility_level"`
	PathWithNamespace string      `json:"path_with_namespace"`
	DefaultBranch     string      `json:"default_branch"`
	CiConfigPath      interface{} `json:"ci_config_path"`
	Homepage          string      `json:"homepage"`
	URL               string      `json:"url"`
	SSHURL            string      `json:"ssh_url"`
	HTTPURL           string      `json:"http_url"`
}

Jump to

Keyboard shortcuts

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