-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**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
1 parent
f6cae67
commit 2241363
Showing
37 changed files
with
993 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
``` |
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.