Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Deploy: add explicit config field in webportal plugin (#2251)
Browse files Browse the repository at this point in the history
* Deploy: add explicit config field in webportal  plugin

* Fix json.dumps

* t

* fix

* Update PLUGINS.md

* Update webportal.md
  • Loading branch information
Gerhut authored Mar 4, 2019
1 parent f62b1bb commit 214f84e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/webportal/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ webportal:
plugins:
- title: Marketplace
uri: /scripts/plugins/marketplace.bundle.js
config:
repo: Microsoft/pai
```
- The `title` field is the title of the web portal plugin listed in the menu, it could be customized by administrators for the same plugin with different configurations.
- The `uri` field is the entry file of the web portal plugin, usually previded by the plugin developer. It may be an absolute URL or a root-relative URL, as the different deploy type of the web portal plugin.
- The `config` field is a key-value dictionary to configure the web portal plugin, available configs are listed in web portal plugin's specific document.

In addition, you can also lock the plugin version if the uri refers the Internet, follow the [Publish](#publish) section to move the online web portal plugin to offline.

Expand Down Expand Up @@ -50,7 +53,7 @@ If any other PAI configuration is needed, please open an issue, PAI developers w

### Provide Plugin Configurations

Ask system administration to set the query string of the entry file, like `http://example.com/github-plugin.js?repo=Microsoft%2Fpai`, `document.currentScript.src` would help you get the full uri of the script, including the query string.
The config of the plugin will be set as the query string of the entry file, like `http://example.com/github-plugin.js?repo=Microsoft%2Fpai`, `document.currentScript.src` would help you get the full uri of the script, including the query string.

### Migrate Current AI Web Tools to PAI Web Portal Plugin

Expand Down
2 changes: 2 additions & 0 deletions src/webportal/config/webportal.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ webportal:
server-port: new-value
```
About config the web portal plugin, see [PLUGINS.md](../../../docs/webportal/PLUGINS.md)
## Generated Configuration <a name="G_Config"></a>
After parsing, object model looks like:
Expand Down
15 changes: 14 additions & 1 deletion src/webportal/config/webportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import json
import urllib
import urlparse


class Webportal:
Expand All @@ -40,6 +42,17 @@ def validation_pre(self):
def run(self):
# parse your service object model here, and return a generated dictionary

def apply_config(plugin):
uri = plugin['uri']
if 'config' in plugin:
# Python 2 only uses urlquote_plus in urlencode
config_query = urllib.urlencode(plugin['config'], True).replace('+', '%20')
uri = urlparse.urljoin(uri, '?' + config_query)
return {
'title': plugin['title'],
'uri': uri,
}

machine_list = self.cluster_configuration['machine-list']
master_ip = [host['hostip'] for host in machine_list if host.get('pai-master') == 'true'][0]
server_port = self.service_configuration['server-port']
Expand All @@ -48,7 +61,7 @@ def run(self):
return {
'server-port': server_port,
'uri': uri,
'plugins': json.dumps(plugins),
'plugins': json.dumps([apply_config(plugin) for plugin in plugins]),
}

#### All service and main module (kubrenetes, machine) is generated. And in this check steps, you could refer to the service object model which you will used in your own service, and check its existence and correctness.
Expand Down

0 comments on commit 214f84e

Please sign in to comment.