mirror of
https://github.com/rocky-linux/peridot.git
synced 2024-12-20 09:48:29 +00:00
Support simple filter for Build API
This commit is contained in:
parent
5eec7a5354
commit
e901745be5
@ -36,16 +36,21 @@
|
|||||||
import {
|
import {
|
||||||
svcNameHttp,
|
svcNameHttp,
|
||||||
endpointHttp,
|
endpointHttp,
|
||||||
NS,
|
|
||||||
envOverridable,
|
envOverridable,
|
||||||
|
NS,
|
||||||
} from '../../../common/frontend_server/upstream.mjs';
|
} from '../../../common/frontend_server/upstream.mjs';
|
||||||
import pkg from '@ory/hydra-client';
|
import pkg from '@ory/hydra-client';
|
||||||
import os from 'os';
|
|
||||||
|
|
||||||
const { Configuration, PublicApi, AdminApi } = pkg;
|
const { Configuration, OidcApi, OAuth2Api } = pkg;
|
||||||
|
|
||||||
export function hydraPublicUrl() {
|
export function hydraPublicUrl() {
|
||||||
return envOverridable('hydra_public', 'http', () => {
|
return envOverridable('hydra_public', 'http', () => {
|
||||||
|
if (!process.env['RESF_ENV']) {
|
||||||
|
if (process.env['HYDRA_PUBLIC_URL']) {
|
||||||
|
return process.env['HYDRA_PUBLIC_URL'];
|
||||||
|
}
|
||||||
|
return 'https://hdr-dev.internal.rdev.ciq.localhost';
|
||||||
|
}
|
||||||
const svc = svcNameHttp('hydra-public');
|
const svc = svcNameHttp('hydra-public');
|
||||||
return endpointHttp(svc, NS('hydra-public'), ':4444');
|
return endpointHttp(svc, NS('hydra-public'), ':4444');
|
||||||
});
|
});
|
||||||
@ -53,18 +58,21 @@ export function hydraPublicUrl() {
|
|||||||
|
|
||||||
function hydraAdminUrl() {
|
function hydraAdminUrl() {
|
||||||
return envOverridable('hydra_admin', 'http', () => {
|
return envOverridable('hydra_admin', 'http', () => {
|
||||||
|
if (!process.env['RESF_ENV']) {
|
||||||
|
return 'https://hdr-admin-dev.internal.rdev.ciq.localhost';
|
||||||
|
}
|
||||||
const svc = svcNameHttp('hydra-admin');
|
const svc = svcNameHttp('hydra-admin');
|
||||||
return endpointHttp(svc, NS('hydra-admin'), ':4445');
|
return endpointHttp(svc, NS('hydra-admin'), ':4445');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const hydraAdmin = new AdminApi(
|
const hydraAdmin = new OAuth2Api(
|
||||||
new Configuration({
|
new Configuration({
|
||||||
basePath: hydraAdminUrl(),
|
basePath: hydraAdminUrl(),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export const hydraPublic = new PublicApi(
|
export const hydraPublic = new OidcApi(
|
||||||
new Configuration({
|
new Configuration({
|
||||||
basePath: hydraPublicUrl(),
|
basePath: hydraPublicUrl(),
|
||||||
})
|
})
|
||||||
@ -85,6 +93,16 @@ function secret() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function hydraAutoSignup(req) {
|
export async function hydraAutoSignup(req) {
|
||||||
|
const envNameClientID = `${req.client.toUpperCase()}_CLIENT_ID`;
|
||||||
|
const envNameClientSecret = `${req.client.toUpperCase()}_CLIENT_SECRET`;
|
||||||
|
|
||||||
|
if (process.env[envNameClientID] && process.env[envNameClientSecret]) {
|
||||||
|
return {
|
||||||
|
clientID: process.env[envNameClientID],
|
||||||
|
secret: process.env[envNameClientSecret],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let ns = process.env['RESF_NS'];
|
let ns = process.env['RESF_NS'];
|
||||||
if (!ns || ns === '') {
|
if (!ns || ns === '') {
|
||||||
ns = 'dev';
|
ns = 'dev';
|
||||||
@ -96,11 +114,11 @@ export async function hydraAutoSignup(req) {
|
|||||||
}
|
}
|
||||||
const clientModel = {
|
const clientModel = {
|
||||||
client_name: name,
|
client_name: name,
|
||||||
client_id: serviceName,
|
|
||||||
scope: req.scopes,
|
scope: req.scopes,
|
||||||
client_secret: secret(),
|
client_secret: secret(),
|
||||||
redirect_uris: null,
|
redirect_uris: null,
|
||||||
grant_types: ['authorization_code', 'refresh_token'],
|
grant_types: ['authorization_code', 'refresh_token'],
|
||||||
|
owner: serviceName,
|
||||||
};
|
};
|
||||||
if (req.frontend) {
|
if (req.frontend) {
|
||||||
clientModel.redirect_uris = [req.redirectUri];
|
clientModel.redirect_uris = [req.redirectUri];
|
||||||
@ -108,23 +126,20 @@ export async function hydraAutoSignup(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ret = {
|
const ret = {
|
||||||
clientID: serviceName,
|
|
||||||
secret: secret(),
|
secret: secret(),
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
const resp = await hydraAdmin.listOAuth2Clients(undefined, undefined, undefined, serviceName);
|
||||||
await hydraAdmin.getOAuth2Client(serviceName);
|
|
||||||
try {
|
let client;
|
||||||
console.log(`Updated client ${name}`);
|
if (resp.data.length <= 0) {
|
||||||
await hydraAdmin.updateOAuth2Client(serviceName, clientModel);
|
client = await hydraAdmin.createOAuth2Client(clientModel);
|
||||||
} catch (e) {
|
} else {
|
||||||
// noinspection ExceptionCaughtLocallyJS
|
client = resp.data[0];
|
||||||
throw e;
|
await hydraAdmin.setOAuth2Client(client.client_id, clientModel);
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log(`Created client ${name}`);
|
|
||||||
await hydraAdmin.createOAuth2Client(clientModel);
|
|
||||||
}
|
}
|
||||||
|
ret.clientID = client.client_id;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,16 +63,16 @@ func (b *Build) ToProto() (*peridotpb.Build, error) {
|
|||||||
var ir []*peridotpb.ImportRevision
|
var ir []*peridotpb.ImportRevision
|
||||||
|
|
||||||
if b.TaskResponse.Valid && b.TaskStatus == peridotpb.TaskStatus_TASK_STATUS_SUCCEEDED {
|
if b.TaskResponse.Valid && b.TaskStatus == peridotpb.TaskStatus_TASK_STATUS_SUCCEEDED {
|
||||||
anyResponse := anypb.Any{}
|
anyResponse := &anypb.Any{}
|
||||||
err := protojson.Unmarshal(b.TaskResponse.JSONText, &anyResponse)
|
err := protojson.Unmarshal(b.TaskResponse.JSONText, anyResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if anyResponse.TypeUrl == "type.googleapis.com/resf.peridot.v1.ModuleBuildTask" {
|
if anyResponse.TypeUrl == "type.googleapis.com/resf.peridot.v1.ModuleBuildTask" {
|
||||||
taskResponse := peridotpb.ModuleBuildTask{}
|
taskResponse := &peridotpb.ModuleBuildTask{}
|
||||||
|
|
||||||
err = anyResponse.UnmarshalTo(&taskResponse)
|
err = anyResponse.UnmarshalTo(taskResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -81,9 +81,9 @@ func (b *Build) ToProto() (*peridotpb.Build, error) {
|
|||||||
ir = append(ir, stream.ImportRevision)
|
ir = append(ir, stream.ImportRevision)
|
||||||
}
|
}
|
||||||
} else if anyResponse.TypeUrl == "type.googleapis.com/resf.peridot.v1.SubmitBuildTask" {
|
} else if anyResponse.TypeUrl == "type.googleapis.com/resf.peridot.v1.SubmitBuildTask" {
|
||||||
taskResponse := peridotpb.SubmitBuildTask{}
|
taskResponse := &peridotpb.SubmitBuildTask{}
|
||||||
|
|
||||||
err = anyResponse.UnmarshalTo(&taskResponse)
|
err = anyResponse.UnmarshalTo(taskResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -112,6 +112,10 @@ func (a *Access) ListBuilds(filters *peridotpb.BuildFilters, projectId string, p
|
|||||||
if filters == nil {
|
if filters == nil {
|
||||||
filters = &peridotpb.BuildFilters{}
|
filters = &peridotpb.BuildFilters{}
|
||||||
}
|
}
|
||||||
|
var packageName *string
|
||||||
|
if filters.PackageName != nil {
|
||||||
|
packageName = &filters.PackageName.Value
|
||||||
|
}
|
||||||
|
|
||||||
var ret models.Builds
|
var ret models.Builds
|
||||||
err := a.query.Select(
|
err := a.query.Select(
|
||||||
@ -135,11 +139,13 @@ func (a *Access) ListBuilds(filters *peridotpb.BuildFilters, projectId string, p
|
|||||||
where
|
where
|
||||||
b.project_id = $1
|
b.project_id = $1
|
||||||
and ($2 :: int is null or $2 :: int = 0 or t.status = $2 :: int)
|
and ($2 :: int is null or $2 :: int = 0 or t.status = $2 :: int)
|
||||||
|
and ($3 :: text is null or $3 :: text = '' or p.name = $3 :: text)
|
||||||
order by b.created_at desc
|
order by b.created_at desc
|
||||||
limit $3 offset $4
|
limit $4 offset $5
|
||||||
`,
|
`,
|
||||||
projectId,
|
projectId,
|
||||||
filters.Status,
|
filters.Status,
|
||||||
|
packageName,
|
||||||
limit,
|
limit,
|
||||||
utils.GetOffset(page, limit),
|
utils.GetOffset(page, limit),
|
||||||
)
|
)
|
||||||
|
@ -199,6 +199,8 @@ message BuildFilters {
|
|||||||
// The status filter only returns builds that
|
// The status filter only returns builds that
|
||||||
// has the given status
|
// has the given status
|
||||||
TaskStatus status = 1;
|
TaskStatus status = 1;
|
||||||
|
|
||||||
|
google.protobuf.StringValue package_name = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListBuildsRequest {
|
message ListBuildsRequest {
|
||||||
|
@ -48,7 +48,7 @@ export default async function run(webpackConfig) {
|
|||||||
const envPublicUrl = process.env['PERIDOT_FRONTEND_HTTP_PUBLIC_URL'];
|
const envPublicUrl = process.env['PERIDOT_FRONTEND_HTTP_PUBLIC_URL'];
|
||||||
const frontendUrl = process.env['RESF_NS'] ? envPublicUrl : devFrontendUrl;
|
const frontendUrl = process.env['RESF_NS'] ? envPublicUrl : devFrontendUrl;
|
||||||
|
|
||||||
const wellKnown = await hydraPublic.discoverOpenIDConfiguration();
|
const wellKnown = await hydraPublic.discoverOidcConfiguration();
|
||||||
const hdr = await hydraAutoSignup({
|
const hdr = await hydraAutoSignup({
|
||||||
name: 'Peridot',
|
name: 'Peridot',
|
||||||
client: 'peridot',
|
client: 'peridot',
|
||||||
|
Loading…
Reference in New Issue
Block a user