Skip to content

Commit b04c0ec

Browse files
diningPhilosopher64Prabhakar Kumar
authored andcommitted
v0.7.0 : Ability to specify to matlab-proxy that MATLAB is already licensed.
1 parent b9a2ec7 commit b04c0ec

File tree

20 files changed

+463
-134
lines changed

20 files changed

+463
-134
lines changed

Advanced-Usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The following table describes all the environment variables that you can set to
2828
| **MWI_SSL_KEY_FILE** | string | `"/path/to/keyfile.key"` | The keyfile string, if present, must point to a file containing the private key. Otherwise the private key will be taken from certfile as well. |
2929
| **MWI_ENABLE_TOKEN_AUTH** | string | `"True"` | When set to `True`, matlab-proxy will require users to provide the security token to access the proxy. <br />The default value is `False` . See [Token-Based Authentication](./SECURITY.md#token-based-authentication) for more information.|
3030
| **MWI_AUTH_TOKEN** | string (optional) | `"AnyURLSafeToken"` | Optionally, provide a custom `token` for use with `MWI_ENABLE_TOKEN_AUTH`. A token can safely contain any combination of alpha numeric text along with the following permitted characters: `- . _ ~`.<br />When absent matlab-proxy will generate a random URL safe token. |
31+
| **MWI_USE_EXISTING_LICENSE** | string (optional) | `"True"` | When set to True, matlab-proxy will not ask you for additional licensing information and will try to launch an already activated MATLAB on your system PATH.
3132

3233

3334
## Custom HTTP Headers

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ Install the version >=0.5.0 to use the package on MacOS.
162162
$ pip install --upgrade matlab-proxy>=0.5.0
163163
```
164164

165+
## Using an already activated MATLAB with matlab-proxy
166+
`matlab-proxy` version `v0.7.0` introduces support for using an existing MATLAB license. Use the Existing License option only if you have an activated MATLAB. This allows you to start MATLAB without authenticating every time.
167+
165168
## Limitations
166169
This package supports the same subset of MATLAB features and commands as MATLAB® Online, except there is no support for Simulink® Online.
167170
[Click here for a full list of Specifications and Limitations for MATLAB Online](https://www.mathworks.com/products/matlab-online/limitations.html).

gui/src/components/Controls/index.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// Copyright (c) 2020-2022 The MathWorks, Inc.
1+
// Copyright (c) 2020-2023 The MathWorks, Inc.
22

33
import React, { useMemo } from 'react';
44
import PropTypes from 'prop-types';
55
import { useSelector } from 'react-redux';
66
import ReactTooltip from 'react-tooltip';
77
import {
88
selectSubmittingServerStatus,
9-
selectLicensingIsMhlm,
9+
selectLicensingInfo,
1010
selectLicensingProvided,
1111
selectMatlabUp,
1212
selectMatlabStarting,
@@ -36,7 +36,6 @@ function Controls({
3636
}) {
3737
const submitting = useSelector(selectSubmittingServerStatus);
3838
const licensed = useSelector(selectLicensingProvided);
39-
const mhlmLicense = useSelector(selectLicensingIsMhlm);
4039
const matlabStarting = useSelector(selectMatlabStarting);
4140
const matlabUp = useSelector(selectMatlabUp);
4241
const matlabStopping = useSelector(selectMatlabStopping);
@@ -45,6 +44,7 @@ function Controls({
4544
const error = useSelector(selectError);
4645
const authEnabled = useSelector(selectAuthEnabled);
4746
const isAuthenticated = useSelector(selectIsAuthenticated);
47+
const licensingInfo = useSelector(selectLicensingInfo);
4848
const canResetLicensing = licensed && !submitting;
4949

5050
const feedbackBody = useMemo(
@@ -55,6 +55,41 @@ MATLAB version: ${matlabVersion}%0D%0A`,
5555
[matlabVersion]
5656
);
5757

