docusaurus-theme-openapi-docs 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/postman-code-generators.d.ts +9 -0
- package/lib/react-magic-dropzone.d.ts +9 -0
- package/lib/theme/ApiDemoPanel/Curl/index.js +0 -1
- package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +0 -1
- package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +21 -3
- package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +5 -2
- package/lib/theme/ApiDemoPanel/index.js +4 -6
- package/lib/theme/ApiItem/index.js +2 -2
- package/lib/theme/ApiItem/styles.module.css +6 -2
- package/lib/theme/{Tabs → ApiTabs}/index.js +3 -3
- package/lib/theme/{Tabs → ApiTabs}/styles.module.css +0 -0
- package/lib-next/postman-code-generators.d.ts +9 -0
- package/lib-next/react-magic-dropzone.d.ts +9 -0
- package/lib-next/theme/ApiDemoPanel/Curl/index.js +2 -4
- package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +1 -2
- package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +26 -3
- package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +5 -2
- package/lib-next/theme/ApiDemoPanel/index.js +6 -8
- package/lib-next/theme/ApiItem/index.js +2 -12
- package/lib-next/theme/ApiItem/styles.module.css +6 -2
- package/{src/theme/Tabs → lib-next/theme/ApiTabs}/index.js +3 -3
- package/lib-next/theme/{Tabs → ApiTabs}/styles.module.css +0 -0
- package/package.json +3 -4
- package/src/postman-code-generators.d.ts +9 -0
- package/src/react-magic-dropzone.d.ts +9 -0
- package/src/theme/ApiDemoPanel/Curl/index.tsx +0 -2
- package/src/theme/ApiDemoPanel/FormFileUpload/index.tsx +0 -1
- package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +26 -3
- package/src/theme/ApiDemoPanel/buildPostmanRequest.ts +5 -3
- package/src/theme/ApiDemoPanel/index.tsx +10 -11
- package/src/theme/ApiItem/index.tsx +2 -12
- package/src/theme/ApiItem/styles.module.css +6 -2
- package/{lib-next/theme/Tabs → src/theme/ApiTabs}/index.js +3 -3
- package/src/theme/{Tabs → ApiTabs}/styles.module.css +0 -0
- package/lib/theme/ApiDemoPanel/Authorization/index.js +0 -174
- package/lib/theme/ApiDemoPanel/Execute/index.js +0 -85
- package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +0 -202
- package/lib-next/theme/ApiDemoPanel/Authorization/index.js +0 -203
- package/lib-next/theme/ApiDemoPanel/Execute/index.js +0 -74
- package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +0 -183
- package/src/theme/ApiDemoPanel/Authorization/index.tsx +0 -211
- package/src/theme/ApiDemoPanel/Execute/index.tsx +0 -88
- package/src/theme/ApiDemoPanel/Execute/makeRequest.ts +0 -184
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* Copyright (c) Palo Alto Networks
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
* ========================================================================== */
|
|
7
|
-
import React, { useState } from "react";
|
|
8
|
-
import clsx from "clsx";
|
|
9
|
-
import FormItem from "../FormItem";
|
|
10
|
-
import FormSelect from "../FormSelect";
|
|
11
|
-
import FormTextInput from "../FormTextInput";
|
|
12
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
13
|
-
import styles from "../styles.module.css";
|
|
14
|
-
import { setAuthData, setSelectedAuth } from "./slice";
|
|
15
|
-
|
|
16
|
-
function LockButton({ mode, children, style, ...rest }) {
|
|
17
|
-
return (
|
|
18
|
-
<button
|
|
19
|
-
className={clsx("button", "button--primary", {
|
|
20
|
-
"button--outline": mode !== "locked",
|
|
21
|
-
})}
|
|
22
|
-
style={{
|
|
23
|
-
marginLeft: "auto",
|
|
24
|
-
display: "flex",
|
|
25
|
-
alignItems: "center",
|
|
26
|
-
marginBottom: "var(--ifm-spacing-vertical)",
|
|
27
|
-
...style,
|
|
28
|
-
}}
|
|
29
|
-
{...rest}
|
|
30
|
-
>
|
|
31
|
-
<span>{children}</span>
|
|
32
|
-
|
|
33
|
-
<svg
|
|
34
|
-
style={{
|
|
35
|
-
marginLeft: "12px",
|
|
36
|
-
width: "18px",
|
|
37
|
-
height: "18px",
|
|
38
|
-
fill: "currentColor",
|
|
39
|
-
}}
|
|
40
|
-
viewBox="0 0 20 20"
|
|
41
|
-
id={mode}
|
|
42
|
-
>
|
|
43
|
-
{mode === "locked" ? (
|
|
44
|
-
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"></path>
|
|
45
|
-
) : (
|
|
46
|
-
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
|
47
|
-
)}
|
|
48
|
-
</svg>
|
|
49
|
-
</button>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function validateData(selectedAuth, data) {
|
|
54
|
-
for (const scheme of selectedAuth) {
|
|
55
|
-
if (data[scheme.key] === undefined) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const hasMissingKeys = Object.values(data[scheme.key]).includes(undefined);
|
|
60
|
-
|
|
61
|
-
if (hasMissingKeys) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function Authorization() {
|
|
70
|
-
const [editing, setEditing] = useState(false);
|
|
71
|
-
const data = useTypedSelector((state) => state.auth.data);
|
|
72
|
-
const options = useTypedSelector((state) => state.auth.options);
|
|
73
|
-
const selected = useTypedSelector((state) => state.auth.selected);
|
|
74
|
-
const dispatch = useTypedDispatch();
|
|
75
|
-
|
|
76
|
-
if (selected === undefined) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const selectedAuth = options[selected];
|
|
81
|
-
const authenticated = validateData(selectedAuth, data);
|
|
82
|
-
const optionKeys = Object.keys(options);
|
|
83
|
-
|
|
84
|
-
if (editing) {
|
|
85
|
-
return (
|
|
86
|
-
<div className={styles.optionsPanel}>
|
|
87
|
-
{optionKeys.length > 1 && (
|
|
88
|
-
<FormItem label="Security Scheme">
|
|
89
|
-
<FormSelect
|
|
90
|
-
options={optionKeys}
|
|
91
|
-
value={selected}
|
|
92
|
-
onChange={(e) => {
|
|
93
|
-
dispatch(setSelectedAuth(e.target.value));
|
|
94
|
-
}}
|
|
95
|
-
/>
|
|
96
|
-
</FormItem>
|
|
97
|
-
)}
|
|
98
|
-
{selectedAuth.map((a) => {
|
|
99
|
-
if (a.type === "http" && a.scheme === "bearer") {
|
|
100
|
-
return (
|
|
101
|
-
<FormItem label="Bearer Token" key={selected + "-bearer"}>
|
|
102
|
-
<FormTextInput
|
|
103
|
-
placeholder="Bearer Token"
|
|
104
|
-
value={data[a.key].token ?? ""}
|
|
105
|
-
onChange={(e) => {
|
|
106
|
-
const value = e.target.value.trim();
|
|
107
|
-
dispatch(
|
|
108
|
-
setAuthData({
|
|
109
|
-
scheme: a.key,
|
|
110
|
-
key: "token",
|
|
111
|
-
value: value ? value : undefined,
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
}}
|
|
115
|
-
/>
|
|
116
|
-
</FormItem>
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (a.type === "http" && a.scheme === "basic") {
|
|
121
|
-
return (
|
|
122
|
-
<React.Fragment key={selected + "-basic"}>
|
|
123
|
-
<FormItem label="Username">
|
|
124
|
-
<FormTextInput
|
|
125
|
-
placeholder="Username"
|
|
126
|
-
value={data[a.key].username ?? ""}
|
|
127
|
-
onChange={(e) => {
|
|
128
|
-
const value = e.target.value.trim();
|
|
129
|
-
dispatch(
|
|
130
|
-
setAuthData({
|
|
131
|
-
scheme: a.key,
|
|
132
|
-
key: "username",
|
|
133
|
-
value: value ? value : undefined,
|
|
134
|
-
})
|
|
135
|
-
);
|
|
136
|
-
}}
|
|
137
|
-
/>
|
|
138
|
-
</FormItem>
|
|
139
|
-
<FormItem label="Password">
|
|
140
|
-
<FormTextInput
|
|
141
|
-
placeholder="Password"
|
|
142
|
-
password
|
|
143
|
-
value={data[a.key].password ?? ""}
|
|
144
|
-
onChange={(e) => {
|
|
145
|
-
const value = e.target.value.trim();
|
|
146
|
-
dispatch(
|
|
147
|
-
setAuthData({
|
|
148
|
-
scheme: a.key,
|
|
149
|
-
key: "password",
|
|
150
|
-
value: value ? value : undefined,
|
|
151
|
-
})
|
|
152
|
-
);
|
|
153
|
-
}}
|
|
154
|
-
/>
|
|
155
|
-
</FormItem>
|
|
156
|
-
</React.Fragment>
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return null;
|
|
161
|
-
})}
|
|
162
|
-
<LockButton
|
|
163
|
-
mode="unlocked"
|
|
164
|
-
style={{
|
|
165
|
-
marginTop: "var(--ifm-spacing-vertical)",
|
|
166
|
-
marginBottom: 0,
|
|
167
|
-
}}
|
|
168
|
-
onClick={() => {
|
|
169
|
-
setEditing(false);
|
|
170
|
-
}}
|
|
171
|
-
>
|
|
172
|
-
Save
|
|
173
|
-
</LockButton>
|
|
174
|
-
</div>
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (authenticated) {
|
|
179
|
-
return (
|
|
180
|
-
<LockButton
|
|
181
|
-
mode="locked"
|
|
182
|
-
onClick={() => {
|
|
183
|
-
setEditing(true);
|
|
184
|
-
}}
|
|
185
|
-
>
|
|
186
|
-
Authorized
|
|
187
|
-
</LockButton>
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return (
|
|
192
|
-
<LockButton
|
|
193
|
-
mode="unlocked"
|
|
194
|
-
onClick={() => {
|
|
195
|
-
setEditing(true);
|
|
196
|
-
}}
|
|
197
|
-
>
|
|
198
|
-
Authorize
|
|
199
|
-
</LockButton>
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export default Authorization;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* Copyright (c) Palo Alto Networks
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
* ========================================================================== */
|
|
7
|
-
import React from "react"; // @ts-ignore
|
|
8
|
-
|
|
9
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
10
|
-
import { setResponse } from "../Response/slice";
|
|
11
|
-
import buildPostmanRequest from "./../buildPostmanRequest";
|
|
12
|
-
import makeRequest from "./makeRequest";
|
|
13
|
-
|
|
14
|
-
function validateRequest(params) {
|
|
15
|
-
for (let paramList of Object.values(params)) {
|
|
16
|
-
for (let param of paramList) {
|
|
17
|
-
if (param.required && !param.value) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function Execute({ postman, proxy }) {
|
|
27
|
-
const pathParams = useTypedSelector((state) => state.params.path);
|
|
28
|
-
const queryParams = useTypedSelector((state) => state.params.query);
|
|
29
|
-
const cookieParams = useTypedSelector((state) => state.params.cookie);
|
|
30
|
-
const headerParams = useTypedSelector((state) => state.params.header);
|
|
31
|
-
const contentType = useTypedSelector((state) => state.contentType.value);
|
|
32
|
-
const body = useTypedSelector((state) => state.body);
|
|
33
|
-
const accept = useTypedSelector((state) => state.accept.value);
|
|
34
|
-
const server = useTypedSelector((state) => state.server.value);
|
|
35
|
-
const params = useTypedSelector((state) => state.params);
|
|
36
|
-
const auth = useTypedSelector((state) => state.auth);
|
|
37
|
-
const isValidRequest = validateRequest(params);
|
|
38
|
-
const dispatch = useTypedDispatch();
|
|
39
|
-
const postmanRequest = buildPostmanRequest(postman, {
|
|
40
|
-
queryParams,
|
|
41
|
-
pathParams,
|
|
42
|
-
cookieParams,
|
|
43
|
-
contentType,
|
|
44
|
-
accept,
|
|
45
|
-
headerParams,
|
|
46
|
-
body,
|
|
47
|
-
server,
|
|
48
|
-
auth,
|
|
49
|
-
});
|
|
50
|
-
return (
|
|
51
|
-
<button
|
|
52
|
-
className="button button--block button--primary"
|
|
53
|
-
style={{
|
|
54
|
-
height: "48px",
|
|
55
|
-
marginBottom: "var(--ifm-spacing-vertical)",
|
|
56
|
-
}}
|
|
57
|
-
disabled={!isValidRequest}
|
|
58
|
-
onClick={async () => {
|
|
59
|
-
dispatch(setResponse("loading..."));
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const res = await makeRequest(postmanRequest, proxy, body);
|
|
63
|
-
dispatch(setResponse(res));
|
|
64
|
-
} catch (e) {
|
|
65
|
-
dispatch(setResponse(e.message ?? "Error fetching."));
|
|
66
|
-
}
|
|
67
|
-
}}
|
|
68
|
-
>
|
|
69
|
-
Execute
|
|
70
|
-
</button>
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export default Execute;
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* Copyright (c) Palo Alto Networks
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
* ========================================================================== */
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
async function loadImage(content) {
|
|
9
|
-
return new Promise((accept, reject) => {
|
|
10
|
-
const reader = new FileReader();
|
|
11
|
-
|
|
12
|
-
reader.onabort = () => {
|
|
13
|
-
console.log("file reading was aborted");
|
|
14
|
-
reject();
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
reader.onerror = () => {
|
|
18
|
-
console.log("file reading has failed");
|
|
19
|
-
reject();
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
reader.onload = () => {
|
|
23
|
-
// Do whatever you want with the file contents
|
|
24
|
-
const binaryStr = reader.result;
|
|
25
|
-
accept(binaryStr);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
reader.readAsArrayBuffer(content);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function makeRequest(request, proxy, _body) {
|
|
33
|
-
const headers = request.toJSON().header;
|
|
34
|
-
let myHeaders = new Headers();
|
|
35
|
-
|
|
36
|
-
if (headers) {
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
headers.forEach((header) => {
|
|
39
|
-
if (header.key && header.value) {
|
|
40
|
-
myHeaders.append(header.key, header.value);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
} // The following code handles multiple files in the same formdata param.
|
|
44
|
-
// It removes the form data params where the src property is an array of filepath strings
|
|
45
|
-
// Splits that array into different form data params with src set as a single filepath string
|
|
46
|
-
// TODO:
|
|
47
|
-
// if (request.body && request.body.mode === 'formdata') {
|
|
48
|
-
// let formdata = request.body.formdata,
|
|
49
|
-
// formdataArray = [];
|
|
50
|
-
// formdata.members.forEach((param) => {
|
|
51
|
-
// let key = param.key,
|
|
52
|
-
// type = param.type,
|
|
53
|
-
// disabled = param.disabled,
|
|
54
|
-
// contentType = param.contentType;
|
|
55
|
-
// // check if type is file or text
|
|
56
|
-
// if (type === 'file') {
|
|
57
|
-
// // if src is not of type string we check for array(multiple files)
|
|
58
|
-
// if (typeof param.src !== 'string') {
|
|
59
|
-
// // if src is an array(not empty), iterate over it and add files as separate form fields
|
|
60
|
-
// if (Array.isArray(param.src) && param.src.length) {
|
|
61
|
-
// param.src.forEach((filePath) => {
|
|
62
|
-
// addFormParam(
|
|
63
|
-
// formdataArray,
|
|
64
|
-
// key,
|
|
65
|
-
// param.type,
|
|
66
|
-
// filePath,
|
|
67
|
-
// disabled,
|
|
68
|
-
// contentType
|
|
69
|
-
// );
|
|
70
|
-
// });
|
|
71
|
-
// }
|
|
72
|
-
// // if src is not an array or string, or is an empty array, add a placeholder for file path(no files case)
|
|
73
|
-
// else {
|
|
74
|
-
// addFormParam(
|
|
75
|
-
// formdataArray,
|
|
76
|
-
// key,
|
|
77
|
-
// param.type,
|
|
78
|
-
// '/path/to/file',
|
|
79
|
-
// disabled,
|
|
80
|
-
// contentType
|
|
81
|
-
// );
|
|
82
|
-
// }
|
|
83
|
-
// }
|
|
84
|
-
// // if src is string, directly add the param with src as filepath
|
|
85
|
-
// else {
|
|
86
|
-
// addFormParam(
|
|
87
|
-
// formdataArray,
|
|
88
|
-
// key,
|
|
89
|
-
// param.type,
|
|
90
|
-
// param.src,
|
|
91
|
-
// disabled,
|
|
92
|
-
// contentType
|
|
93
|
-
// );
|
|
94
|
-
// }
|
|
95
|
-
// }
|
|
96
|
-
// // if type is text, directly add it to formdata array
|
|
97
|
-
// else {
|
|
98
|
-
// addFormParam(
|
|
99
|
-
// formdataArray,
|
|
100
|
-
// key,
|
|
101
|
-
// param.type,
|
|
102
|
-
// param.value,
|
|
103
|
-
// disabled,
|
|
104
|
-
// contentType
|
|
105
|
-
// );
|
|
106
|
-
// }
|
|
107
|
-
// });
|
|
108
|
-
// request.body.update({
|
|
109
|
-
// mode: 'formdata',
|
|
110
|
-
// formdata: formdataArray,
|
|
111
|
-
// });
|
|
112
|
-
// }
|
|
113
|
-
|
|
114
|
-
const body = request.body?.toJSON();
|
|
115
|
-
let myBody = undefined;
|
|
116
|
-
|
|
117
|
-
if (body !== undefined && Object.keys(body).length > 0) {
|
|
118
|
-
switch (body.mode) {
|
|
119
|
-
case "urlencoded": {
|
|
120
|
-
myBody = new URLSearchParams();
|
|
121
|
-
|
|
122
|
-
if (Array.isArray(body.urlencoded)) {
|
|
123
|
-
for (const data of body.urlencoded) {
|
|
124
|
-
if (data.key && data.value) {
|
|
125
|
-
myBody.append(data.key, data.value);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
case "raw": {
|
|
134
|
-
myBody = (body.raw ?? "").toString();
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
case "formdata": {
|
|
139
|
-
myBody = new FormData();
|
|
140
|
-
|
|
141
|
-
if (Array.isArray(body.formdata)) {
|
|
142
|
-
for (const data of body.formdata) {
|
|
143
|
-
if (data.key && data.value) {
|
|
144
|
-
myBody.append(data.key, data.value);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
case "file": {
|
|
153
|
-
if (_body.type === "raw" && _body.content?.type === "file") {
|
|
154
|
-
myBody = await loadImage(_body.content.value.content);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
default:
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const requestOptions = {
|
|
166
|
-
method: request.method,
|
|
167
|
-
headers: myHeaders,
|
|
168
|
-
body: myBody,
|
|
169
|
-
};
|
|
170
|
-
let finalUrl = request.url.toString();
|
|
171
|
-
|
|
172
|
-
if (proxy) {
|
|
173
|
-
// Ensure the proxy ends with a slash.
|
|
174
|
-
let normalizedProxy = proxy.replace(/\/$/, "") + "/";
|
|
175
|
-
finalUrl = normalizedProxy + request.url.toString();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return await fetch(finalUrl, requestOptions).then((response) => {
|
|
179
|
-
return response.text();
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export default makeRequest;
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* Copyright (c) Palo Alto Networks
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
* ========================================================================== */
|
|
7
|
-
|
|
8
|
-
import React, { useState } from "react";
|
|
9
|
-
|
|
10
|
-
import clsx from "clsx";
|
|
11
|
-
|
|
12
|
-
import FormItem from "../FormItem";
|
|
13
|
-
import FormSelect from "../FormSelect";
|
|
14
|
-
import FormTextInput from "../FormTextInput";
|
|
15
|
-
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
16
|
-
import styles from "../styles.module.css";
|
|
17
|
-
import { AuthState, Scheme, setAuthData, setSelectedAuth } from "./slice";
|
|
18
|
-
|
|
19
|
-
type Props = {
|
|
20
|
-
mode: "locked" | "unlocked";
|
|
21
|
-
} & JSX.IntrinsicElements["button"];
|
|
22
|
-
|
|
23
|
-
function LockButton({ mode, children, style, ...rest }: Props) {
|
|
24
|
-
return (
|
|
25
|
-
<button
|
|
26
|
-
className={clsx("button", "button--primary", {
|
|
27
|
-
"button--outline": mode !== "locked",
|
|
28
|
-
})}
|
|
29
|
-
style={{
|
|
30
|
-
marginLeft: "auto",
|
|
31
|
-
display: "flex",
|
|
32
|
-
alignItems: "center",
|
|
33
|
-
marginBottom: "var(--ifm-spacing-vertical)",
|
|
34
|
-
...style,
|
|
35
|
-
}}
|
|
36
|
-
{...rest}
|
|
37
|
-
>
|
|
38
|
-
<span>{children}</span>
|
|
39
|
-
|
|
40
|
-
<svg
|
|
41
|
-
style={{
|
|
42
|
-
marginLeft: "12px",
|
|
43
|
-
width: "18px",
|
|
44
|
-
height: "18px",
|
|
45
|
-
fill: "currentColor",
|
|
46
|
-
}}
|
|
47
|
-
viewBox="0 0 20 20"
|
|
48
|
-
id={mode}
|
|
49
|
-
>
|
|
50
|
-
{mode === "locked" ? (
|
|
51
|
-
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"></path>
|
|
52
|
-
) : (
|
|
53
|
-
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
|
54
|
-
)}
|
|
55
|
-
</svg>
|
|
56
|
-
</button>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function validateData(selectedAuth: Scheme[], data: AuthState["data"]) {
|
|
61
|
-
for (const scheme of selectedAuth) {
|
|
62
|
-
if (data[scheme.key] === undefined) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
const hasMissingKeys = Object.values(data[scheme.key]).includes(undefined);
|
|
66
|
-
if (hasMissingKeys) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function Authorization() {
|
|
74
|
-
const [editing, setEditing] = useState(false);
|
|
75
|
-
|
|
76
|
-
const data = useTypedSelector((state) => state.auth.data);
|
|
77
|
-
const options = useTypedSelector((state) => state.auth.options);
|
|
78
|
-
const selected = useTypedSelector((state) => state.auth.selected);
|
|
79
|
-
|
|
80
|
-
const dispatch = useTypedDispatch();
|
|
81
|
-
|
|
82
|
-
if (selected === undefined) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const selectedAuth = options[selected];
|
|
87
|
-
|
|
88
|
-
const authenticated = validateData(selectedAuth, data);
|
|
89
|
-
|
|
90
|
-
const optionKeys = Object.keys(options);
|
|
91
|
-
|
|
92
|
-
if (editing) {
|
|
93
|
-
return (
|
|
94
|
-
<div className={styles.optionsPanel}>
|
|
95
|
-
{optionKeys.length > 1 && (
|
|
96
|
-
<FormItem label="Security Scheme">
|
|
97
|
-
<FormSelect
|
|
98
|
-
options={optionKeys}
|
|
99
|
-
value={selected}
|
|
100
|
-
onChange={(e) => {
|
|
101
|
-
dispatch(setSelectedAuth(e.target.value));
|
|
102
|
-
}}
|
|
103
|
-
/>
|
|
104
|
-
</FormItem>
|
|
105
|
-
)}
|
|
106
|
-
{selectedAuth.map((a) => {
|
|
107
|
-
if (a.type === "http" && a.scheme === "bearer") {
|
|
108
|
-
return (
|
|
109
|
-
<FormItem label="Bearer Token" key={selected + "-bearer"}>
|
|
110
|
-
<FormTextInput
|
|
111
|
-
placeholder="Bearer Token"
|
|
112
|
-
value={data[a.key].token ?? ""}
|
|
113
|
-
onChange={(e) => {
|
|
114
|
-
const value = e.target.value.trim();
|
|
115
|
-
dispatch(
|
|
116
|
-
setAuthData({
|
|
117
|
-
scheme: a.key,
|
|
118
|
-
key: "token",
|
|
119
|
-
value: value ? value : undefined,
|
|
120
|
-
})
|
|
121
|
-
);
|
|
122
|
-
}}
|
|
123
|
-
/>
|
|
124
|
-
</FormItem>
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (a.type === "http" && a.scheme === "basic") {
|
|
129
|
-
return (
|
|
130
|
-
<React.Fragment key={selected + "-basic"}>
|
|
131
|
-
<FormItem label="Username">
|
|
132
|
-
<FormTextInput
|
|
133
|
-
placeholder="Username"
|
|
134
|
-
value={data[a.key].username ?? ""}
|
|
135
|
-
onChange={(e) => {
|
|
136
|
-
const value = e.target.value.trim();
|
|
137
|
-
dispatch(
|
|
138
|
-
setAuthData({
|
|
139
|
-
scheme: a.key,
|
|
140
|
-
key: "username",
|
|
141
|
-
value: value ? value : undefined,
|
|
142
|
-
})
|
|
143
|
-
);
|
|
144
|
-
}}
|
|
145
|
-
/>
|
|
146
|
-
</FormItem>
|
|
147
|
-
<FormItem label="Password">
|
|
148
|
-
<FormTextInput
|
|
149
|
-
placeholder="Password"
|
|
150
|
-
password
|
|
151
|
-
value={data[a.key].password ?? ""}
|
|
152
|
-
onChange={(e) => {
|
|
153
|
-
const value = e.target.value.trim();
|
|
154
|
-
dispatch(
|
|
155
|
-
setAuthData({
|
|
156
|
-
scheme: a.key,
|
|
157
|
-
key: "password",
|
|
158
|
-
value: value ? value : undefined,
|
|
159
|
-
})
|
|
160
|
-
);
|
|
161
|
-
}}
|
|
162
|
-
/>
|
|
163
|
-
</FormItem>
|
|
164
|
-
</React.Fragment>
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return null;
|
|
169
|
-
})}
|
|
170
|
-
<LockButton
|
|
171
|
-
mode="unlocked"
|
|
172
|
-
style={{
|
|
173
|
-
marginTop: "var(--ifm-spacing-vertical)",
|
|
174
|
-
marginBottom: 0,
|
|
175
|
-
}}
|
|
176
|
-
onClick={() => {
|
|
177
|
-
setEditing(false);
|
|
178
|
-
}}
|
|
179
|
-
>
|
|
180
|
-
Save
|
|
181
|
-
</LockButton>
|
|
182
|
-
</div>
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (authenticated) {
|
|
187
|
-
return (
|
|
188
|
-
<LockButton
|
|
189
|
-
mode="locked"
|
|
190
|
-
onClick={() => {
|
|
191
|
-
setEditing(true);
|
|
192
|
-
}}
|
|
193
|
-
>
|
|
194
|
-
Authorized
|
|
195
|
-
</LockButton>
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return (
|
|
200
|
-
<LockButton
|
|
201
|
-
mode="unlocked"
|
|
202
|
-
onClick={() => {
|
|
203
|
-
setEditing(true);
|
|
204
|
-
}}
|
|
205
|
-
>
|
|
206
|
-
Authorize
|
|
207
|
-
</LockButton>
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export default Authorization;
|