2019-02-21 15:06:34 +00:00
|
|
|
// Copyright 2019 Sorint.lab
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package gitsource
|
|
|
|
|
|
|
|
import (
|
2019-05-13 12:21:41 +00:00
|
|
|
"errors"
|
2019-02-21 15:06:34 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/sorintlab/agola/internal/services/types"
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CommitStatus string
|
|
|
|
|
|
|
|
const (
|
|
|
|
CommitStatusPending CommitStatus = "pending"
|
|
|
|
CommitStatusSuccess CommitStatus = "success"
|
2019-05-15 09:26:50 +00:00
|
|
|
CommitStatusError CommitStatus = "error"
|
2019-02-21 15:06:34 +00:00
|
|
|
CommitStatusFailed CommitStatus = "failed"
|
|
|
|
)
|
|
|
|
|
2019-05-13 12:21:41 +00:00
|
|
|
var ErrUnauthorized = errors.New("unauthorized")
|
|
|
|
|
2019-02-21 15:06:34 +00:00
|
|
|
type GitSource interface {
|
2019-04-03 13:01:21 +00:00
|
|
|
GetRepoInfo(repopath string) (*RepoInfo, error)
|
|
|
|
GetFile(repopath, commit, file string) ([]byte, error)
|
|
|
|
DeleteDeployKey(repopath, title string) error
|
|
|
|
CreateDeployKey(repopath, title, pubKey string, readonly bool) error
|
|
|
|
UpdateDeployKey(repopath, title, pubKey string, readonly bool) error
|
|
|
|
DeleteRepoWebhook(repopath, url string) error
|
|
|
|
CreateRepoWebhook(repopath, url, secret string) error
|
2019-05-07 16:29:31 +00:00
|
|
|
ParseWebhook(r *http.Request, secret string) (*types.WebhookData, error)
|
2019-04-29 15:35:07 +00:00
|
|
|
CreateCommitStatus(repopath, commitSHA string, status CommitStatus, targetURL, description, context string) error
|
2019-05-23 14:58:20 +00:00
|
|
|
// ListUserRepos report repos where the user has the permission to create deploy keys and webhooks
|
2019-04-29 15:36:29 +00:00
|
|
|
ListUserRepos() ([]*RepoInfo, error)
|
2019-02-21 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type UserSource interface {
|
|
|
|
GetUserInfo() (*UserInfo, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type PasswordSource interface {
|
|
|
|
UserSource
|
2019-04-30 10:13:12 +00:00
|
|
|
LoginPassword(username, password, tokenName string) (string, error)
|
2019-02-21 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Oauth2Source interface {
|
|
|
|
UserSource
|
2019-04-29 13:39:59 +00:00
|
|
|
// GetOauth2AuthorizationURL return the authorization request URL to the
|
2019-02-21 15:06:34 +00:00
|
|
|
// authorization server
|
|
|
|
GetOauth2AuthorizationURL(callbackURL, state string) (redirectURL string, err error)
|
2019-04-29 13:39:59 +00:00
|
|
|
// RequestOauth2Token requests the oauth2 token to the authorization server
|
2019-02-21 15:06:34 +00:00
|
|
|
RequestOauth2Token(callbackURL, code string) (*oauth2.Token, error)
|
2019-04-29 13:39:59 +00:00
|
|
|
// RefreshOauth2Token refreshed the oauth2 token
|
|
|
|
RefreshOauth2Token(refreshToken string) (*oauth2.Token, error)
|
2019-02-21 15:06:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 09:07:54 +00:00
|
|
|
type RepoInfo struct {
|
|
|
|
ID string
|
2019-04-29 15:36:29 +00:00
|
|
|
Path string
|
2019-06-11 09:07:12 +00:00
|
|
|
HTMLURL string
|
2019-04-03 09:07:54 +00:00
|
|
|
SSHCloneURL string
|
|
|
|
HTTPCloneURL string
|
|
|
|
}
|
|
|
|
|
2019-02-21 15:06:34 +00:00
|
|
|
type UserInfo struct {
|
|
|
|
ID string
|
|
|
|
LoginName string
|
|
|
|
Email string
|
|
|
|
}
|