Skip to content

Commit

Permalink
feat: allow validators for oauth fields
Browse files Browse the repository at this point in the history
  • Loading branch information
soleksy-splunk committed Oct 3, 2024
1 parent b2c34d2 commit aafafa4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 33 deletions.
1 change: 1 addition & 0 deletions docs/advanced/oauth_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Auth can be used inside the entity tag. Use `type: "oauth"` in the entity list a
- `encrypted` should be true if the user wants that particular field encrypted, otherwise, there is no need to have this parameter.
- `required` specifies whether the field is required or not. The default value is true.
- `defaultValue` is the initial input value (string, number, or boolean).
- `validators` array that is used to validate the values of fields using various [validators](../entity/validators.md).
- `options`:
+ `placeholder`: (RENOUNCED) The placeholder for the field.
+ `disableonEdit`: When the form is in edit mode, the field becomes unable to be edited. The default value is false.
Expand Down
64 changes: 35 additions & 29 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,35 +591,8 @@
"encrypted": {
"$ref": "#/definitions/encrypted"
},
"validators": {
"type": "array",
"description": "It is used to validate the values of fields using various validators.",
"minItems": 1,
"items": {
"anyOf": [
{
"$ref": "#/definitions/NumberValidator"
},
{
"$ref": "#/definitions/StringValidator"
},
{
"$ref": "#/definitions/RegexValidator"
},
{
"$ref": "#/definitions/EmailValidator"
},
{
"$ref": "#/definitions/Ipv4Validator"
},
{
"$ref": "#/definitions/UrlValidator"
},
{
"$ref": "#/definitions/DateValidator"
}
]
}
"validators":{
"$ref": "#/definitions/AnyValidator"
},
"options": {
"type": "object",
Expand Down Expand Up @@ -2086,6 +2059,9 @@
},
"modifyFieldsOnValue": {
"$ref": "#/definitions/modifyFieldsOnValue"
},
"validators":{
"$ref": "#/definitions/AnyValidator"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2323,6 +2299,36 @@
],
"additionalProperties": false
},
"AnyValidator":{
"type": "array",
"description": "It is used to validate the values of fields using various validators.",
"minItems": 1,
"items": {
"anyOf": [
{
"$ref": "#/definitions/NumberValidator"
},
{
"$ref": "#/definitions/StringValidator"
},
{
"$ref": "#/definitions/RegexValidator"
},
{
"$ref": "#/definitions/EmailValidator"
},
{
"$ref": "#/definitions/Ipv4Validator"
},
{
"$ref": "#/definitions/UrlValidator"
},
{
"$ref": "#/definitions/DateValidator"
}
]
}
},
"ValueLabelPair": {
"type": "object",
"description": "Options with a label and a value.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,25 @@
{
"oauth_field": "some_text",
"label": "Disabled on edit for oauth",
"help": "Enter text for field disabled on edit",
"help": "Enter text for field disabled on edit, no special characters allowed",
"field": "basic_oauth_text",
"required": false,
"options": {
"disableonEdit": true
}
},
"validators": [
{
"type": "string",
"errorMsg": "Max host length is 4096",
"minLength": 10,
"maxLength": 4096
},
{
"type": "regex",
"errorMsg": "do not use special characters",
"pattern": "^[a-zA-Z]\\w*$"
}
]
}
],
"oauth": [
Expand Down Expand Up @@ -1622,10 +1635,10 @@
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.49.0Rcc63ee532",
"version": "5.50.0Rb2c34d2c8",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.8",
"_uccVersion": "5.49.0",
"_uccVersion": "5.50.0",
"supportedThemes": [
"light",
"dark"
Expand Down
1 change: 1 addition & 0 deletions ui/src/types/globalConfig/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export const OAuthFields = z.object({
})
.optional(),
modifyFieldsOnValue: ModifyFieldsOnValue,
validators: AllValidators.optional(),
});

export const OAuthEntity = CommonEditableEntityFields.extend({
Expand Down

0 comments on commit aafafa4

Please sign in to comment.