Skip to content

Commit 6d8400a

Browse files
author
Gene Hynson
authored
feat(sub): can specify custom client id (#6005)
* feat(sub): can specify custom client id * fix: use uuid instead of crypto
1 parent 26c0082 commit 6d8400a

File tree

6 files changed

+86
-2
lines changed

6 files changed

+86
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"cy": "CYPRESS_dexUrl=https://$INGRESS_HOST:$PORT_HTTPS CYPRESS_baseUrl=http://localhost:9999 cypress open",
5353
"cy:dev": "source ../monitor-ci/.env && CYPRESS_dexUrl=CLOUD CYPRESS_baseUrl=https://$INGRESS_HOST:$PORT_HTTPS cypress open --config testFiles='{cloud,shared}/**/*.*'",
5454
"cy:dev-oss": "source ../monitor-ci/.env && CYPRESS_dexUrl=OSS CYPRESS_baseUrl=https://$INGRESS_HOST:$PORT_HTTPS cypress open --config testFiles='{oss,shared}/**/*.*'",
55-
"generate": "export SHA=b320a258a7a908662c3f36f73a9e5673d60700d5 && export REMOTE=https://raw.githubusercontent.com/influxdata/openapi/${SHA}/ && yarn generate-meta",
55+
"generate": "export SHA=97ca3ce15361c5f5b5654fd32a20df4a31c45cd7 && export REMOTE=https://raw.githubusercontent.com/influxdata/openapi/${SHA}/ && yarn generate-meta",
5656
"generate-local": "export REMOTE=../openapi/ && yarn generate-meta",
5757
"generate-local-cloud": "export REMOTE=../openapi/ && yarn generate-meta-cloud",
5858
"generate-meta": "if [ -z \"${CLOUD_URL}\" ]; then yarn generate-meta-oss; else yarn generate-meta-cloud; fi",
@@ -222,6 +222,7 @@
222222
"s2-geometry": "^1.2.10",
223223
"ts-jest": "27.0.7",
224224
"use-local-storage-state": "^9.0.2",
225+
"uuid": "^9.0.0",
225226
"vscode-languageserver-protocol": "^3.16.0",
226227
"worker-plugin": "^5.0.1",
227228
"y-websocket": "^1.4.4",

src/types/subscriptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface Subscription {
4444
brokerCACert?: string
4545
authType: BrokerAuthTypes
4646
brokerCertCreationDate?: string
47+
clientID?: string
4748
}
4849

4950
export interface SubscriptionStatus {

src/writeData/subscriptions/components/BrokerDetails.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
&__example-text {
7272
font-style: italic;
7373
color: $cf-grey-55;
74+
margin-bottom: $cf-space-m;
7475
}
7576
&__creds {
7677
.cf-form--element {

src/writeData/subscriptions/components/BrokerForm.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
@import '@influxdata/clockface/dist/variables.scss';
2+
3+
.no-margin-bottom {
4+
margin-bottom: $cf-space-s !important;
5+
}
26
.create-broker-form {
37
float: right;
48
width: 75%;
@@ -72,6 +76,7 @@
7276
&__example-text {
7377
font-style: italic;
7478
color: $cf-grey-55;
79+
margin-bottom: $cf-space-m;
7580
}
7681
&__creds {
7782
.cf-form--element {

src/writeData/subscriptions/components/BrokerFormContent.tsx

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Libraries
2-
import React, {FC, useEffect, useState} from 'react'
2+
import React, {FC, useEffect, useRef, useState} from 'react'
3+
import {v4 as uuidv4} from 'uuid'
34

45
// Components
56
import {
@@ -19,6 +20,9 @@ import {
1920
AlignItems,
2021
FlexDirection,
2122
ComponentStatus,
23+
Toggle,
24+
InputToggleType,
25+
InputLabel,
2226
} from '@influxdata/clockface'
2327
import UserInput from 'src/writeData/subscriptions/components/UserInput'
2428
import CertificateInput from 'src/writeData/subscriptions/components/CertificateInput'
@@ -57,6 +61,10 @@ const BrokerFormContent: FC<Props> = ({
5761
const mqttProtocol = 'MQTT'
5862
const protocolList = [mqttProtocol]
5963
const [protocol, setProtocol] = useState(mqttProtocol)
64+
const [useCustomClientID, setUseCustomClientID] = useState(
65+
!!formContent.clientID || false
66+
)
67+
const randomClientID = useRef(uuidv4())
6068

6169
useEffect(() => {
6270
updateForm({...formContent, protocol: protocol.toLowerCase()})
@@ -293,6 +301,69 @@ const BrokerFormContent: FC<Props> = ({
293301
}`}
294302
</Heading>
295303
)}
304+
{isFlagEnabled('subscriptionsClientId') && (
305+
<>
306+
<Form.ValidationElement
307+
label="Client ID"
308+
value={formContent.brokerHost}
309+
required={useCustomClientID}
310+
validationFunc={() =>
311+
useCustomClientID &&
312+
handleValidation('Client ID', formContent.clientID)
313+
}
314+
helpText="We will generate a Client ID for you, but some providers require you use their Client ID. If your provider requires a specific Client ID, the connection will fail without it. Check your provider’s documentation to verify whether you need to use their Client ID."
315+
className="no-margin-bottom"
316+
>
317+
{status => (
318+
<Input
319+
type={InputType.Text}
320+
placeholder={
321+
useCustomClientID
322+
? 'Enter a client id'
323+
: randomClientID.current
324+
}
325+
name="clientid"
326+
autoFocus={false}
327+
value={formContent.clientID}
328+
onChange={e => {
329+
updateForm({
330+
...formContent,
331+
clientID: e.target.value,
332+
})
333+
}}
334+
onBlur={() =>
335+
event(
336+
'completed form field',
337+
{formField: 'clientid', step: 'broker'},
338+
{feature: 'subscriptions'}
339+
)
340+
}
341+
status={
342+
edit && useCustomClientID
343+
? status
344+
: ComponentStatus.Disabled
345+
}
346+
testID={`${className}-broker-form--clientid`}
347+
maxLength={255}
348+
/>
349+
)}
350+
</Form.ValidationElement>
351+
<Toggle
352+
type={InputToggleType.Checkbox}
353+
checked={useCustomClientID}
354+
id="clientid-toggle"
355+
size={ComponentSize.Small}
356+
titleText="Use Custom Client ID"
357+
onChange={() => {
358+
setUseCustomClientID(!useCustomClientID)
359+
updateForm({...formContent, clientID: ''})
360+
}}
361+
disabled={!edit}
362+
>
363+
<InputLabel>Use Custom Client ID</InputLabel>
364+
</Toggle>
365+
</>
366+
)}
296367
</Grid.Column>
297368
<Grid.Column widthXS={Columns.Twelve}>
298369
<Heading

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12366,6 +12366,11 @@ uuid@^8.3.2:
1236612366
resolved "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz"
1236712367
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
1236812368

12369+
uuid@^9.0.0:
12370+
version "9.0.0"
12371+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
12372+
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==
12373+
1236912374
v8-compile-cache-lib@^3.0.1:
1237012375
version "3.0.1"
1237112376
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"

0 commit comments

Comments
 (0)