Add Gitea endpoints and credentials

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-05-14 00:34:54 +00:00
parent 40e6581a75
commit 823a9e4b82
100 changed files with 7439 additions and 660 deletions

View file

@ -11,7 +11,7 @@ import (
"github.com/cloudbase/garm/params"
)
func (r *Runner) ListCredentials(ctx context.Context) ([]params.GithubCredentials, error) {
func (r *Runner) ListCredentials(ctx context.Context) ([]params.ForgeCredentials, error) {
if !auth.IsAdmin(ctx) {
return nil, runnerErrors.ErrUnauthorized
}
@ -37,31 +37,31 @@ func (r *Runner) ListCredentials(ctx context.Context) ([]params.GithubCredential
return creds, nil
}
func (r *Runner) CreateGithubCredentials(ctx context.Context, param params.CreateGithubCredentialsParams) (params.GithubCredentials, error) {
func (r *Runner) CreateGithubCredentials(ctx context.Context, param params.CreateGithubCredentialsParams) (params.ForgeCredentials, error) {
if !auth.IsAdmin(ctx) {
return params.GithubCredentials{}, runnerErrors.ErrUnauthorized
return params.ForgeCredentials{}, runnerErrors.ErrUnauthorized
}
if err := param.Validate(); err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "failed to validate github credentials params")
return params.ForgeCredentials{}, errors.Wrap(err, "failed to validate github credentials params")
}
creds, err := r.store.CreateGithubCredentials(ctx, param)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "failed to create github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "failed to create github credentials")
}
return creds, nil
}
func (r *Runner) GetGithubCredentials(ctx context.Context, id uint) (params.GithubCredentials, error) {
func (r *Runner) GetGithubCredentials(ctx context.Context, id uint) (params.ForgeCredentials, error) {
if !auth.IsAdmin(ctx) {
return params.GithubCredentials{}, runnerErrors.ErrUnauthorized
return params.ForgeCredentials{}, runnerErrors.ErrUnauthorized
}
creds, err := r.store.GetGithubCredentials(ctx, id, true)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "failed to get github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "failed to get github credentials")
}
cached, ok := cache.GetGithubCredentials((creds.ID))
@ -84,18 +84,18 @@ func (r *Runner) DeleteGithubCredentials(ctx context.Context, id uint) error {
return nil
}
func (r *Runner) UpdateGithubCredentials(ctx context.Context, id uint, param params.UpdateGithubCredentialsParams) (params.GithubCredentials, error) {
func (r *Runner) UpdateGithubCredentials(ctx context.Context, id uint, param params.UpdateGithubCredentialsParams) (params.ForgeCredentials, error) {
if !auth.IsAdmin(ctx) {
return params.GithubCredentials{}, runnerErrors.ErrUnauthorized
return params.ForgeCredentials{}, runnerErrors.ErrUnauthorized
}
if err := param.Validate(); err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "failed to validate github credentials params")
return params.ForgeCredentials{}, errors.Wrap(err, "failed to validate github credentials params")
}
newCreds, err := r.store.UpdateGithubCredentials(ctx, id, param)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "failed to update github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "failed to update github credentials")
}
return newCreds, nil