58+
let licensingData, licensingConfirmationMessage;
59+
switch (licensingInfo?.type) {
60+
case "mhlm":
61+
licensingData = {
62+
label: 'Sign Out',
63+
dataTip : 'Sign out of MATLAB',
64+
};
65+
licensingConfirmationMessage = `Are you sure you want to sign out of MATLAB?`
66+
break;
67+
case "nlm":
68+
licensingData = {
69+
label: 'Remove License Server Address',
70+
dataTip : 'Remove the network license manager server address',
71+
};
72+
licensingConfirmationMessage = `Are you sure you want to remove the network license manager server address?`
73+
break;
74+
75+
case "existing_license":
76+
licensingData = {
77+
label: 'Stop using Existing License',
78+
dataTip : 'Stop using existing license',
79+
};
80+
licensingConfirmationMessage = `Are you sure you want to stop using an Existing License?`
81+
break;
82+
83+
default:
84+
licensingData = {
85+
label: 'None',
86+
dataTip : 'None',
87+
};
88+
licensingConfirmationMessage = null
89+
}
90+
91+
92+
5893
const Confirmations = {
5994
START: {
6095
type: 'confirmation',
@@ -73,7 +108,7 @@ MATLAB version: ${matlabVersion}%0D%0A`,
73108
},
74109
SIGN_OUT: {
75110
type: 'confirmation',
76-
message: `Are you sure you want to ${mhlmLicense ? 'sign out of MATLAB' : 'unset the connection string'}?`,
111+
message: licensingConfirmationMessage,
77112
callback: fetchUnsetLicensing
78113
},
79114
HELP: {
@@ -92,7 +127,7 @@ MATLAB version: ${matlabVersion}%0D%0A`,
92127
return cls + 'btn_color_blue';
93128
}
94129
return cls + 'btn_color_mediumgray';
95-
};
130+
};
96131

