Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(providers): Added bitbucket enterprise provider #568

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(providers): Added BasicAuth support
Porsh33 committed Apr 14, 2022
commit 43bcc4f19ac9bc01308ff03068f99bbf52c00090
2 changes: 2 additions & 0 deletions pb/api.proto
Original file line number Diff line number Diff line change
@@ -69,6 +69,8 @@ message Job {
string sshPrivateKey = 21;
bool sshClone = 22;
string branch = 23;
string providerHttpUser = 24;
string providerHttpPass = 25;
}

message Command {
4 changes: 4 additions & 0 deletions server/api/provider/create.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ func HandleCreate(providers core.ProviderStore) http.HandlerFunc {
Host string `json:"host" valid:"url,required"`
AccessToken string `json:"accessToken" valid:"stringlength(12|50),required"`
Secret string `json:"secret" valid:"stringlength(5|50),required"`
HttpUser string `json:"HttpUser"`
HttpPass string `json:"HttpPass"`
}

return func(w http.ResponseWriter, r *http.Request) {
@@ -44,6 +46,8 @@ func HandleCreate(providers core.ProviderStore) http.HandlerFunc {
AccessToken: f.AccessToken,
Secret: f.Secret,
UserID: claims.ID,
HttpUser: f.HttpUser,
HttpPass: f.HttpPass,
}

if err := providers.Create(provider); err != nil {
16 changes: 10 additions & 6 deletions server/api/provider/update.go
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ func HandleUpdate(providers core.ProviderStore, users core.UserStore) http.Handl
Host string `json:"host" valid:"url,required"`
AccessToken string `json:"accessToken"`
Secret string `json:"secret" valid:"stringlength(5|50),required"`
HttpUser string `json:"HttpUser"`
HttpPass string `json:"HttpPass"`
}

return func(w http.ResponseWriter, r *http.Request) {
@@ -52,12 +54,14 @@ func HandleUpdate(providers core.ProviderStore, users core.UserStore) http.Handl

if p.UserID == claims.ID || user.Role == "admin" {
provider := &core.Provider{
ID: f.ID,
Name: f.Name,
URL: f.URL,
Host: f.Host,
Secret: f.Secret,
UserID: claims.ID,
ID: f.ID,
Name: f.Name,
URL: f.URL,
Host: f.Host,
Secret: f.Secret,
UserID: claims.ID,
HttpUser: f.HttpUser,
HttpPass: f.HttpPass,
}

if f.AccessToken != "" {
2 changes: 2 additions & 0 deletions server/core/provider.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ type (
Name string `gorm:"not null" json:"name"`
URL string `gorm:"not null" json:"url"`
AccessToken string `gorm:"not null" json:"-"`
HttpUser string `json:"HttpUser"`
HttpPass string `json:"HttpPass"`
Porsh33 marked this conversation as resolved.
Show resolved Hide resolved
Secret string `gorm:"not null" json:"secret"`
Host string `gorm:"not null" json:"host"`
LastSync *time.Time `json:"lastSync"`
47 changes: 27 additions & 20 deletions server/scheduler/scheduler.go
Original file line number Diff line number Diff line change
@@ -312,27 +312,34 @@ func (s *scheduler) startJob(job *core.Job, worker *core.Worker) {
s.logger.Errorf("error parsing commands for job %d: %s", job.ID, err.Error())
}

url := job.Build.Repository.Clone
if url == "" {
url = job.Build.Repository.URL
}

j := &pb.Job{
Id: uint64(job.ID),
BuildId: uint64(job.BuildID),
Commands: commands.Commands,
Image: job.Image,
Env: envs,
Url: job.Build.Repository.URL,
SshURL: job.Build.Repository.CloneSSH,
ProviderName: job.Build.Repository.Provider.Name,
ProviderURL: job.Build.Repository.Provider.URL,
ProviderToken: job.Build.Repository.Provider.AccessToken,
Ref: job.Build.Ref,
CommitSHA: job.Build.Commit,
Branch: job.Build.Branch,
RepoName: job.Build.Repository.FullName,
Action: pb.Job_JobStart,
WorkerId: worker.ID,
Cache: strings.Split(job.Cache, ","),
Mount: strings.Split(job.Mount, ","),
SshPrivateKey: job.Build.Repository.SSHPrivateKey,
SshClone: job.Build.Repository.UseSSH,
Id: uint64(job.ID),
BuildId: uint64(job.BuildID),
Commands: commands.Commands,
Image: job.Image,
Env: envs,
Url: url,
SshURL: job.Build.Repository.CloneSSH,
ProviderName: job.Build.Repository.Provider.Name,
ProviderURL: job.Build.Repository.Provider.URL,
ProviderToken: job.Build.Repository.Provider.AccessToken,
Ref: job.Build.Ref,
CommitSHA: job.Build.Commit,
Branch: job.Build.Branch,
RepoName: job.Build.Repository.FullName,
Action: pb.Job_JobStart,
WorkerId: worker.ID,
Cache: strings.Split(job.Cache, ","),
Mount: strings.Split(job.Mount, ","),
SshPrivateKey: job.Build.Repository.SSHPrivateKey,
SshClone: job.Build.Repository.UseSSH,
ProviderHttpUser: job.Build.Repository.Provider.HttpUser,
ProviderHttpPass: job.Build.Repository.Provider.HttpPass,
}

s.mu.Lock()
5 changes: 4 additions & 1 deletion server/store/provider/provider.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,10 @@ func (s providerStore) Create(provider *core.Provider) error {
}

func (s providerStore) Update(provider *core.Provider) error {
return s.db.Model(provider).Updates(&provider).Error
updateHttp := make(map[string]interface{})
updateHttp["HttpUser"] = provider.HttpUser
updateHttp["HttpPass"] = provider.HttpPass
return s.db.Model(provider).Updates(updateHttp).Updates(&provider).Error
}

func (s providerStore) Delete(provider *core.Provider) error {
Original file line number Diff line number Diff line change
@@ -51,6 +51,30 @@ <h2>Git SCM Provider Integration</h2>
Host URL is URL where SCM provider can access Abstruse to trigger webhooks.
</span>
</div>
<div class="field">
<label class="label">Http Basic auth</label>
<input
type="text"
name="httpuser"
class="input"
placeholder="Http username for clone"
formControlName="httpUser"
autocomplete="off"
style="display: inline;box-sizing: border-box;width: calc(50% - 2px);"
/>
<input
type="text"
name="httppass"
class="input"
placeholder="Http password for clone"
formControlName="httpPass"
autocomplete="off"
style="display: inline;box-sizing: border-box;width: calc(50% - 2px);"
/>
<span class="form-helper">
Basic auth for clone operations via HTTP
</span>
</div>
<div class="field">
<label class="label">Access Token</label>
<input
Original file line number Diff line number Diff line change
@@ -46,12 +46,16 @@ export class ProvidersModalComponent implements OnInit {

this.error = null;
this.saving = true;
console.log('im here');
console.log(this.form.controls);
let data: any = {
name: this.form.controls.name.value,
url: this.form.controls.url.value,
host: this.form.controls.host.value,
accessToken: this.form.controls.accessToken.value,
secret: this.form.controls.secret.value
secret: this.form.controls.secret.value,
httpUser: this.form.controls.httpUser.value,
httpPass: this.form.controls.httpPass.value
};
if (this.provider && this.provider.id) {
data = { ...data, ...{ id: this.provider.id } };
@@ -141,7 +145,9 @@ export class ProvidersModalComponent implements OnInit {
[Validators.required]
],
accessToken: [(this.provider && this.provider.accessToken) || null],
secret: [(this.provider && this.provider.secret) || null, [Validators.required]]
secret: [(this.provider && this.provider.secret) || null, [Validators.required]],
httpUser: [(this.provider && this.provider.HttpUser) || null],
httpPass: [(this.provider && this.provider.HttpPass) || null]
});
}
}
4 changes: 4 additions & 0 deletions web/abstruse/src/app/providers/shared/provider.class.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ export class Provider {
public host?: string,
public secret?: string,
public accessToken?: string,
public HttpUser?: string,
public HttpPass?: string,
public lastSync?: Date | null,
public userID?: number,
public createdAt?: Date,
@@ -51,6 +53,8 @@ export const generateProvider = (data: any): Provider => {
data.host,
data.secret,
data.accessToken,
data.HttpUser,
data.HttpPass,
data.lastSync ? new Date(data.lastSync) : null,
data.userID,
new Date(data.createdAt),
12 changes: 11 additions & 1 deletion worker/app/server.go
Original file line number Diff line number Diff line change
@@ -219,11 +219,21 @@ func (s *Server) StartJob(job *pb.Job, stream pb.API_StartJobServer) error {
logch <- []byte(yellow(fmt.Sprintf("==> Cloning repository %s ref: %s sha: %s... ", job.GetSshURL(), job.GetRef(), job.GetCommitSHA())))
}

HttpUser := job.GetProviderHttpUser()
Porsh33 marked this conversation as resolved.
Show resolved Hide resolved
if HttpUser == "" {
HttpUser = "user"
}
HttpPass := job.GetProviderHttpPass()
if HttpPass == "" {
HttpPass = job.GetProviderToken()
}

if err := git.CloneRepository(
job.GetUrl(),
job.GetRef(),
job.GetCommitSHA(),
job.GetProviderToken(),
HttpUser,
HttpPass,
dir,
job.GetSshURL(),
[]byte(job.GetSshPrivateKey()),
8 changes: 4 additions & 4 deletions worker/git/clone.go
Original file line number Diff line number Diff line change
@@ -14,14 +14,14 @@ import (
)

// CloneRepository clones repository contents to specified path.
func CloneRepository(url, ref, commit, token, dir, sshURL string, sshKey []byte, useSSH bool) error {
func CloneRepository(url, ref, commit, user, pass, dir, sshURL string, sshKey []byte, useSSH bool) error {
var auth transport.AuthMethod
var err error

if token != "" && !useSSH {
if pass != "" && !useSSH {
auth = &http.BasicAuth{
Username: "user",
Password: token,
Username: user,
Password: pass,
}
} else if useSSH {
url = sshURL