Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaianirh committed May 13, 2024
2 parents 9a14031 + ae115a9 commit e5edaa0
Show file tree
Hide file tree
Showing 412 changed files with 30,827 additions and 28,896 deletions.
4 changes: 4 additions & 0 deletions INTERNATIONALIZATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ To add support for a new language to OpenShift:
1. Look up the [ISO 639-1 code](https://www.loc.gov/standards/iso639-2/php/code_list.php) for the new language.
2. Add the new language code to `./frontend/i18n-scripts/languages.sh`
3. Update the language switcher component (`./frontend/public/components/modals/language-preferences-modal.tsx`) to support the new language if translations are available.
4. Update the OCP UI Project Template to include the new laguage(s) in the Phrase TMS portal. Refer to the [Phrase Project Templates ](https://support.phrase.com/hc/en-us/articles/5709647439772-Project-Templates-TMS) on how to update the Project Template. You must have Phrase project owner permissions to perform this task.

#### Utilities
We have added various scripts to help us automate internationalization-related tasks in OpenShift.
Expand All @@ -119,3 +120,6 @@ For more information, please review the [README](./frontend/i18n-scripts/README.

#### Testing
We test that internationalization is working for various pages and components using the [i18next-pseudo](https://github.com/MattBoatman/i18next-pseudo) JavaScript library, which returns translated strings in "pseudolocalization" format. Our Cypress custom commands [cy.isPseudoLocalized()](https://github.com/openshift/console/blob/9c930b7b411f5e88f2f890639159e09bdadb78dc/frontend/packages/integration-tests-cypress/support/i18n.ts#L45) and [cy.testI18n()](https://github.com/openshift/console/blob/9c930b7b411f5e88f2f890639159e09bdadb78dc/frontend/packages/integration-tests-cypress/support/i18n.ts#L13) append query params to URLs to invoke "pseudolocalization" and are used in various test suites such as [pseudolocalization.cy.ts](https://github.com/openshift/console/blob/175a6a274204bbe44def1963daf572e4463c36f9/frontend/packages/integration-tests-cypress/tests/i18n/pseudolocalization.cy.ts#L27) to verify strings in the masthead, dashboard, navigation menu, list views, and detail pages are translated.

#### Supported Languages representation
Supported languages are represented using the ISO 639-1 Code defined in `frontend/packages/console-app/src/components/user-preferences/language/const.ts` with the exception of Chinese. While locale directories for Chinese still follow the ISO 639-1 Code format, the region code is also included to distinguish the supported simplified Chinese from other variants.
41 changes: 27 additions & 14 deletions cmd/bridge/config/auth/authoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/rest"
"k8s.io/klog"
"k8s.io/klog/v2"

"github.com/openshift/console/cmd/bridge/config/session"
"github.com/openshift/console/pkg/auth"
Expand All @@ -29,6 +29,7 @@ type AuthOptions struct {
ClientSecret string
ClientSecretFilePath string
CAFilePath string
OCLoginCommand string

ExtraScopes flagutil.StringSliceFlag

Expand All @@ -43,10 +44,11 @@ type CompletedOptions struct {
type completedOptions struct {
AuthType string

IssuerURL *url.URL
ClientID string
ClientSecret string
CAFilePath string
IssuerURL *url.URL
ClientID string
ClientSecret string
CAFilePath string
OCLoginCommand string

ExtraScopes []string

Expand All @@ -65,6 +67,7 @@ func (c *AuthOptions) AddFlags(fs *flag.FlagSet) {
fs.StringVar(&c.ClientSecret, "user-auth-oidc-client-secret", "", "The OIDC OAuth2 Client Secret.")
fs.StringVar(&c.ClientSecretFilePath, "user-auth-oidc-client-secret-file", "", "File containing the OIDC OAuth2 Client Secret.")
fs.StringVar(&c.CAFilePath, "user-auth-oidc-ca-file", "", "Path to a PEM file for the OIDC/OAuth2 issuer CA.")
fs.StringVar(&c.OCLoginCommand, "user-auth-oidc-oc-login-command", "", "External OIDC OC login command which will be displayed in the console 'Copy Login Command' dialog.")

fs.Var(&c.ExtraScopes, "user-auth-oidc-token-scopes", "Comma-separated list of extra scopes to request ID tokens with")

Expand All @@ -79,6 +82,7 @@ func (c *AuthOptions) ApplyConfig(config *serverconfig.Auth) {
serverconfig.SetIfUnset(&c.ClientSecretFilePath, config.ClientSecretFile)
serverconfig.SetIfUnset(&c.CAFilePath, config.OAuthEndpointCAFile)
serverconfig.SetIfUnset(&c.LogoutRedirect, config.LogoutRedirect)
serverconfig.SetIfUnset(&c.OCLoginCommand, config.OIDCOCLoginCommand)

if c.InactivityTimeoutSeconds == 0 {
c.InactivityTimeoutSeconds = config.InactivityTimeoutSeconds
Expand Down Expand Up @@ -111,6 +115,7 @@ func (c *AuthOptions) Complete() (*CompletedOptions, error) {
ExtraScopes: c.ExtraScopes,
CAFilePath: c.CAFilePath,
InactivityTimeoutSeconds: c.InactivityTimeoutSeconds,
OCLoginCommand: c.OCLoginCommand,
}

if len(c.IssuerURL) > 0 {
Expand Down Expand Up @@ -174,6 +179,10 @@ func (c *AuthOptions) Validate() []error {
errs = append(errs, flags.NewInvalidFlagError("user-auth-oidc-token-scopes", "cannot be used with --user-auth=\"openshift\""))
}

if len(c.OCLoginCommand) != 0 {
errs = append(errs, flags.NewInvalidFlagError("user-auth-oidc-oc-login-command", "cannot be used with --user-auth=\"openshift\""))
}

case "oidc":
if len(c.IssuerURL) == 0 {
errs = append(errs, fmt.Errorf("--user-auth-oidc-issuer-url must be set if --user-auth=oidc"))
Expand All @@ -198,7 +207,6 @@ func (c *completedOptions) ApplyTo(
sessionConfig *session.CompletedOptions,
) error {
srv.InactivityTimeout = c.InactivityTimeoutSeconds
srv.LogoutRedirect = c.LogoutRedirectURL

var err error
srv.Authenticator, err = c.getAuthenticator(
Expand Down Expand Up @@ -234,7 +242,7 @@ func (c *completedOptions) getAuthenticator(
authLoginSuccessEndpoint = proxy.SingleJoiningSlash(baseURL.String(), server.AuthLoginSuccessEndpoint)
oidcClientSecret = c.ClientSecret
// Abstraction leak required by NewAuthenticator. We only want the browser to send the auth token for paths starting with basePath/api.
cookiePath = proxy.SingleJoiningSlash(baseURL.Path, "/api/")
cookiePath = proxy.SingleJoiningSlash(baseURL.Path, "/api")
refererPath = baseURL.String()
useSecureCookies = baseURL.Scheme == "https"
)
Expand All @@ -257,13 +265,14 @@ func (c *completedOptions) getAuthenticator(

// Config for logging into console.
oidcClientConfig := &auth.Config{
AuthSource: authSource,
IssuerURL: userAuthOIDCIssuerURL.String(),
IssuerCA: c.CAFilePath,
ClientID: c.ClientID,
ClientSecret: oidcClientSecret,
RedirectURL: proxy.SingleJoiningSlash(baseURL.String(), server.AuthLoginCallbackEndpoint),
Scope: scopes,
AuthSource: authSource,
IssuerURL: userAuthOIDCIssuerURL.String(),
IssuerCA: c.CAFilePath,
ClientID: c.ClientID,
ClientSecret: oidcClientSecret,
RedirectURL: proxy.SingleJoiningSlash(baseURL.String(), server.AuthLoginCallbackEndpoint),
Scope: scopes,
OCLoginCommand: c.OCLoginCommand,

// Use the k8s CA file for OpenShift OAuth metadata discovery.
// This might be different than IssuerCA.
Expand All @@ -281,6 +290,10 @@ func (c *completedOptions) getAuthenticator(
K8sConfig: k8sClientConfig,
}

if c.LogoutRedirectURL != nil {
oidcClientConfig.LogoutRedirectOverride = c.LogoutRedirectURL.String()
}

authenticator, err := auth.NewAuthenticator(context.Background(), oidcClientConfig)
if err != nil {
klog.Fatalf("Error initializing authenticator: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
oscrypto "github.com/openshift/library-go/pkg/crypto"

"k8s.io/client-go/rest"
"k8s.io/klog"
klog "k8s.io/klog/v2"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion dynamic-demo-plugin/.yarnrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
# yarn lockfile v1


yarn-path "../frontend/.yarn/releases/yarn-1.22.15.js"
yarn-path "../frontend/.yarn/releases/yarn-1.22.22.js"
network-timeout "600000"
disable-self-update-check true
1 change: 1 addition & 0 deletions dynamic-demo-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"react-i18next": "^11.7.3",
"react-router": "5.3.x",
"react-router-dom": "5.3.x",
"react-router-dom-v5-compat": "^6.11.2",
"style-loader": "0.23.1",
"ts-loader": "9.x",
"ts-node": "10.9.2",
Expand Down
12 changes: 3 additions & 9 deletions dynamic-demo-plugin/src/components/ExampleNamespacedPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { match as RMatch } from 'react-router-dom';
import { useParams } from 'react-router-dom-v5-compat';
import {
Card,
CardBody,
Expand Down Expand Up @@ -39,8 +39,8 @@ const NamespacePageContent = ({ namespace }: { namespace?: string }) => {
);
};

export const ExampleNamespacedPage: React.FC<ExampleNamespacedPageProps> = ({ match }) => {
const { ns } = match?.params;
export const ExampleNamespacedPage: React.FC = () => {
const { ns } = useParams<'ns'>();
const activeNamespace = ns || 'all-namespaces';

return (
Expand All @@ -50,9 +50,3 @@ export const ExampleNamespacedPage: React.FC<ExampleNamespacedPageProps> = ({ ma
</>
);
};

type ExampleNamespacedPageProps = {
match: RMatch<{
ns?: string;
}>;
};
16 changes: 12 additions & 4 deletions dynamic-demo-plugin/src/utils/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,27 @@ export const eventListener = async (eventType: string, properties?: any) => {
},
};
switch (eventType) {
case 'identify':
case 'identify': {
const { user, ...otherProperties } = properties;
const id = user.metadata.uid || `${location.host}-${user.metadata.name}`;
// With 4.15+ we can use the user object directly, but on older releases (<4.15)
// we need to extract the user object from the metadata.
// All properties are defined in the UserInfo interface and marked as optional.
const uid = user?.uid || user?.metadata?.uid;
const username = user?.username || user?.metadata?.name;
const id = uid || `${location.host}-${username}`;
// Use SHA1 hash algorithm to anonymize the user
const anonymousIdBuffer = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(id));
const anonymousIdArray = Array.from(new Uint8Array(anonymousIdBuffer));
const anonymousId = anonymousIdArray.map((b) => b.toString(16).padStart(2, '0')).join('');
(window as any).analytics.identify(anonymousId, otherProperties, anonymousIP);
break;
case 'page':
}
case 'page': {
(window as any).analytics.page(undefined, properties, anonymousIP);
break;
default:
}
default: {
(window as any).analytics.track(eventType, properties, anonymousIP);
}
}
};
36 changes: 18 additions & 18 deletions dynamic-demo-plugin/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"@openshift-console/dynamic-plugin-sdk-webpack@file:../frontend/packages/console-dynamic-plugin-sdk/dist/webpack":
version "0.0.0-fixed"
dependencies:
"@openshift/dynamic-plugin-sdk-webpack" "^4.0.1"
"@openshift/dynamic-plugin-sdk-webpack" "^4.0.2"
ajv "^6.12.3"
chalk "2.4.x"
comment-json "4.x"
Expand Down Expand Up @@ -156,10 +156,10 @@
sanitize-html "^2.3.2"
showdown "1.8.6"

"@openshift/dynamic-plugin-sdk-webpack@^4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@openshift/dynamic-plugin-sdk-webpack/-/dynamic-plugin-sdk-webpack-4.0.1.tgz#5d9956f12234fd50854868744b947a4a1009406a"
integrity sha512-ZlY57t1WIl8B8XNPoq+CuU/+Ll4/ZX/7IO/dxn+7dp1S/NUmdvgwv01mXpUcjviOUhhgWl/dK2WvCQTzz6CoZg==
"@openshift/dynamic-plugin-sdk-webpack@^4.0.2":
version "4.0.2"
resolved "https://registry.yarnpkg.com/@openshift/dynamic-plugin-sdk-webpack/-/dynamic-plugin-sdk-webpack-4.0.2.tgz#0304911c9c27ecff7ba5d2df5ca24f781fd445ec"
integrity sha512-zgRLt9WM63aGYygrQEtd8QtWoP5zYWr67kzlRKzGcHeRbWDgiHnY7FOiDUM04bYeb4lL6qv3iErEnrtvVpyh0Q==
dependencies:
lodash "^4.17.21"
semver "^7.3.7"
Expand Down Expand Up @@ -204,10 +204,10 @@
resolved "https://registry.yarnpkg.com/@patternfly/react-tokens/-/react-tokens-5.1.1.tgz#098b70b4ed4d05217004395abc7395a46acc9abe"
integrity sha512-cHuNkzNA9IY9aDwfjSEkitQoVEvRhOJRKhH0yIRlRByEkbdoV9jJZ9xj20hNShE+bxmNuom+MCTQSkpkN1bV8A==

"@remix-run/router@1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.9.0.tgz#9033238b41c4cbe1e961eccb3f79e2c588328cf6"
integrity sha512-bV63itrKBC0zdT27qYm6SDZHlkXwFL1xMBuhkn+X7l0+IIhNaH5wuuvZKp6eKhCD4KFhujhfhCT1YxXW6esUIA==
"@remix-run/router@1.6.2":
version "1.6.2"
resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.6.2.tgz#bbe75f8c59e0b7077584920ce2cc76f8f354934d"
integrity sha512-LzqpSrMK/3JBAVBI9u3NWtOhWNw5AMQfrUFYB0+bDHTSw17z++WJLsPsxAuK+oSddsxk4d7F/JcdDPM1M5YAhA==

"@tsconfig/node10@^1.0.7":
version "1.0.9"
Expand Down Expand Up @@ -3027,12 +3027,12 @@ react-redux@7.2.2:
react-is "^16.13.1"

react-router-dom-v5-compat@^6.11.2:
version "6.16.0"
resolved "https://registry.yarnpkg.com/react-router-dom-v5-compat/-/react-router-dom-v5-compat-6.16.0.tgz#3033241ce206297bac95da1e7f0038089abb933a"
integrity sha512-MfjB9qYZVnWUEHENFa+XpVU5qbDPkqpGvjaF/8nHCnCkfy5pxYajrZrmRmaR4v6Ehtu7GAx59JFTSoQGhLu1+g==
version "6.11.2"
resolved "https://registry.yarnpkg.com/react-router-dom-v5-compat/-/react-router-dom-v5-compat-6.11.2.tgz#832a6e7aeef05f3cac12c0147b7c2c11a1540e50"
integrity sha512-3EKqtVKqpHOdUgGJiDfPJpsvZpCF+fPw3NO1mFU8eovOKvuksy/Rz7/FWR2e/FknIOOz4wdomx3w046M3aXkNg==
dependencies:
history "^5.3.0"
react-router "6.16.0"
react-router "6.11.2"

react-router-dom@5.3.x:
version "5.3.4"
Expand Down Expand Up @@ -3062,12 +3062,12 @@ react-router@5.3.4, react-router@5.3.x:
tiny-invariant "^1.0.2"
tiny-warning "^1.0.0"

react-router@6.16.0:
version "6.16.0"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.16.0.tgz#abbf3d5bdc9c108c9b822a18be10ee004096fb81"
integrity sha512-VT4Mmc4jj5YyjpOi5jOf0I+TYzGpvzERy4ckNSvSh2RArv8LLoCxlsZ2D+tc7zgjxcY34oTz2hZaeX5RVprKqA==
react-router@6.11.2:
version "6.11.2"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.11.2.tgz#006301c4da1a173d7ad76b7ecd2da01b9dd3837a"
integrity sha512-74z9xUSaSX07t3LM+pS6Un0T55ibUE/79CzfZpy5wsPDZaea1F8QkrsiyRnA2YQ7LwE/umaydzXZV80iDCPkMg==
dependencies:
"@remix-run/router" "1.9.0"
"@remix-run/router" "1.6.2"

react-side-effect@^2.1.0:
version "2.1.1"
Expand Down
3 changes: 2 additions & 1 deletion examples/run-bridge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ set -exuo pipefail
./bin/bridge \
--base-address=http://localhost:9000 \
--ca-file=examples/ca.crt \
--k8s-auth=openshift \
--k8s-auth=bearer-token \
--k8s-auth-bearer-token="$(oc whoami --show-token)" \
--k8s-mode=off-cluster \
--k8s-mode-off-cluster-endpoint="$(oc whoami --show-server)" \
--k8s-mode-off-cluster-skip-verify-tls=true \
Expand Down

0 comments on commit e5edaa0

Please sign in to comment.