Skip to content

Commit 53f3ffb

Browse files
authored
feat(orchestrator): add auth requester widget (#972)
* feat(orchestrator): add auth requester widget * replaced custom capitalize with lodash * updated generated openapi * fixed report
1 parent 38372b3 commit 53f3ffb

32 files changed

Lines changed: 691 additions & 403 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-orchestrator-form-react': minor
3+
'@red-hat-developer-hub/backstage-plugin-orchestrator-form-api': minor
4+
'@red-hat-developer-hub/backstage-plugin-orchestrator-backend': minor
5+
'@red-hat-developer-hub/backstage-plugin-orchestrator-common': minor
6+
'@red-hat-developer-hub/backstage-plugin-orchestrator': minor
7+
---
8+
9+
implemented authorization widget for enabling specifying the required auth providers in the schema so the UI can pick it up from there and forward to workflow execution

workspaces/orchestrator/plugins/orchestrator-backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"express-promise-router": "^4.1.1",
8686
"fs-extra": "^10.1.0",
8787
"isomorphic-git": "^1.23.0",
88+
"lodash": "^4.17.21",
8889
"moment": "^2.29.4",
8990
"openapi-backend": "^5.10.5",
9091
"yn": "^5.0.0"

workspaces/orchestrator/plugins/orchestrator-backend/src/service/SonataFlowService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import { LoggerService } from '@backstage/backend-plugin-api';
1818

19+
import capitalize from 'lodash/capitalize';
20+
1921
import {
2022
AuthToken,
2123
extractWorkflowFormat,
@@ -109,7 +111,7 @@ export class SonataFlowService {
109111
if (args.authTokens && Array.isArray(args.authTokens)) {
110112
args.authTokens.forEach(tokenObj => {
111113
if (tokenObj.provider && tokenObj.token) {
112-
const headerKey = `X-Authorization-${tokenObj.provider}`;
114+
const headerKey = `X-${capitalize(tokenObj.provider)}-Authorization`;
113115
headers[headerKey] = String(tokenObj.token); // Ensure token is a string
114116
}
115117
});

workspaces/orchestrator/plugins/orchestrator-backend/src/service/router.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ const authorize = async (
8484
httpAuth: HttpAuthService,
8585
): Promise<AuthorizePermissionResponse> => {
8686
const credentials = await httpAuth.credentials(request);
87-
8887
const decisionResponses: AuthorizePermissionResponse[][] = await Promise.all(
8988
anyOfPermissions.map(permission =>
9089
permissionsSvc.authorize([{ permission }], {
@@ -255,7 +254,7 @@ export async function createBackendRouter(
255254

256255
const middleware = MiddlewareFactory.create({ logger, config });
257256

258-
router.use(middleware.error());
257+
router.use(middleware.error({ logAllErrors: true })); // log also openapi errors
259258

260259
return router;
261260
}
@@ -309,7 +308,7 @@ async function initRouterApi(
309308
_req: express.Request,
310309
res: express.Response,
311310
) => {
312-
console.log('validationFail', c.operation);
311+
console.log('OPENAPI validationFail', c.operation);
313312
res.status(400).json({ err: c.validation.errors });
314313
},
315314
notFound: async (_c, req: express.Request, res: express.Response) => {

workspaces/orchestrator/plugins/orchestrator-common/report.api.md

Lines changed: 342 additions & 304 deletions
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
export * from './tokenDescriptorTypes';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import { OAuthScope } from '@backstage/core-plugin-api';
17+
18+
export type ScmTokenProvider = 'gitlab' | 'github';
19+
20+
export type TokenProvider = ScmTokenProvider | 'microsoft';
21+
22+
export type AuthTokenDescriptor = {
23+
provider: TokenProvider;
24+
scope?: OAuthScope;
25+
tokenType: 'openId' | 'oauth';
26+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9b58bc9fda4bd3d2e3222fac599125372f0f5dd5
1+
61c0db002e4c6e594a5b1fccc7d54f9e81f5ca4d

workspaces/orchestrator/plugins/orchestrator-common/src/generated/api/definition.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

workspaces/orchestrator/plugins/orchestrator-common/src/generated/client/api.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,23 @@ export interface AuthToken {
5353
* @type {string}
5454
* @memberof AuthToken
5555
*/
56-
'provider': string;
56+
'provider': AuthTokenProviderEnum;
5757
/**
5858
* The auth token itself retrieved from the above specified provider name
5959
* @type {string}
6060
* @memberof AuthToken
6161
*/
6262
'token': string;
6363
}
64+
65+
export const AuthTokenProviderEnum = {
66+
Github: 'github',
67+
Gitlab: 'gitlab',
68+
Microsoft: 'microsoft'
69+
} as const;
70+
71+
export type AuthTokenProviderEnum = typeof AuthTokenProviderEnum[keyof typeof AuthTokenProviderEnum];
72+
6473
/**
6574
* The ErrorResponse object represents a common structure for handling errors in API responses. It includes essential information about the error, such as the error message and additional optional details.
6675
* @export

0 commit comments

Comments
 (0)