Skip to content

Commit b83b4fa

Browse files
committed
[#25] Add info to README about protocol events, remove feature gate
Fixes #25
1 parent 4d5c25d commit b83b4fa

File tree

4 files changed

+109
-46
lines changed

4 files changed

+109
-46
lines changed

README.md

+86
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,92 @@ Due to technical issues with generating a unique kubeConfig per cluster, when th
127127

128128
We hope to overcome this limitation in the future.
129129

130+
## Supported protocol requests
131+
132+
[Lens 4.2](https://medium.com/k8slens/lens-4-2-released-f1c3268d3f95) introduced a new __custom Lens protocol handler__. This means Lens can now respond to `lens://` URL requests made in the browser, and this extension can now support some interesting requests that enable tighter integration between Mirantis Container Cloud instances and Lens.
133+
134+
> Note that this integration is a one-way street: Container Cloud -> Lens. It does not work the other way around. _Reverse_ integration is achieved simply by making Container Cloud API requests from Lens, which is much easier to achieve, and has been used by this extension since its inception.
135+
136+
The __base URL__ for requests that this extension can respond to is:
137+
138+
```
139+
lens://extensions/@mirantis/lens-extension-cc
140+
```
141+
142+
The following APIs are currently supported by this extension, from the base URL above:
143+
144+
### Protocol - Activate cluster
145+
146+
Activates a cluster __already added__ to Lens.
147+
148+
```
149+
GET /activateCluster
150+
?cloudUrl={string}
151+
&namespace={string}
152+
&clusterName={string}
153+
&clusterId={string}
154+
```
155+
156+
- `cloudUrl`: URL to the instance, e.g. `https://container-cloud.my-company.com`
157+
- `namespace`: ID of the Container Cloud namespace containing the cluster to activate.
158+
- `clusterName`: Name of the cluster to activate.
159+
- `clusterId`: ID of the cluster (in `namespace`) to activate.
160+
161+
### Protocol - Add one cluster
162+
163+
Adds a __single__ cluster to Lens (if it hasn't already been added) by providing a pre-configured kubeConfig JSON object for the cluster. As such, this endpoint does not require the extension to perform any authentication/authorization requests. It simply stores the kubeConfig on disk and tells Lens where to find it.
164+
165+
```
166+
GET /kubeConfig
167+
?cloudUrl={string}
168+
&namespace={string}
169+
&clusterName={string}
170+
&clusterId={string}
171+
&kubeConfig={string}
172+
```
173+
174+
- `cloudUrl`: URL to the instance, e.g. `https://container-cloud.my-company.com`
175+
- `namespace`: ID of the Container Cloud namespace containing the cluster to activate.
176+
- `clusterName`: Name of the cluster to activate.
177+
- `clusterId`: ID of the cluster (in `namespace`) to activate.
178+
- `kubeConfig`: JSON-stringified, Base64-encoded kubeConfig payload.
179+
180+
### Protocol - Add multiple clusters
181+
182+
Allows the user to add __one or more__ clusters to Lens by telling the extension where to find them. Unlike [adding one cluster](#add-one-cluster), it does not automatically add any clusters to Lens. It simply triggers the extension to immediately list all available clusters, and then lets the user choose which ones to add.
183+
184+
```
185+
GET /addClusters
186+
?cloudUrl={string}
187+
&username={string}
188+
&tokens={string}
189+
[ &keycloakLogin={boolean} ]
190+
[ &namespaces={string} ]
191+
```
192+
193+
- `cloudUrl`: URL to the instance, e.g. `https://container-cloud.my-company.com`
194+
- `username`: Username associated with the `tokens`.
195+
- `tokens`: JSON-stringified, Base64-encoded OAuth2 tokens for the user.
196+
- `keycloakLogin` (Optional): `false` (default) if the instance in `cloudUrl` uses basic (username/password) authentication; `true` if the instance in `cloudUrl` uses SSO authorization.
197+
- `namespaces` (Optional): Comma-delimited list of namespace IDs to restrict the list of clusters presented by the extension (i.e. a filter on namespaces). Only clusters in these namespaces will be listed.
198+
199+
### Protocol - SSO OAuth Code
200+
201+
Allow the extension to use the system's default browser to broker an OAuth authorization code with a Keycloak client in a Container Cloud instance. This is used both for general access (to list clusters) as well as specific cluster access to generate kubeConfig files to add to Lens.
202+
203+
```
204+
GET /oauth/code
205+
?code={string}
206+
[ &state={string} ]
207+
[ &error={string} ]
208+
[ &error_description={string} ]
209+
```
210+
211+
- `code`: Temporary authorization code to exchange for API tokens.
212+
- `state` (Optional): Used to differentiate between requests for general access and specific access. The value is generated by the extension as part of the request and should come back as part of the response.
213+
- `error` (Optional): OAuth error message, if an error occurs.
214+
- `error_description` (Optional): OAuth error description, if an error occurs.
215+
130216
## FAQ
131217

132218
- Why are management clusters not selected by default?

src/cc/View.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,8 @@ export const View = function ({ extension }) {
641641

642642
<HelpColumn>
643643
<HelpContent
644-
// TRACKING: https://github.com/Mirantis/lens-extension-cc/issues/25
645644
dangerouslySetInnerHTML={{
646-
__html: strings.view.help.html(
647-
Array.isArray(extension.protocolHandlers)
648-
),
645+
__html: strings.view.help.html(),
649646
}}
650647
/>
651648
<PreferencesPanel />

src/renderer.tsx

+18-29
Original file line numberDiff line numberDiff line change
@@ -138,35 +138,24 @@ export default class ExtensionRenderer extends LensRendererExtension {
138138
};
139139

140140
async onActivate() {
141-
// TODO remove this HACK once updated type is published that includes the new method;
142-
// for how, this just gets around the TSC complaining the method isn't defined on `this`
143-
// TRACKING: https://github.com/Mirantis/lens-extension-cc/issues/25
144-
const that = this as any;
145-
if (Array.isArray(that.protocolHandlers)) {
146-
that.protocolHandlers = [
147-
{
148-
pathSchema: `/${EXT_EVENT_ACTIVATE_CLUSTER}`,
149-
handler: this.handleProtocolActivateCluster,
150-
},
151-
{
152-
pathSchema: `/${EXT_EVENT_ADD_CLUSTERS}`,
153-
handler: this.handleProtocolAddClusters,
154-
},
155-
{
156-
pathSchema: `/${EXT_EVENT_KUBECONFIG}`,
157-
handler: this.handleProtocolKubeConfig,
158-
},
159-
{
160-
pathSchema: `/${EXT_EVENT_OAUTH_CODE}`,
161-
handler: this.handleProtocolOauthCode,
162-
},
163-
];
164-
} else {
165-
logger.warn(
166-
'renderer/onActivate',
167-
'This version of Lens does not support "lens://" protocol requests.'
168-
);
169-
}
141+
this.protocolHandlers = [
142+
{
143+
pathSchema: `/${EXT_EVENT_ACTIVATE_CLUSTER}`,
144+
handler: this.handleProtocolActivateCluster,
145+
},
146+
{
147+
pathSchema: `/${EXT_EVENT_ADD_CLUSTERS}`,
148+
handler: this.handleProtocolAddClusters,
149+
},
150+
{
151+
pathSchema: `/${EXT_EVENT_KUBECONFIG}`,
152+
handler: this.handleProtocolKubeConfig,
153+
},
154+
{
155+
pathSchema: `/${EXT_EVENT_OAUTH_CODE}`,
156+
handler: this.handleProtocolOauthCode,
157+
},
158+
];
170159

171160
await prefStore.loadExtension(this);
172161
}

src/strings.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ export const view: Dict = {
6969
close: () => 'Reset back to normal view',
7070
},
7171
help: {
72-
html: (showLinkInfo = false) => {
73-
// TODO: remove parameter and always show info once links supported
74-
// TRACKING: https://github.com/Mirantis/lens-extension-cc/issues/25
75-
let text = `
72+
html: () =>
73+
`
7674
<h2>Adding Clusters</h2>
7775
<p>
7876
This extension makes it easy to add clusters from a ${mccFullName} instance.
@@ -93,20 +91,13 @@ export const view: Dict = {
9391
be added to the <code>${workspacePrefix}demo</code> workspace (and the workspace will be
9492
created if it doesn't exist already).
9593
</p>
96-
`;
97-
98-
text += showLinkInfo
99-
? `
10094
<h2>Links</h2>
10195
<p>
10296
When activating this extension via links from a ${mccFullName} instance (requires Lens
103-
4.1 or later), the extension UI will add an X (Close) button to the top/right corner
97+
4.2 or later), the extension UI will add an X (Close) button to the top/right corner
10498
of its main panel in certain cases. Click the Close button to return to the default view.
10599
</p>
106-
`
107-
: '';
108-
return text;
109-
},
100+
`,
110101
},
111102
};
112103

0 commit comments

Comments
 (0)