97132
return (
98133
<div id="controls" className="labels-on-top">
@@ -127,10 +162,10 @@ MATLAB version: ${matlabVersion}%0D%0A`,
127162
onClick={() => callback(Confirmations.SIGN_OUT)}
128163
disabled={!canResetLicensing || (authEnabled && !isAuthenticated)}
129164
data-for="control-button-tooltip"
130-
data-tip={mhlmLicense ? 'Sign out' : 'Unset the network license manager server address'}
165+
data-tip= {licensingData.dataTip}
131166
>
132167
<span className='icon-custom-sign-out'></span>
133-
<span className='btn-label'>{mhlmLicense ? 'Sign Out' : 'Unset License Server Address'}</span>
168+
<span className='btn-label'>{licensingData.label}</span>
134169
</button>
135170
{/* <button
136171
id="terminateIntegration"

gui/src/components/Information/Information.spec.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Information Component', () => {
2020
tutorialHidden: false,
2121
overlayVisibility: false,
2222
serverStatus: {
23-
licensingInfo: { type: 'MHLM', emailAddress: 'abc@mathworks.com' },
23+
licensingInfo: { type: 'mhlm', emailAddress: 'abc@mathworks.com' },
2424
matlabStatus: 'up',
2525
matlabVersion: 'R2020b',
2626
isFetching: false,
@@ -71,7 +71,7 @@ describe('Information Component', () => {
7171
});
7272

7373
it('should render Online Licensing info with licensing type MHLM', () => {
74-
const { container, debug, getByText } = render(
74+
const { getByText } = render(
7575
<Information closeHandler={closeHandler} children={children} />,
7676
{ initialState: initialState }
7777
);
@@ -85,10 +85,10 @@ describe('Information Component', () => {
8585

8686
it('should render Online Licensing info with licensing type NLM', () => {
8787
initialState.serverStatus.licensingInfo = {
88-
type: 'NLM',
88+
type: 'nlm',
8989
connectionString: 'abc@nlm',
9090
};
91-
const { container, debug, getByText } = render(
91+
const { getByText } = render(
9292
<Information closeHandler={closeHandler} children={children} />,
9393
{ initialState: initialState }
9494
);
@@ -100,6 +100,19 @@ describe('Information Component', () => {
100100
);
101101
});
102102

103+
it('should render Existing License with licensing type existing_license', () => {
104+
initialState.serverStatus.licensingInfo = {
105+
type: 'existing_license',
106+
};
107+
const { getByText } = render(
108+
<Information closeHandler={closeHandler} children={children} />,
109+
{ initialState: initialState }
110+
);
111+
112+
const licensingInfo = getByText('Licensing:');
113+
expect(licensingInfo.nextSibling.textContent).toEqual("Existing License");
114+
});
115+
103116
it('should display errors', () => {
104117
initialState.error = {
105118
message: 'Exited with exit code -9',

gui/src/components/Information/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
selectInformationDetails,
1212
selectAuthEnabled,
1313
selectIsAuthenticated,
14-
selectAuthToken
14+
selectAuthToken,
1515
} from '../../selectors';
1616
import { updateAuthStatus } from '../../actionCreators';
1717
import './Information.css';
@@ -39,16 +39,21 @@ function Information({
3939

4040
let info;
4141
switch (licensingInfo?.type) {
42-
case "MHLM":
42+
case "mhlm":
4343
info = {
4444
label: `Online License Manager (${licensingInfo.emailAddress})`
4545
};
4646
break;
47-
case "NLM":
47+
case "nlm":
4848
info = {
4949
label: `Network License Manager (${licensingInfo.connectionString})`
5050
};
5151
break;
52+
case "existing_license":
53+
info = {
54+
label : 'Existing License'
55+
};
56+
break;
5257
default:
5358
info = {
5459
label: 'None'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
label {
2+
padding-left: 5px;
3+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { useDispatch } from 'react-redux';
3+
import {
4+
fetchSetLicensing
5+
} from '../../actionCreators';
6+
import "./ExistingLicense.css"
7+
8+
9+
10+
function ExistingLicense() {
11+
const dispatch = useDispatch();
12+
13+
function submitForm(event) {
14+
event.preventDefault();
15+
dispatch(fetchSetLicensing({
16+
'type': 'existing_license',
17+
}));
18+
}
19+
20+
return (
21+
<div id="ExistingLicense">
22+
<form onSubmit={submitForm}>
23+
<div className='form-group'>
24+
<p>
25+
<b>Note</b>: Choose this option if you already have an activated MATLAB license. This option allows you to run MATLAB on your host machine without providing additional licensing information.
26+
</p>
27+
<br/>
28+
<input type="submit" id="submit" value="Start MATLAB" className="btn btn_color_blue" />
29+
</div>
30+
</form>
31+
</div>
32+
)
33+
}
34+
35+
export default ExistingLicense;

gui/src/components/LicensingGatherer/LicenseGatherer.spec.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('LicenseGatherer component', () => {
1515
overlayVisibility: false,
1616

1717
serverStatus: {
18-
licensingInfo: { type: 'MHLM', emailAddress: 'abc@mathworks.com' },
18+
licensingInfo: { type: 'mhlm', emailAddress: 'abc@mathworks.com' },
1919
matlabStatus: 'up',
2020
matlabVersion: 'R2020b',
2121
isFetching: false,
@@ -63,7 +63,7 @@ describe('LicenseGatherer component', () => {
6363

6464
initialState.serverStatus.wsEnv = 'mw-integ'
6565

66-
const { container, debug } = render(<LicenseGatherer />, { initialState: initialState });
66+
const { container } = render(<LicenseGatherer />, { initialState: initialState });
6767

6868
const mhlmTab = container.querySelector('#mhlm-tab');
6969

@@ -99,11 +99,24 @@ describe('LicenseGatherer component', () => {
9999
// Click on nlm Tab
100100
fireEvent.click(nlmTab);
101101

102-
// Check if nlm iframe is rendered.
102+
// Check if nlm tab is rendered.
103103
const nlmTabContent = container.querySelector('#NLM');
104104
expect(nlmTabContent).toBeInTheDocument();
105105
});
106106

107+
it('should have rendered existing license tab content without crashing', () => {
108+
const { container } = render(<LicenseGatherer />, { initialState: initialState });
109+
110+
const existingLicenseTab = container.querySelector('#existingLicense-tab');
111+
expect(existingLicenseTab).toBeInTheDocument();
112+
113+
// Click on existingLicense Tab
114+
fireEvent.click(existingLicenseTab);
115+
116+
// Check if existingLicense tab is rendered.
117+
const existingLicenseTabContent = container.querySelector('#existingLicense');
118+
expect(existingLicenseTabContent).toBeInTheDocument();
119+
});
107120

108121
test.each([
109122
['1234', true], ['hostname', true], ['1234hostname', true], ['1234,', true], ['hostname,', true],

gui/src/components/LicensingGatherer/MHLM.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function MHLM() {
102102
} else if (data.event === 'login') {
103103
// Persist credentials to serverside
104104
dispatch(fetchSetLicensing({
105-
type: 'MHLM',
105+
type: 'mhlm',
106106
token: data.token,
107107
profileId: data.profileId,
108108
emailAddress: data.emailAddress,

gui/src/components/LicensingGatherer/NLM.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function NLM() {
5050
function submitForm(event) {
5151
event.preventDefault();
5252
dispatch(fetchSetLicensing({
53-
'type': 'NLM',
53+
'type': 'nlm',
5454
'connectionString': connStr
5555
}));
5656
}

0 commit comments

Comments
 (0)