From cd77f7d37d31c7f3701dfb47adeda051a5618fbc Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Wed, 25 Oct 2023 02:23:16 +0000 Subject: [PATCH 1/3] token-insights: change .body.pf-c-content* into .pf-c-content > .body* --- src/containers/token/token-insights.tsx | 230 ++++++++++++------------ 1 file changed, 115 insertions(+), 115 deletions(-) diff --git a/src/containers/token/token-insights.tsx b/src/containers/token/token-insights.tsx index d871a01105..2dfcf45d4a 100644 --- a/src/containers/token/token-insights.tsx +++ b/src/containers/token/token-insights.tsx @@ -52,134 +52,134 @@ class TokenInsights extends React.Component { }" --fail --silent --show-error --output /dev/null`; return ( - + <> this.closeAlert(i)} />
-
-

{t`Connect Private Automation Hub`}

-

- - Use the Server URL below to sync certified collections to the - Red Hat Certified repository in your private Automation Hub. If - you wish to sync validated content, you can add a remote with a - server url pointed to the validated repo. - -

-
-
-

{t`Connect the ansible-galaxy client`}

-

- - Documentation on how to configure the{' '} - ansible-galaxy client can be found{' '} - - here - - . Use the following parameters to configure the client. - -

-
-
-

{t`Offline token`}

-

- - Use this token to authenticate clients that need to download - content from Automation Hub. This is a secret token used to - protect your content. Store your API token in a secure location. - -

- {tokenData ? ( -
- {tokenData.refresh_token} -
- ) : ( -
- -
- )} -
- +
+
+

{t`Connect Private Automation Hub`}

+

- The token will expire after 30 days of inactivity. Run the - command below periodically to prevent your token from - expiring. + Use the Server URL below to sync certified collections to the + Red Hat Certified repository in your private Automation Hub. + If you wish to sync validated content, you can add a remote + with a server url pointed to the validated repo. - - - {renewTokenCmd} - -

-

{t`Manage tokens`}

- - To revoke a token or see all of your tokens, visit the{' '} - - offline API token management - {' '} - page. - -
-
-

{t`Server URL`}

-

- - Use this URL to configure the API endpoints that clients need to - download certified content from Automation Hub. Synclists are - deprecated in AAP 2.4 and will be removed in a future release, - instead use client-side requirements.yml, see AAP 2.4 - documentation. - -

- - {getRepoURL('published', true)} - -
-
-

{t`SSO URL`}

-

- - Use this URL to configure the authentication URLs that clients - need to download content from Automation Hub. - -

- - https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token - -
-
-

{t`CRC public key`}

-

+

+
+
+

{t`Connect the ansible-galaxy client`}

+

+ + Documentation on how to configure the{' '} + ansible-galaxy client can be found{' '} + + here + + . Use the following parameters to configure the client. + +

+
+
+

{t`Offline token`}

+

+ + Use this token to authenticate clients that need to download + content from Automation Hub. This is a secret token used to + protect your content. Store your API token in a secure + location. + +

+ {tokenData ? ( +
+ {tokenData.refresh_token} +
+ ) : ( +
+ +
+ )} +
+ + + The token will expire after 30 days of inactivity. Run the + command below periodically to prevent your token from + expiring. + + + + {renewTokenCmd} + +
+

{t`Manage tokens`}

- We use a number of keys to sign our software packages. The - necessary public keys are included in the relevant products and - are used to automatically verify software updates. You can also - verify the packages manually using the keys on this page. More - information can be found{' '} + To revoke a token or see all of your tokens, visit the{' '} - here. - + offline API token management + {' '} + page. -

+
+
+

{t`Server URL`}

+

+ + Use this URL to configure the API endpoints that clients need + to download certified content from Automation Hub. Synclists + are deprecated in AAP 2.4 and will be removed in a future + release, instead use client-side requirements.yml, see AAP 2.4 + documentation. + +

+ + {getRepoURL('published', true)} + +
+
+

{t`SSO URL`}

+

+ + Use this URL to configure the authentication URLs that clients + need to download content from Automation Hub. + +

+ + https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token + +
+
+

{t`CRC public key`}

+

+ + We use a number of keys to sign our software packages. The + necessary public keys are included in the relevant products + and are used to automatically verify software updates. You can + also verify the packages manually using the keys on this page. + More information can be found{' '} + + here. + + +

