mirror of
https://github.com/rocky-linux/peridot.git
synced 2024-12-21 02:08:29 +00:00
allow peridot project to specify a build pool type in additional to build pool architecture
Signed-off-by: mystic knight <techguru@byiq.com>
This commit is contained in:
parent
f19044b3d2
commit
fdc848b847
@ -31,30 +31,30 @@
|
|||||||
package serverpsql
|
package serverpsql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jmoiron/sqlx/types"
|
"github.com/jmoiron/sqlx/types"
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
"google.golang.org/protobuf/encoding/protojson"
|
"google.golang.org/protobuf/encoding/protojson"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
"peridot.resf.org/peridot/db/models"
|
"peridot.resf.org/peridot/db/models"
|
||||||
peridotpb "peridot.resf.org/peridot/pb"
|
peridotpb "peridot.resf.org/peridot/pb"
|
||||||
"peridot.resf.org/utils"
|
"peridot.resf.org/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *Access) ListProjects(filters *peridotpb.ProjectFilters) (ret models.Projects, err error) {
|
func (a *Access) ListProjects(filters *peridotpb.ProjectFilters) (ret models.Projects, err error) {
|
||||||
if filters == nil {
|
if filters == nil {
|
||||||
filters = &peridotpb.ProjectFilters{}
|
filters = &peridotpb.ProjectFilters{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ids pq.StringArray = nil
|
var ids pq.StringArray = nil
|
||||||
if filters.Ids != nil {
|
if filters.Ids != nil {
|
||||||
ids = filters.Ids
|
ids = filters.Ids
|
||||||
}
|
}
|
||||||
|
|
||||||
err = a.query.Select(
|
err = a.query.Select(
|
||||||
&ret,
|
&ret,
|
||||||
`
|
`
|
||||||
select
|
select
|
||||||
id,
|
id,
|
||||||
created_at,
|
created_at,
|
||||||
@ -88,19 +88,19 @@ func (a *Access) ListProjects(filters *peridotpb.ProjectFilters) (ret models.Pro
|
|||||||
and ($3 :: uuid[] is null or id = any($3 :: uuid[]))
|
and ($3 :: uuid[] is null or id = any($3 :: uuid[]))
|
||||||
order by created_at desc
|
order by created_at desc
|
||||||
`,
|
`,
|
||||||
utils.StringValueP(filters.Id),
|
utils.StringValueP(filters.Id),
|
||||||
utils.StringValueP(filters.Name),
|
utils.StringValueP(filters.Name),
|
||||||
ids,
|
ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Access) GetProjectKeys(projectId string) (*models.ProjectKey, error) {
|
func (a *Access) GetProjectKeys(projectId string) (*models.ProjectKey, error) {
|
||||||
var ret models.ProjectKey
|
var ret models.ProjectKey
|
||||||
err := a.query.Get(
|
err := a.query.Get(
|
||||||
&ret,
|
&ret,
|
||||||
`
|
`
|
||||||
select
|
select
|
||||||
id,
|
id,
|
||||||
created_at,
|
created_at,
|
||||||
@ -110,21 +110,21 @@ func (a *Access) GetProjectKeys(projectId string) (*models.ProjectKey, error) {
|
|||||||
from project_keys
|
from project_keys
|
||||||
where project_id = $1
|
where project_id = $1
|
||||||
`,
|
`,
|
||||||
projectId,
|
projectId,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProjectModuleConfiguration returns the module configurations for the given project.
|
// GetProjectModuleConfiguration returns the module configurations for the given project.
|
||||||
func (a *Access) GetProjectModuleConfiguration(projectId string) (*peridotpb.ModuleConfiguration, error) {
|
func (a *Access) GetProjectModuleConfiguration(projectId string) (*peridotpb.ModuleConfiguration, error) {
|
||||||
var ret types.JSONText
|
var ret types.JSONText
|
||||||
err := a.query.Get(
|
err := a.query.Get(
|
||||||
&ret,
|
&ret,
|
||||||
`
|
`
|
||||||
select
|
select
|
||||||
proto
|
proto
|
||||||
from project_module_configuration
|
from project_module_configuration
|
||||||
@ -132,86 +132,86 @@ func (a *Access) GetProjectModuleConfiguration(projectId string) (*peridotpb.Mod
|
|||||||
project_id = $1
|
project_id = $1
|
||||||
and active = true
|
and active = true
|
||||||
`,
|
`,
|
||||||
projectId,
|
projectId,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
anyPb := &anypb.Any{}
|
anyPb := &anypb.Any{}
|
||||||
err = protojson.Unmarshal(ret, anyPb)
|
err = protojson.Unmarshal(ret, anyPb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal module configuration (protojson): %v", err)
|
return nil, fmt.Errorf("failed to unmarshal module configuration (protojson): %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pb := &peridotpb.ModuleConfiguration{}
|
pb := &peridotpb.ModuleConfiguration{}
|
||||||
err = anypb.UnmarshalTo(anyPb, pb, proto.UnmarshalOptions{})
|
err = anypb.UnmarshalTo(anyPb, pb, proto.UnmarshalOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal module configuration: %v", err)
|
return nil, fmt.Errorf("failed to unmarshal module configuration: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pb, nil
|
return pb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Access) CreateProjectModuleConfiguration(projectId string, config *peridotpb.ModuleConfiguration) error {
|
func (a *Access) CreateProjectModuleConfiguration(projectId string, config *peridotpb.ModuleConfiguration) error {
|
||||||
anyPb, err := anypb.New(config)
|
anyPb, err := anypb.New(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal module configuration: %v", err)
|
return fmt.Errorf("failed to marshal module configuration: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
protoJson, err := protojson.Marshal(anyPb)
|
protoJson, err := protojson.Marshal(anyPb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to marshal module configuration (protojson): %v", err)
|
return fmt.Errorf("failed to marshal module configuration (protojson): %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = a.query.Exec(
|
_, err = a.query.Exec(
|
||||||
`
|
`
|
||||||
insert into project_module_configuration (project_id, proto, active)
|
insert into project_module_configuration (project_id, proto, active)
|
||||||
values ($1, $2, true)
|
values ($1, $2, true)
|
||||||
on conflict (project_id) do update
|
on conflict (project_id) do update
|
||||||
set proto = $2, active = true
|
set proto = $2, active = true
|
||||||
`,
|
`,
|
||||||
projectId,
|
projectId,
|
||||||
protoJson,
|
protoJson,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Access) CreateProject(project *peridotpb.Project) (*models.Project, error) {
|
func (a *Access) CreateProject(project *peridotpb.Project) (*models.Project, error) {
|
||||||
if err := project.ValidateAll(); err != nil {
|
if err := project.ValidateAll(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := models.Project{
|
ret := models.Project{
|
||||||
Name: project.Name.Value,
|
Name: project.Name.Value,
|
||||||
MajorVersion: int(project.MajorVersion.Value),
|
MajorVersion: int(project.MajorVersion.Value),
|
||||||
DistTagOverride: utils.StringValueToNullString(project.DistTag),
|
DistTagOverride: utils.StringValueToNullString(project.DistTag),
|
||||||
TargetGitlabHost: project.TargetGitlabHost.Value,
|
TargetGitlabHost: project.TargetGitlabHost.Value,
|
||||||
TargetPrefix: project.TargetPrefix.Value,
|
TargetPrefix: project.TargetPrefix.Value,
|
||||||
TargetBranchPrefix: project.TargetBranchPrefix.Value,
|
TargetBranchPrefix: project.TargetBranchPrefix.Value,
|
||||||
SourceGitHost: utils.StringValueToNullString(project.SourceGitHost),
|
SourceGitHost: utils.StringValueToNullString(project.SourceGitHost),
|
||||||
SourcePrefix: utils.StringValueToNullString(project.SourcePrefix),
|
SourcePrefix: utils.StringValueToNullString(project.SourcePrefix),
|
||||||
SourceBranchPrefix: utils.StringValueToNullString(project.SourceBranchPrefix),
|
SourceBranchPrefix: utils.StringValueToNullString(project.SourceBranchPrefix),
|
||||||
CdnUrl: utils.StringValueToNullString(project.CdnUrl),
|
CdnUrl: utils.StringValueToNullString(project.CdnUrl),
|
||||||
StreamMode: project.StreamMode,
|
StreamMode: project.StreamMode,
|
||||||
TargetVendor: project.TargetVendor,
|
TargetVendor: project.TargetVendor,
|
||||||
AdditionalVendor: project.AdditionalVendor.Value,
|
AdditionalVendor: project.AdditionalVendor.Value,
|
||||||
Archs: project.Archs,
|
Archs: project.Archs,
|
||||||
BuildPoolType: project.BuildPoolType,
|
BuildPoolType: project.BuildPoolType,
|
||||||
FollowImportDist: project.FollowImportDist,
|
FollowImportDist: project.FollowImportDist,
|
||||||
BranchSuffix: utils.StringValueToNullString(project.BranchSuffix),
|
BranchSuffix: utils.StringValueToNullString(project.BranchSuffix),
|
||||||
GitMakePublic: project.GitMakePublic,
|
GitMakePublic: project.GitMakePublic,
|
||||||
VendorMacro: utils.StringValueToNullString(project.VendorMacro),
|
VendorMacro: utils.StringValueToNullString(project.VendorMacro),
|
||||||
PackagerMacro: utils.StringValueToNullString(project.PackagerMacro),
|
PackagerMacro: utils.StringValueToNullString(project.PackagerMacro),
|
||||||
}
|
}
|
||||||
|
|
||||||
err := a.query.Get(
|
err := a.query.Get(
|
||||||
&ret,
|
&ret,
|
||||||
`
|
`
|
||||||
insert into projects
|
insert into projects
|
||||||
(name, major_version, dist_tag_override, target_gitlab_host, target_prefix,
|
(name, major_version, dist_tag_override, target_gitlab_host, target_prefix,
|
||||||
target_branch_prefix, source_git_host, source_prefix, source_branch_prefix, cdn_url,
|
target_branch_prefix, source_git_host, source_prefix, source_branch_prefix, cdn_url,
|
||||||
@ -220,65 +220,65 @@ func (a *Access) CreateProject(project *peridotpb.Project) (*models.Project, err
|
|||||||
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
|
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
|
||||||
returning id, created_at, updated_at
|
returning id, created_at, updated_at
|
||||||
`,
|
`,
|
||||||
ret.Name,
|
ret.Name,
|
||||||
ret.MajorVersion,
|
ret.MajorVersion,
|
||||||
ret.DistTagOverride,
|
ret.DistTagOverride,
|
||||||
ret.TargetGitlabHost,
|
ret.TargetGitlabHost,
|
||||||
ret.TargetPrefix,
|
ret.TargetPrefix,
|
||||||
ret.TargetBranchPrefix,
|
ret.TargetBranchPrefix,
|
||||||
ret.SourceGitHost,
|
ret.SourceGitHost,
|
||||||
ret.SourcePrefix,
|
ret.SourcePrefix,
|
||||||
ret.SourceBranchPrefix,
|
ret.SourceBranchPrefix,
|
||||||
ret.CdnUrl,
|
ret.CdnUrl,
|
||||||
ret.StreamMode,
|
ret.StreamMode,
|
||||||
ret.TargetVendor,
|
ret.TargetVendor,
|
||||||
ret.AdditionalVendor,
|
ret.AdditionalVendor,
|
||||||
ret.Archs,
|
ret.Archs,
|
||||||
ret.BuildPoolType,
|
ret.BuildPoolType,
|
||||||
ret.FollowImportDist,
|
ret.FollowImportDist,
|
||||||
ret.BranchSuffix,
|
ret.BranchSuffix,
|
||||||
ret.GitMakePublic,
|
ret.GitMakePublic,
|
||||||
ret.VendorMacro,
|
ret.VendorMacro,
|
||||||
ret.PackagerMacro,
|
ret.PackagerMacro,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Access) UpdateProject(id string, project *peridotpb.Project) (*models.Project, error) {
|
func (a *Access) UpdateProject(id string, project *peridotpb.Project) (*models.Project, error) {
|
||||||
if err := project.ValidateAll(); err != nil {
|
if err := project.ValidateAll(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := models.Project{
|
ret := models.Project{
|
||||||
Name: project.Name.Value,
|
Name: project.Name.Value,
|
||||||
MajorVersion: int(project.MajorVersion.Value),
|
MajorVersion: int(project.MajorVersion.Value),
|
||||||
DistTagOverride: utils.StringValueToNullString(project.DistTag),
|
DistTagOverride: utils.StringValueToNullString(project.DistTag),
|
||||||
TargetGitlabHost: project.TargetGitlabHost.Value,
|
TargetGitlabHost: project.TargetGitlabHost.Value,
|
||||||
TargetPrefix: project.TargetPrefix.Value,
|
TargetPrefix: project.TargetPrefix.Value,
|
||||||
TargetBranchPrefix: project.TargetBranchPrefix.Value,
|
TargetBranchPrefix: project.TargetBranchPrefix.Value,
|
||||||
SourceGitHost: utils.StringValueToNullString(project.SourceGitHost),
|
SourceGitHost: utils.StringValueToNullString(project.SourceGitHost),
|
||||||
SourcePrefix: utils.StringValueToNullString(project.SourcePrefix),
|
SourcePrefix: utils.StringValueToNullString(project.SourcePrefix),
|
||||||
SourceBranchPrefix: utils.StringValueToNullString(project.SourceBranchPrefix),
|
SourceBranchPrefix: utils.StringValueToNullString(project.SourceBranchPrefix),
|
||||||
CdnUrl: utils.StringValueToNullString(project.CdnUrl),
|
CdnUrl: utils.StringValueToNullString(project.CdnUrl),
|
||||||
StreamMode: project.StreamMode,
|
StreamMode: project.StreamMode,
|
||||||
TargetVendor: project.TargetVendor,
|
TargetVendor: project.TargetVendor,
|
||||||
AdditionalVendor: project.AdditionalVendor.Value,
|
AdditionalVendor: project.AdditionalVendor.Value,
|
||||||
Archs: project.Archs,
|
Archs: project.Archs,
|
||||||
BuildPoolType: project.BuildPoolType,
|
BuildPoolType: project.BuildPoolType.Value,
|
||||||
FollowImportDist: project.FollowImportDist,
|
FollowImportDist: project.FollowImportDist,
|
||||||
BranchSuffix: utils.StringValueToNullString(project.BranchSuffix),
|
BranchSuffix: utils.StringValueToNullString(project.BranchSuffix),
|
||||||
GitMakePublic: project.GitMakePublic,
|
GitMakePublic: project.GitMakePublic,
|
||||||
VendorMacro: utils.StringValueToNullString(project.VendorMacro),
|
VendorMacro: utils.StringValueToNullString(project.VendorMacro),
|
||||||
PackagerMacro: utils.StringValueToNullString(project.PackagerMacro),
|
PackagerMacro: utils.StringValueToNullString(project.PackagerMacro),
|
||||||
}
|
}
|
||||||
|
|
||||||
err := a.query.Get(
|
err := a.query.Get(
|
||||||
&ret,
|
&ret,
|
||||||
`
|
`
|
||||||
update projects set
|
update projects set
|
||||||
name = $1,
|
name = $1,
|
||||||
major_version = $2,
|
major_version = $2,
|
||||||
@ -304,65 +304,65 @@ func (a *Access) UpdateProject(id string, project *peridotpb.Project) (*models.P
|
|||||||
where id = $21
|
where id = $21
|
||||||
returning id, created_at, updated_at
|
returning id, created_at, updated_at
|
||||||
`,
|
`,
|
||||||
ret.Name,
|
ret.Name,
|
||||||
ret.MajorVersion,
|
ret.MajorVersion,
|
||||||
ret.DistTagOverride,
|
ret.DistTagOverride,
|
||||||
ret.TargetGitlabHost,
|
ret.TargetGitlabHost,
|
||||||
ret.TargetPrefix,
|
ret.TargetPrefix,
|
||||||
ret.TargetBranchPrefix,
|
ret.TargetBranchPrefix,
|
||||||
ret.SourceGitHost,
|
ret.SourceGitHost,
|
||||||
ret.SourcePrefix,
|
ret.SourcePrefix,
|
||||||
ret.SourceBranchPrefix,
|
ret.SourceBranchPrefix,
|
||||||
ret.CdnUrl,
|
ret.CdnUrl,
|
||||||
ret.StreamMode,
|
ret.StreamMode,
|
||||||
ret.TargetVendor,
|
ret.TargetVendor,
|
||||||
ret.AdditionalVendor,
|
ret.AdditionalVendor,
|
||||||
ret.Archs,
|
ret.Archs,
|
||||||
ret.BuildPoolType,
|
ret.BuildPoolType,
|
||||||
ret.FollowImportDist,
|
ret.FollowImportDist,
|
||||||
ret.BranchSuffix,
|
ret.BranchSuffix,
|
||||||
ret.GitMakePublic,
|
ret.GitMakePublic,
|
||||||
ret.VendorMacro,
|
ret.VendorMacro,
|
||||||
ret.PackagerMacro,
|
ret.PackagerMacro,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Access) SetProjectKeys(projectId string, username string, password string) error {
|
func (a *Access) SetProjectKeys(projectId string, username string, password string) error {
|
||||||
_, err := a.query.Exec(
|
_, err := a.query.Exec(
|
||||||
`
|
`
|
||||||
insert into project_keys (project_id, gitlab_username, gitlab_secret)
|
insert into project_keys (project_id, gitlab_username, gitlab_secret)
|
||||||
values ($1, $2, $3)
|
values ($1, $2, $3)
|
||||||
on conflict (project_id) do update
|
on conflict (project_id) do update
|
||||||
set gitlab_username = $2, gitlab_secret = $3
|
set gitlab_username = $2, gitlab_secret = $3
|
||||||
`,
|
`,
|
||||||
projectId,
|
projectId,
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Access) SetBuildRootPackages(projectId string, srpmPackages pq.StringArray, buildPackages pq.StringArray) error {
|
func (a *Access) SetBuildRootPackages(projectId string, srpmPackages pq.StringArray, buildPackages pq.StringArray) error {
|
||||||
if srpmPackages == nil {
|
if srpmPackages == nil {
|
||||||
srpmPackages = pq.StringArray{}
|
srpmPackages = pq.StringArray{}
|
||||||
}
|
}
|
||||||
if buildPackages == nil {
|
if buildPackages == nil {
|
||||||
buildPackages = pq.StringArray{}
|
buildPackages = pq.StringArray{}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := a.query.Exec(
|
_, err := a.query.Exec(
|
||||||
`
|
`
|
||||||
update projects set srpm_stage_packages = $2, build_stage_packages = $3 where id = $1
|
update projects set srpm_stage_packages = $2, build_stage_packages = $3 where id = $1
|
||||||
`,
|
`,
|
||||||
projectId,
|
projectId,
|
||||||
srpmPackages,
|
srpmPackages,
|
||||||
buildPackages,
|
buildPackages,
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user