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