+
-
+ ); } From 32c1dd4cafcc9cebf19243742b7d0ce805adf354 Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Sat, 9 Sep 2023 20:19:19 +0000 Subject: [PATCH 2/3] Token insights - restore MyDistribution query, show separate synclist url No-Issue --- src/api/index.ts | 1 + src/api/my-distribution.ts | 7 +++ src/containers/token/token-insights.tsx | 83 +++++++++++++++++++++---- src/loaders/app.scss | 9 +++ 4 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 src/api/my-distribution.ts diff --git a/src/api/index.ts b/src/api/index.ts index 9fa6739c35..d35f5b28cc 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -21,6 +21,7 @@ export { GroupRoleAPI } from './group-role'; export { ImportAPI } from './import'; export { LegacyNamespaceAPI } from './legacy-namespace'; export { LegacyRoleAPI } from './legacy-role'; +export { MyDistributionAPI } from './my-distribution'; export { MyNamespaceAPI } from './my-namespace'; export { MySyncListAPI } from './my-synclist'; export { NamespaceAPI } from './namespace'; diff --git a/src/api/my-distribution.ts b/src/api/my-distribution.ts new file mode 100644 index 0000000000..6491faad68 --- /dev/null +++ b/src/api/my-distribution.ts @@ -0,0 +1,7 @@ +import { HubAPI } from './hub'; + +class API extends HubAPI { + apiPath = this.getUIPath('my-distributions/'); +} + +export const MyDistributionAPI = new API(); diff --git a/src/containers/token/token-insights.tsx b/src/containers/token/token-insights.tsx index 2dfcf45d4a..5613984126 100644 --- a/src/containers/token/token-insights.tsx +++ b/src/containers/token/token-insights.tsx @@ -1,6 +1,7 @@ import { Trans, t } from '@lingui/macro'; -import { Button, ClipboardCopyVariant } from '@patternfly/react-core'; +import { Alert, Button, ClipboardCopyVariant } from '@patternfly/react-core'; import React from 'react'; +import { MyDistributionAPI } from 'src/api'; import { AlertList, AlertType, @@ -10,11 +11,13 @@ import { closeAlertMixin, } from 'src/components'; import { AppContext } from 'src/loaders/app-context'; -import { RouteProps, withRouter } from 'src/utilities'; +import { RouteProps, errorMessage, withRouter } from 'src/utilities'; import { getRepoURL } from 'src/utilities'; interface IState { - tokenData: { + alerts: AlertType[]; + synclistBasePath?: string; + tokenData?: { access_token: string; expires_in: number; id_token: string; @@ -24,7 +27,6 @@ interface IState { session_state: string; token_type: string; }; - alerts: AlertType[]; } class TokenInsights extends React.Component { @@ -32,21 +34,58 @@ class TokenInsights extends React.Component { super(props); this.state = { - tokenData: undefined, alerts: [], + synclistBasePath: null, + tokenData: null, }; } componentDidMount() { + this.getTokenData(); + this.getSynclistBasePath(); + } + + getTokenData() { + if (!window.insights?.chrome) { + // outside insights platform + return; + } + // this function will fail if chrome.auth.doOffline() hasn't been called // so it never works the first time .. loadToken() causes a reload and then it works => no error handling - window.insights.chrome.auth.getOfflineToken().then((result) => { - this.setState({ tokenData: result.data }); - }); + window.insights.chrome.auth + .getOfflineToken() + .then(({ data: tokenData }) => this.setState({ tokenData })); + } + + getSynclistBasePath() { + MyDistributionAPI.list() + .then(({ data }) => { + const syncDistro = data.data.find(({ base_path }) => + base_path.includes('synclist'), + ); + this.setState({ + synclistBasePath: syncDistro?.base_path, + }); + }) + .catch((e) => { + const { status, statusText } = e.response; + this.setState({ + synclistBasePath: null, + alerts: [ + ...this.state.alerts, + { + variant: 'danger', + title: t`Server URL could not be displayed.`, + description: errorMessage(status, statusText), + }, + ], + }); + }); } render() { - const { tokenData, alerts } = this.state; + const { alerts, synclistBasePath, tokenData } = this.state; const renewTokenCmd = `curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token -d grant_type=refresh_token -d client_id="cloud-services" -d refresh_token="${ tokenData?.refresh_token ?? '{{ user_token }}' }" --fail --silent --show-error --output /dev/null`; @@ -136,15 +175,33 @@ class TokenInsights extends React.Component {

Use this URL to configure the API endpoints that clients need - to download certified content from Automation Hub. Synclists - are deprecated in AAP 2.4 and will be removed in a future - release, instead use client-side requirements.yml, see AAP 2.4 - documentation. + to download certified content from Automation Hub.{' '}

{getRepoURL('published', true)} +

+ + Synclists are deprecated in AAP 2.4 and will be removed in a + future release, use client-side requirements.yml instead. +
+ If you're using sync toggles with AAP 2.3 or older, you + will need to use a different URL: +
+

+ {synclistBasePath ? ( + + {getRepoURL(synclistBasePath)} + + ) : ( + + )}

{t`SSO URL`}

diff --git a/src/loaders/app.scss b/src/loaders/app.scss index 7110824922..7325d4a8c7 100644 --- a/src/loaders/app.scss +++ b/src/loaders/app.scss @@ -65,3 +65,12 @@ body, padding-left: 0; } } + +// token-insights: inline alert inside pf-c-content has big title and extra margin +.hub-content-alert-fix { + .pf-c-alert__title { + margin: 0; + font-size: var(--pf-c-alert__title--FontSize); + font-weight: var(--pf-c-alert__title--FontWeight); + } +} From 64a2843fe634339f5a316dc29f212dfbc3feb352 Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Wed, 25 Oct 2023 02:35:08 +0000 Subject: [PATCH 3/3] token-insights: add validated --- src/containers/token/token-insights.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/containers/token/token-insights.tsx b/src/containers/token/token-insights.tsx index 5613984126..4333aed0d9 100644 --- a/src/containers/token/token-insights.tsx +++ b/src/containers/token/token-insights.tsx @@ -175,16 +175,27 @@ class TokenInsights extends React.Component {

Use this URL to configure the API endpoints that clients need - to download certified content from Automation Hub.{' '} + to download certified content from Automation + Hub.{' '}

{getRepoURL('published', true)} +

+ + Use this URL for validated content from + Automation Hub.{' '} + +

+ + {getRepoURL('validated')} +

Synclists are deprecated in AAP 2.4 and will be removed in a - future release, use client-side requirements.yml instead. + future release, use client-side requirements.yml{' '} + instead.
If you're using sync toggles with AAP 2.3 or older, you will need to use a different URL: