Skip to content

Commit

Permalink
expose configuration to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
reddec committed May 5, 2020
1 parent de5104b commit 839e451
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/tinc-web-boot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (m *Root) Run(global *globalContext) error {
AuthKey: m.AuthKey,
LocalUIPort: uint16(port),
PublicAddresses: m.UIPublicAddress,
Binding: m.Bind,
}
webApi, uiApp := apiCfg.New(pool)
if !m.Headless {
Expand Down
26 changes: 25 additions & 1 deletion docs/tinc_web_ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Operations with tinc-web-boot related to UI
* [TincWebUI.IssueAccessToken](#tincwebuiissueaccesstoken) - Issue and sign token
* [TincWebUI.Notify](#tincwebuinotify) - Make desktop notification if system supports it
* [TincWebUI.Endpoints](#tincwebuiendpoints) - Endpoints list to access web UI
* [TincWebUI.Configuration](#tincwebuiconfiguration) - Configuration defined for the instance



Expand Down Expand Up @@ -81,4 +82,27 @@ EOF
|------|------|---------|
| host | `string` | |
| port | `uint16` | |
| kind | `EndpointKind` | |
| kind | `EndpointKind` | |

## TincWebUI.Configuration

Configuration defined for the instance

* Method: `TincWebUI.Configuration`
* Returns: `*Config`

```bash
curl -H 'Content-Type: application/json' --data-binary @- "http://127.0.0.1:8686/api/" <<EOF
{
"jsonrpc" : "2.0",
"id" : 1,
"method" : "TincWebUI.Configuration",
"params" : []
}
EOF
```
### Config

| Json | Type | Comment |
|------|------|---------|
| binding | `string` | |
11 changes: 11 additions & 0 deletions support/go/tincwebui/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ type Endpoint struct {
Kind EndpointKind `json:"kind"`
}

//
type Config struct {
Binding string `json:"binding"`
}

func Default() *TincWebUIClient {
return &TincWebUIClient{BaseURL: "http://127.0.0.1:8686/api/"}
}
Expand All @@ -46,3 +51,9 @@ func (impl *TincWebUIClient) Endpoints(ctx context.Context) (reply []Endpoint, e
err = client.CallHTTP(ctx, impl.BaseURL, "TincWebUI.Endpoints", atomic.AddUint64(&impl.sequence, 1), &reply)
return
}

// Configuration defined for the instance
func (impl *TincWebUIClient) Configuration(ctx context.Context) (reply *Config, err error) {
err = client.CallHTTP(ctx, impl.BaseURL, "TincWebUI.Configuration", atomic.AddUint64(&impl.sequence, 1), &reply)
return
}
12 changes: 12 additions & 0 deletions support/js/tincwebui.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ export class TincWebUI {
}));
}

/**
Configuration defined for the instance
**/
async configuration(){
return (await this.__call('Configuration', {
"jsonrpc" : "2.0",
"method" : "TincWebUI.Configuration",
"id" : this.__next_id(),
"params" : []
}));
}



__next_id() {
Expand Down
39 changes: 39 additions & 0 deletions support/postman/tincwebui.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,45 @@
},
"description": "# TincWebUI.Endpoints\n\nEndpoints list to access web UI\n\n* Method: `TincWebUI.Endpoints`\n* Returns: `[]Endpoint`\n\n### Endpoint\n\n| Json | Type | Comment |\n|------|------|---------|\n| host | `string` | |\n| port | `uint16` | |\n| kind | `EndpointKind` | |\n\n"
}
},
{
"name": "Configuration",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"jsonrpc\": \"2.0\",\n \"method\": \"TincWebUI.Configuration\",\n \"id\": 1,\n \"params\": {}\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://127.0.0.1:8686/api/",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"port": "8686",
"path": [
"",
"api",
""
]
},
"description": "# TincWebUI.Configuration\n\nConfiguration defined for the instance\n\n* Method: `TincWebUI.Configuration`\n* Returns: `*Config`\n\n### Config\n\n| Json | Type | Comment |\n|------|------|---------|\n| binding | `string` | |\n\n"
}
}
]
}
32 changes: 32 additions & 0 deletions support/python/tincwebui.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ def from_json(payload: dict) -> 'Endpoint':
)


@dataclass
class Config:
binding: 'str'

def to_json(self) -> dict:
return {
"binding": self.binding,
}

@staticmethod
def from_json(payload: dict) -> 'Config':
return Config(
binding=payload['binding'],
)


class TincWebUIError(RuntimeError):
def __init__(self, method: str, code: int, message: str, data: Any):
super().__init__('{}: {}: {} - {}'.format(method, code, message, data))
Expand Down Expand Up @@ -119,3 +135,19 @@ async def endpoints(self) -> List[Endpoint]:
if 'error' in payload:
raise TincWebUIError.from_json('endpoints', payload['error'])
return [Endpoint.from_json(x) for x in (payload['result'] or [])]

async def configuration(self) -> Config:
"""
Configuration defined for the instance
"""
response = await self.__request('POST', self.__url, json={
"jsonrpc": "2.0",
"method": "TincWebUI.Configuration",
"id": self.__next_id(),
"params": []
})
assert response.status // 100 == 2, str(response.status) + " " + str(response.reason)
payload = await response.json()
if 'error' in payload:
raise TincWebUIError.from_json('configuration', payload['error'])
return Config.from_json(payload['result'])
2 changes: 1 addition & 1 deletion support/ts/tincweb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface Upgrade {



export type Duration = string; // suffixes: ns, us, ms, s, m, h (!!!!)
export type Duration = string; // suffixes: ns, us, ms, s, m, h


// support stuff
Expand Down
16 changes: 16 additions & 0 deletions support/ts/tincwebui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export interface Endpoint {
kind: EndpointKind
}

export interface Config {
binding: string
}



export enum EndpointKind {
Expand Down Expand Up @@ -220,6 +224,18 @@ export class TincWebUI {
})) as Array<Endpoint>;
}

/**
Configuration defined for the instance
**/
async configuration(): Promise<Config> {
return (await this.__call({
"jsonrpc" : "2.0",
"method" : "TincWebUI.Configuration",
"id" : this.__next_id(),
"params" : []
})) as Config;
}


private __next_id() {
this.__id += 1;
Expand Down
6 changes: 5 additions & 1 deletion web/internal/tinc_web_ui.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions web/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Config struct {
AuthKey string
LocalUIPort uint16
PublicAddresses []string
Binding string
}

//go:generate go-bindata -pkg web -prefix ui/build/ -fs ui/build/...
Expand Down Expand Up @@ -60,6 +61,7 @@ func (cfg Config) New(pool *tincd.Tincd) (*gin.Engine, *uiRoutes) {
port: cfg.LocalUIPort,
publicAddress: cfg.PublicAddresses,
pool: pool,
config: shared.Config{Binding: cfg.Binding},
}

internal.RegisterTincWeb(&jsonRouter, &api{pool: pool, publicAddress: cfg.PublicAddresses, key: cfg.AuthKey})
Expand Down
5 changes: 5 additions & 0 deletions web/routes_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type uiRoutes struct {
key string
port uint16
publicAddress []string
config shared.Config
pool *tincd.Tincd
}

Expand Down Expand Up @@ -78,3 +79,7 @@ func (srv *uiRoutes) Endpoints() ([]shared.Endpoint, error) {
}
return ans, nil
}

func (srv *uiRoutes) Configuration() (*shared.Config, error) {
return &srv.config, nil
}
6 changes: 6 additions & 0 deletions web/shared/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ type Endpoint struct {
Kind EndpointKind `json:"kind"`
}

type Config struct {
Binding string `json:"binding"`
}

// Operations with tinc-web-boot related to UI
type TincWebUI interface {
// Issue and sign token
Expand All @@ -79,6 +83,8 @@ type TincWebUI interface {
Notify(title, message string) (bool, error)
// Endpoints list to access web UI
Endpoints() ([]Endpoint, error)
// Configuration defined for the instance
Configuration() (*Config, error)
}

// Operations for joining public network
Expand Down

0 comments on commit 839e451

Please sign in to comment.