mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove last usage of legacy global secretsStore
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4ff4b5e7af
commit
1d431666f3
@ -1,12 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { asLegacyGlobalForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
|
||||||
import secretStoreInjectable from "./store.injectable";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `di.inject(secretStoreInjectable)` instead
|
|
||||||
*/
|
|
||||||
export const secretStore = asLegacyGlobalForExtensionApi(secretStoreInjectable);
|
|
||||||
@ -11,25 +11,38 @@ import { disposeOnUnmount, observer } from "mobx-react";
|
|||||||
import { DrawerItem, DrawerTitle } from "../drawer";
|
import { DrawerItem, DrawerTitle } from "../drawer";
|
||||||
import { Input } from "../input";
|
import { Input } from "../input";
|
||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
import { Notifications } from "../notifications";
|
import type { ShowNotification } from "../notifications";
|
||||||
import { base64, toggle } from "../../utils";
|
import { base64, toggle } from "../../utils";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { secretStore } from "./legacy-store";
|
|
||||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||||
import { Secret } from "../../../common/k8s-api/endpoints";
|
import { Secret } from "../../../common/k8s-api/endpoints";
|
||||||
import { KubeObjectMeta } from "../kube-object-meta";
|
import { KubeObjectMeta } from "../kube-object-meta";
|
||||||
import logger from "../../../common/logger";
|
import type { Logger } from "../../../common/logger";
|
||||||
|
import type { SecretStore } from "./store";
|
||||||
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
|
import loggerInjectable from "../../../common/logger.injectable";
|
||||||
|
import secretStoreInjectable from "./store.injectable";
|
||||||
|
import showSuccessNotificationInjectable from "../notifications/show-success-notification.injectable";
|
||||||
|
import type { ShowCheckedErrorNotification } from "../notifications/show-checked-error.injectable";
|
||||||
|
import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable";
|
||||||
|
|
||||||
export interface SecretDetailsProps extends KubeObjectDetailsProps<Secret> {
|
export interface SecretDetailsProps extends KubeObjectDetailsProps<Secret> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Dependencies {
|
||||||
|
secretStore: SecretStore;
|
||||||
|
logger: Logger;
|
||||||
|
showSuccessNotification: ShowNotification;
|
||||||
|
showCheckedErrorNotification: ShowCheckedErrorNotification;
|
||||||
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class SecretDetails extends React.Component<SecretDetailsProps> {
|
class NonInjectedSecretDetails extends React.Component<SecretDetailsProps & Dependencies> {
|
||||||
@observable isSaving = false;
|
@observable isSaving = false;
|
||||||
@observable data: Partial<Record<string, string>> = {};
|
@observable data: Partial<Record<string, string>> = {};
|
||||||
@observable revealSecret = observable.set<string>();
|
@observable revealSecret = observable.set<string>();
|
||||||
|
|
||||||
constructor(props: SecretDetailsProps) {
|
constructor(props: SecretDetailsProps & Dependencies) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
@ -53,10 +66,10 @@ export class SecretDetails extends React.Component<SecretDetailsProps> {
|
|||||||
this.isSaving = true;
|
this.isSaving = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await secretStore.update(secret, { ...secret, data: this.data });
|
await this.props.secretStore.update(secret, { ...secret, data: this.data });
|
||||||
Notifications.ok("Secret successfully updated.");
|
this.props.showSuccessNotification("Secret successfully updated.");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Notifications.checkedError(err, "Unknown error occured while updating the secret");
|
this.props.showCheckedErrorNotification(err, "Unknown error occured while updating the secret");
|
||||||
}
|
}
|
||||||
this.isSaving = false;
|
this.isSaving = false;
|
||||||
};
|
};
|
||||||
@ -134,7 +147,7 @@ export class SecretDetails extends React.Component<SecretDetailsProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { object: secret } = this.props;
|
const { object: secret, logger } = this.props;
|
||||||
|
|
||||||
if (!secret) {
|
if (!secret) {
|
||||||
return null;
|
return null;
|
||||||
@ -157,3 +170,13 @@ export class SecretDetails extends React.Component<SecretDetailsProps> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const SecretDetails = withInjectables<Dependencies, SecretDetailsProps>(NonInjectedSecretDetails, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
...props,
|
||||||
|
logger: di.inject(loggerInjectable),
|
||||||
|
secretStore: di.inject(secretStoreInjectable),
|
||||||
|
showCheckedErrorNotification: di.inject(showCheckedErrorNotificationInjectable),
|
||||||
|
showSuccessNotification: di.inject(showSuccessNotificationInjectable),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import { disposeOnUnmount, observer } from "mobx-react";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
import { secretStore } from "../../+config-secrets/legacy-store";
|
|
||||||
import type { Secret, ServiceAccount } from "../../../../common/k8s-api/endpoints";
|
import type { Secret, ServiceAccount } from "../../../../common/k8s-api/endpoints";
|
||||||
import { DrawerItem, DrawerTitle } from "../../drawer";
|
import { DrawerItem, DrawerTitle } from "../../drawer";
|
||||||
import { Icon } from "../../icon";
|
import { Icon } from "../../icon";
|
||||||
@ -18,23 +17,32 @@ import type { KubeObjectDetailsProps } from "../../kube-object-details";
|
|||||||
import { KubeObjectMeta } from "../../kube-object-meta";
|
import { KubeObjectMeta } from "../../kube-object-meta";
|
||||||
import { Spinner } from "../../spinner";
|
import { Spinner } from "../../spinner";
|
||||||
import { ServiceAccountsSecret } from "./secret";
|
import { ServiceAccountsSecret } from "./secret";
|
||||||
import { getDetailsUrl } from "../../kube-detail-params";
|
import type { SecretStore } from "../../+config-secrets/store";
|
||||||
|
import type { GetDetailsUrl } from "../../kube-detail-params/get-details-url.injectable";
|
||||||
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
|
import getDetailsUrlInjectable from "../../kube-detail-params/get-details-url.injectable";
|
||||||
|
import secretStoreInjectable from "../../+config-secrets/store.injectable";
|
||||||
|
|
||||||
export interface ServiceAccountsDetailsProps extends KubeObjectDetailsProps<ServiceAccount> {
|
export interface ServiceAccountsDetailsProps extends KubeObjectDetailsProps<ServiceAccount> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const defensiveLoadSecretIn = (namespace: string) => (
|
interface Dependencies {
|
||||||
({ name }: { name: string }) => (
|
secretStore: SecretStore;
|
||||||
secretStore.load({ name, namespace })
|
getDetailsUrl: GetDetailsUrl;
|
||||||
.catch(() => name)
|
}
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetailsProps> {
|
class NonInjectedServiceAccountsDetails extends React.Component<ServiceAccountsDetailsProps & Dependencies> {
|
||||||
readonly secrets = observable.array<Secret | string>();
|
readonly secrets = observable.array<Secret | string>();
|
||||||
readonly imagePullSecrets = observable.array<Secret | string>();
|
readonly imagePullSecrets = observable.array<Secret | string>();
|
||||||
|
|
||||||
|
private defensiveLoadSecretIn = (namespace: string) => (
|
||||||
|
({ name }: { name: string }) => (
|
||||||
|
this.props.secretStore.load({ name, namespace })
|
||||||
|
.catch(() => name)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount(): void {
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
autorun(async () => {
|
autorun(async () => {
|
||||||
@ -50,7 +58,7 @@ export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetai
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defensiveLoadSecret = defensiveLoadSecretIn(namespace);
|
const defensiveLoadSecret = this.defensiveLoadSecretIn(namespace);
|
||||||
|
|
||||||
const secretLoaders = Promise.all(serviceAccount.getSecrets().map(defensiveLoadSecret));
|
const secretLoaders = Promise.all(serviceAccount.getSecrets().map(defensiveLoadSecret));
|
||||||
const imagePullSecretLoaders = Promise.all(serviceAccount.getImagePullSecrets().map(defensiveLoadSecret));
|
const imagePullSecretLoaders = Promise.all(serviceAccount.getImagePullSecrets().map(defensiveLoadSecret));
|
||||||
@ -108,7 +116,7 @@ export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetai
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link key={secret.getId()} to={getDetailsUrl(secret.selfLink)}>
|
<Link key={secret.getId()} to={this.props.getDetailsUrl(secret.selfLink)}>
|
||||||
{secret.getName()}
|
{secret.getName()}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
@ -116,7 +124,7 @@ export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetai
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { object: serviceAccount } = this.props;
|
const { object: serviceAccount, secretStore } = this.props;
|
||||||
|
|
||||||
if (!serviceAccount) {
|
if (!serviceAccount) {
|
||||||
return null;
|
return null;
|
||||||
@ -150,3 +158,11 @@ export class ServiceAccountsDetails extends React.Component<ServiceAccountsDetai
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ServiceAccountsDetails = withInjectables<Dependencies, ServiceAccountsDetailsProps>(NonInjectedServiceAccountsDetails, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
...props,
|
||||||
|
getDetailsUrl: di.inject(getDetailsUrlInjectable),
|
||||||
|
secretStore: di.inject(secretStoreInjectable),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user