Add API endpoint for some scaleset ops
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
85eac363d5
commit
7e1a83c79a
31 changed files with 2768 additions and 25 deletions
|
|
@ -15,6 +15,7 @@
|
|||
package sql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
|
|
@ -60,7 +61,6 @@ func (s *sqlDatabase) sqlToParamsInstance(instance Instance) (params.Instance, e
|
|||
OSArch: instance.OSArch,
|
||||
Status: instance.Status,
|
||||
RunnerStatus: instance.RunnerStatus,
|
||||
PoolID: instance.PoolID.String(),
|
||||
CallbackURL: instance.CallbackURL,
|
||||
MetadataURL: instance.MetadataURL,
|
||||
StatusMessages: []params.StatusMessage{},
|
||||
|
|
@ -75,6 +75,22 @@ func (s *sqlDatabase) sqlToParamsInstance(instance Instance) (params.Instance, e
|
|||
|
||||
if instance.ScaleSetFkID != nil {
|
||||
ret.ScaleSetID = *instance.ScaleSetFkID
|
||||
ret.ProviderName = instance.ScaleSet.ProviderName
|
||||
ret.RunnerBootstrapTimeout = instance.ScaleSet.RunnerBootstrapTimeout
|
||||
}
|
||||
|
||||
if instance.PoolID != uuid.Nil {
|
||||
ret.PoolID = instance.PoolID.String()
|
||||
ret.ProviderName = instance.Pool.ProviderName
|
||||
ret.RunnerBootstrapTimeout = instance.Pool.RunnerBootstrapTimeout
|
||||
}
|
||||
|
||||
if ret.ScaleSetID == 0 && ret.PoolID == "" {
|
||||
return params.Instance{}, errors.New("missing pool or scale set id")
|
||||
}
|
||||
|
||||
if ret.ScaleSetID != 0 && ret.PoolID != "" {
|
||||
return params.Instance{}, errors.New("both pool and scale set ids are set")
|
||||
}
|
||||
|
||||
if instance.Job != nil {
|
||||
|
|
@ -591,3 +607,27 @@ func (s *sqlDatabase) sendNotify(entityType dbCommon.DatabaseEntityType, op dbCo
|
|||
}
|
||||
return s.producer.Notify(message)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) GetGithubEntity(_ context.Context, entityType params.GithubEntityType, entityID string) (params.GithubEntity, error) {
|
||||
var ghEntity params.EntityGetter
|
||||
var err error
|
||||
switch entityType {
|
||||
case params.GithubEntityTypeEnterprise:
|
||||
ghEntity, err = s.GetEnterpriseByID(s.ctx, entityID)
|
||||
case params.GithubEntityTypeOrganization:
|
||||
ghEntity, err = s.GetOrganizationByID(s.ctx, entityID)
|
||||
case params.GithubEntityTypeRepository:
|
||||
ghEntity, err = s.GetRepositoryByID(s.ctx, entityID)
|
||||
default:
|
||||
return params.GithubEntity{}, errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
|
||||
}
|
||||
if err != nil {
|
||||
return params.GithubEntity{}, errors.Wrap(err, "failed to get ")
|
||||
}
|
||||
|
||||
entity, err := ghEntity.GetEntity()
|
||||
if err != nil {
|
||||
return params.GithubEntity{}, errors.Wrap(err, "failed to get entity")
|
||||
}
|
||||
return entity, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue