Skip to content

Commit

Permalink
feat: add proxy component (#1444)
Browse files Browse the repository at this point in the history
**Issue number:** ADDON-72372

## Summary
Similar to logging component, we now have a proxy component, also
introduced a new argument `--need-proxy` which includes default proxy
configuration during `init` method
### Changes

- Just like logging component we now have a new type `proxyTab` which
gives default proxy configuration, so that user doesn't have to mention
default configuration themselves they just have to mention their custom
configurations.

- Introduced a new argument in `init` method that is `--need-proxy`,
which includes default proxy configuration in `globalConfig.json` during
creation of new add-on.

- Changed the approach of fetching proxy_details in`oauth template`
file. For that created a function in solnlib which fetches proxy_details
and validates `proxy_host` and `proxy_port`.

### User experience

> Changes according to UX point of view :

- If user have to use our default configuration of proxy they just need
to define `type=proxyTab` in their globalConfig.
- They can add their custom validations for any field, but they would
have to use some specific keys for that
for ex. If a user wants to customize the label of `port` they would just
have to write
 `{
       "type": "proxyTab",
       "port": {
             "label": "Proxy port",
  }
} `
- Now users can validate their port and hostnames of proxy through
`get_proxy_dict` function of solnlib.
- While initializing an add-on user will have extra parameter
`--need-proxy` which includes default proxy configuration in
`globalConfig.json`.

## Checklist

If your change doesn't seem to apply, please leave them unchecked.

* [x] I have performed a self-review of this change
* [x] Changes have been tested
* [x] Changes are documented
* [x] PR title follows [conventional commit
semantics](https://www.conventionalcommits.org/en/v1.0.0/)

---------

Co-authored-by: Artem Rys <rysartem@gmail.com>
  • Loading branch information
hetangmodi-crest and artemrys authored Jan 7, 2025
1 parent f6cae67 commit 2241363
Show file tree
Hide file tree
Showing 37 changed files with 993 additions and 295 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ site/
assets/
Splunk_TA_Dynatrace/*
Splunk_TA_Dynatrace_ucc/*
demo_addon_for_splunk_already_exists/
demo_addon_for_splunk_license/
addon_name
demo_addon_for_splunk*/
addon_name/
init_addon_for_ucc_package/
demo_addon_for_splunk/

Expand Down
23 changes: 14 additions & 9 deletions docs/configurations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ tab.
Currently available tab components:

- [Logging tab](./logging.md)
- [Proxy tab](./proxy.md)

### Usage

Expand All @@ -56,12 +57,16 @@ Currently available tab components:
"entity": []
},
{
"name": "proxy",
"title": "Proxy",
"entity": [],
"options": {
"saveValidator": ""
}
"type": "proxyTab",
"warning": {
"config": {
"message": "Some warning message"
}
},
"proxy_type": true,
"username": true,
"password": true,
"dns_resolution": true
},
{
"type": "loggingTab"
Expand All @@ -70,7 +75,7 @@ Currently available tab components:
}
```

Note: The example above creates a Configuration page with two **empty** tabs: Account and Proxy.
Note: The example above creates a Configuration page with an **empty** Account tab.
Specify your properties in `"table"` and `"entity"`.

### Output
Expand All @@ -79,8 +84,8 @@ This is how table looks in the UI:

![image](../images/configuration/configuration_with_table_output.png)

This is how form looks in the UI:
This is how Proxy tab looks in the UI:

![image](../images/configuration/configuration_without_table_output.png)
![image](../images/configuration/proxy_tab_with_warning.png)

More information about how to set Proxy tab, can be found [here](./proxy.md).
309 changes: 210 additions & 99 deletions docs/configurations/proxy.md
Original file line number Diff line number Diff line change
@@ -1,120 +1,231 @@
# Proxy

There are fields that need to be specified in order to enable proxy.
The Proxy tab is a predefined component that allows to create a proxy tab with default configurations. It is added in the `pages.configuration.tabs` array

### Fields
![image](../images/configuration/proxy_tab.png)

| Field Name | Description |
|----------------|--------------------------------------------------------------------|
| proxy_enabled | Whether proxy should be enabled. |
| proxy_type | Proxy type. Available values: http, http_no_tunnel, socks4, socks5 |
| proxy_url | Host |
| proxy_port | Port |
| proxy_username | Username used to access the proxy server |
| proxy_password | Password assigned for that username |
| proxy_rdns | Whether reverse DNS resolution should be used |

### Example Tab
### Minimal definition

```json
{
"name": "proxy",
"title": "Proxy",
"entity": [
{
"type": "checkbox",
"label": "Enable",
"field": "proxy_enabled"
},
{
"type": "singleSelect",
"label": "Proxy Type",
"options": {
"disableSearch": true,
"autoCompleteFields": [
{
"value": "http",
"label": "http"
},
{
"value": "socks4",
"label": "socks4"
},
{
"value": "socks5",
"label": "socks5"
}
]
},
"defaultValue": "http",
"field": "proxy_type"
},
{
"type": "text",
"label": "Host",
"validators": [
{
"type": "string",
"errorMsg": "Max host length is 4096",
"minLength": 0,
"maxLength": 4096
}
],
"field": "proxy_url"
},
"type": "proxyTab"
}
```

This creates the tab seen in the image above with 3 default entities that are `Enable` (checkbox for enabling proxy), `Host` (proxy host) and `Port` (proxy port).

### Available configurations

Below are the available properties that can be used while configuring `proxy`. Properties like `name`, `title`, `enable proxy`, `host` and `port` are auto generated (if [minimal defination](#minimal-definition) of proxy is provided).

- Name (auto generated):

```
proxy
```

- Title (auto generated):

```
Proxy
```

- Enable proxy (auto generated) :

```json
{
"type": "checkbox",
"label": "Enable",
"field": "proxy_enabled"
}
```

- Proxy type :

```json
{
"type": "singleSelect",
"label": "Proxy Type",
"required": false,
"options": {
"disableSearch": true,
"autoCompleteFields": [
{"value": "http", "label": "http"},
{"value": "socks4", "label": "socks4"},
{"value": "socks5", "label": "socks5"},
],
},
"defaultValue": "http",
"field": "proxy_type",
}
```

- Host (auto generated) :

```json
{
"type": "text",
"label": "Host",
"validators": [
{
"type": "text",
"label": "Port",
"validators": [
{
"type": "number",
"range": [
1,
65535
]
}
],
"field": "proxy_port"
"type": "string",
"errorMsg": "Max host length is 4096",
"minLength": 0,
"maxLength": 4096,
},
{
"type": "text",
"label": "Username",
"validators": [
{
"type": "string",
"errorMsg": "Max length of username is 50",
"minLength": 0,
"maxLength": 50
}
],
"field": "proxy_username"
"type": "regex",
"errorMsg": "Proxy Host should not have special characters",
"pattern": "^[a-zA-Z]\\w*$",
},
],
"field": "proxy_url",
}
```

- Port (auto generated) :

```json
{
"type": "text",
"label": "Port",
"validators": [{"type": "number", "range": [1, 65535], "isInteger": true}],
"field": "proxy_port",
}
```

- Username :

```json
{
"type": "text",
"label": "Username",
"validators": [
{
"type": "text",
"label": "Password",
"validators": [
{
"type": "string",
"errorMsg": "Max length of password is 8192",
"minLength": 0,
"maxLength": 8192
}
],
"encrypted": true,
"field": "proxy_password"
},
"type": "string",
"errorMsg": "Max length of username is 50",
"minLength": 0,
"maxLength": 50,
}
],
"field": "proxy_username",
}
```

- Password :

```json
{
"type": "text",
"label": "Password",
"validators": [
{
"type": "checkbox",
"label": "Reverse DNS resolution",
"field": "proxy_rdns"
"type": "string",
"errorMsg": "Max length of password is 8192",
"minLength": 0,
"maxLength": 8192,
}
],
"options": {
"saveValidator": "function(formData) { if(!formData.proxy_enabled || formData.proxy_enabled === '0') {return true; } if(!formData.proxy_url) { return 'Proxy Host can not be empty'; } if(!formData.proxy_port) { return 'Proxy Port can not be empty'; } return true; }"
"encrypted": true,
"field": "proxy_password",
}
```

- DNS Resolution checkbox :

```json
{
"type": "checkbox",
"label": "DNS resolution",
"field": "proxy_rdns",
}
```


When only `"type": "proxyTab"` is specified in the globalConfig file, the following entities will be generated by default `host`, `port`, `enable proxy`.

Entities such as `proxy_type`, `username`, `password`, and `dns_resolution` will not be included by default.
To include these optional entities in your add-on, you must explicitly set them to `True` in your configuration. For details on available configurations, refer to the [available configurations](#available-configurations) section.

### Usage

It is placed just like every other configuration tab.

```json
{
"pages": {
"configuration": {
"tabs": [
{
"type": "proxyTab"
}
],
"title": "Configuration",
"description": "..."
}
}
}
```

The example above creates the following form:
To customize these default configurations, you can define them in JSON format by specifying certain keys unique to each entity (refer the [keys section](#keys) for details on the required keys for each entity). When creating the JSON, you only need to include the values you want to customize. For example, if you don’t need to modify fields like `lable` or `field`, you can skip including them in your globalConfig. For better understanding, refer to the provided [Example](#example) which demonstrates how to apply customizations effectively.

> **_NOTE:_**
There are 2 ways to exclude optional entities in your add-on, either omit them from the proxy tab, or set the entities to false.

### Keys

| Key Name | Description |
|----------------|--------------------------------------------------------------------|
| name | Name of the proxy |
| title | Title of proxy tab |
| enable_proxy | Whether proxy should be enabled |
| proxy_type | Type of Proxy communication protocols supported. Default: `SOCKS4`, `SOCKS5`, `HTTP` |
| host | Hostname (FQDN, IPv6 or IPv4) of the Proxy server |
| port | Port of the Proxy server that accepts the connection |
| username | Username used to authenticate the access to Proxy Server |
| password | Password for the provided username to authenticate access to Proxy Server |
| dns_resolution | Whether DNS resolution should be done by Proxy server or not |


### Example

![image](../images/configuration/configuration_without_table_output.png)
```json
{
"type": "proxyTab",
"name": "custom_proxy",
"warning": {
"config": {
"message": "Some warning message"
}
},
"port": {
"label": "Proxy port",
"validator": [
{
"type": "number",
"range": [
1025,
65535
],
"isInteger": true
}
]
},
"username": true,
"password": {
"label": "Password for Proxy"
},
"dns_resolution": false,
}
```

The above will get converted to the older definition (mentioned below) in your output directory.

![image](../images/configuration/proxy_tab_custom.png)

```json
{
--8<-- "tests/unit/tabs/test_proxy_tab.py:9:69"
}
```
Binary file added docs/images/configuration/proxy_tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/configuration/proxy_tab_custom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2241363

Please sign in to comment.