Skip to content

Commit 699c0d4

Browse files
committed
starting cli
1 parent 53d44f6 commit 699c0d4

40 files changed

+4426
-22
lines changed

cli/Cargo.lock

+2,343
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[package]
2+
name = "daikokucli"
3+
version = "0.0.1"
4+
edition = "2021"
5+
authors = ["Zwiterrion <etienne.anne@icloud.com>"]
6+
license = "MIT OR Apache-2.0"
7+
description = "A CLI to create and build WASM binaries"
8+
readme = "README.md"
9+
homepage = "https://github.com/MAIF/wasmo"
10+
repository = "https://github.com/MAIF/wasmo"
11+
keywords = ["cli", "wasm", "build", "webassembly"]
12+
categories = ["command-line-utilities"]
13+
14+
[[bin]]
15+
name = "wasmo"
16+
path = "src/bin.rs"
17+
18+
[dependencies]
19+
clap = { version = "4.4.6", features = ["derive"] }
20+
home = "0.5.5"
21+
paris = {version = "1.5"}
22+
zip-extensions = "0.6.2"
23+
hyper = { version = "1", features = ["full"] }
24+
hyper-util = { version = "0.1", features = ["full"] }
25+
tokio-tungstenite = { version = "0.20.1", features = ["native-tls"] }
26+
tokio = { version = "1", features = ["full"] }
27+
serde_json = "1.0.107"
28+
lazy_static = "1.4.0"
29+
serde = { version = "1.0.189", features = ["derive"] }
30+
toml = "0.8.2"
31+
futures-util = "0.3.28"
32+
http-body-util = "0.1"
33+
bytes = "1.5.0"
34+
error-stack = "0.4.1"
35+
dirs = "5.0.1"
36+
chrono = "0.4.31"
37+
once_cell = "1.18.0"
38+
hyper-tls = "0.5.0"
39+
base64 = "0.21.5"
40+
futures-channel = "0.3.29"
41+
42+
[dev-dependencies]
43+
serial_test = "2.0.0"
44+
assert_cmd = "2.0.12"
45+
predicates = "3.0.4"
46+
assert_fs = "1.0.13"

cli/README.md

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<div align="center">
2+
<h1><code>wasmo</code></h1>
3+
4+
<strong>A <a href="https://github.com/MAIF/">MAIF</a> opensource project</strong>
5+
6+
<p>
7+
<strong>Wasmo CLI brings WASM to your architecture</strong>
8+
</p>
9+
10+
<p>
11+
Wasmo CLI can be combined with the power of <a href="https://hub.docker.com/r/maif/wasmo">Docker Wasmo server images</a> to build locally and remotely WASM binaries.
12+
</p>
13+
</div>
14+
15+
16+
# Installation
17+
18+
This project can be installed and compiled from source with this Cargo command:
19+
20+
```
21+
$ cargo install wasmo
22+
or
23+
$ brew tap maif/wasmo
24+
$ brew install wasmo
25+
```
26+
27+
Additionally there are [precompiled artifacts built on CI][artifacts] which are
28+
available for download as well.
29+
30+
[artifacts]: https://github.com/MAIF/wasmo/releases
31+
32+
Installation can be confirmed with:
33+
34+
```
35+
$ wasmo --version
36+
```
37+
38+
Subcommands can be explored with:
39+
40+
```
41+
$ wasmo help
42+
```
43+
44+
# Core commands
45+
46+
The `wasmo` CLI internally contains a number of subcommands for working
47+
with wasm modules:
48+
49+
| Tool | Arguments | Description |
50+
| ---------------------------- | -- | ------------------------------------------------------------- |
51+
| `wasmo config set` | path &#124; server &#124; clientId &#124; clientSecret | Globally configure the CLI with the path where the configuration file will be stored and the server to reach during the build. These parameters are optional and can be passed when running the build command. |
52+
| `wasmo config get` | | Get the configuration from the configured path file or from `$HOME/.wasmo` |
53+
| `wasmo config reset` | | Clean configuration and reset to default settings. The default file path configuration will be `$HOME/.wasmo` ||
54+
| `wasmo init` | template &#124; name &#124; path | Initialize a WASM plugin to the specific path. You can choose between many templates, javascript/typescript (js/ts), Open Policy Agent (opa), Rust or Golang (go). |
55+
| `wasmo build` | path &#124; host &#124; server &#124; clientId &#124; clientSecret | Build the plugin by sending the contents to the remote or local Wasmo server. As soon as the build is complete, the WASM binary is donwloaded and saved in the plugin folder. |
56+
57+
# Quick start
58+
59+
```
60+
wasmo init --name=my-first-plugin --template=js
61+
wasmo build --host=OneShotDocker --path=my-first-plugin
62+
```
63+
64+
Then open the content of your `my-first-plugin` folder. You should find the generated WASM binary named `my-first-plugin-1.0.0.wasm`.
65+
66+
## Selecting a template
67+
68+
You can now optionally start a new plugin from a template by appending `--template=[template-name]` to the creation command.
69+
70+
If you don't pass a template, Wasmo will list the available templates: `js`, `ts`, `opa`, `go` and `rust`.
71+
72+
```
73+
wasmo init --name=my-first-plugin --template=[template-name] --path=[output-directory]
74+
```
75+
76+
Running this command with any of theses templates will create a directory called `my-first-plugin` inside the specified output directory (or the current if omitted). Inside that directory, it will generate the initial project structure with the metadata file pre-filled with the name of your plugin.
77+
78+
## Creating a production WASM binary
79+
80+
`wasmo build` starts the process to build a WASM binary of your plugin. Inside the plugin directory will be your WASM binary and sources.
81+
82+
You have two ways to build your plugin:
83+
- locally with Docker
84+
- remotely by deploying a [Wasmo server][wasmoserver]
85+
86+
[wasmoserver]: https://github.com/MAIF/wasmo
87+
88+
Assuming we want to build our `my-first-plugin` locally. Enter `wasmo build --host=OneShotDocker --path=my-first-plugin` to start the build.
89+
90+
Let's explain these 3 parameters:
91+
- the `path` parameter is explicitly used to indicate the plugin to build
92+
- the `host` indicates which kind of Wasmo server used. The pratical way is to use `Docker` or `OneShotDocker` because it prevents to install a Wasmo server by deploying, inside your locally Docker, a new Wasmo container. The last possible value is `Remote` and can be used to specify with a URI the remote Wasmo server used.
93+
<!--
94+
[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/NdbQR6vQ5Sk/0.jpg)](https://www.youtube.com/watch?v=NdbQR6vQ5Sk) -->
95+
96+
## Configure your configuration file
97+
98+
```
99+
wasmo config get
100+
wasmo config reset
101+
wasmo config set <key>=<value>
102+
```
103+
Note: This command is unaware of workspaces.
104+
105+
### Description
106+
107+
wasmo gets its config from the command line, environment variables, `.wasmo` files, and in some cases, directly from the build command.
108+
109+
The `wasmo config` command can be used to update and edit the contents of the user and global wasmo files.
110+
111+
### Sub-commands
112+
113+
#### set
114+
115+
```
116+
wasmo config set <key>=<value>
117+
```
118+
119+
Sets each of the config keys to the value provided.
120+
121+
If value is omitted, then it sets it to an empty string.
122+
123+
The available keys are:
124+
- `path`: configure the path where the wasmo configuration will be stored
125+
- `server`: the Wasmo server to build your plugins (an URL format value is expected)
126+
- `clientId`: the client id used in Basic and Otoroshi Auth
127+
- `clientSecret`: the client secret used in Basic and Otoroshi Auth
128+
129+
You can also edit the configuration file manually. In this case, the following values are :
130+
- `path` = WASMO_PATH
131+
- `server` = WASMO_SERVER
132+
133+
#### get
134+
135+
```
136+
wasmo config get
137+
```
138+
139+
Show all the config settings.
140+
141+
142+
#### reset
143+
144+
```
145+
wasmo config get
146+
```
147+
148+
Reset the configuration file with the default settings. The custom user `.wasmo` files will not be deleted.
149+
150+
# License
151+
152+
This project is licensed under the Apache 2.0 license with the LLVM exception.
153+
154+
### Contribution
155+
156+
Unless you explicitly state otherwise, any contribution intentionally submitted
157+
for inclusion in this project by you, as defined in the Apache-2.0 license,
158+
shall be licensed as above, without any additional terms or conditions.

cli/my-first-cms/.daikokuignore

Whitespace-only changes.

cli/my-first-cms/src/blocks/.gitkeep

Whitespace-only changes.

cli/my-first-cms/src/pages/.gitkeep

Whitespace-only changes.

cli/my-first-cms/src/pages/404.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<DOCTYPE html>
2+
<html>
3+
<head></head>
4+
<body>
5+
<h1>404 not found</h1>
6+
</body>
7+
</html>

cli/my-first-cms/src/pages/API.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{#daikoku-api "{{daikoku-path-param '0'}}"}}
2+
3+
{{#daikoku-template-wrapper "61fbaa95320100dbfca04d11" title="{{api.name}}" desc="Description de mon API" }}
4+
5+
<h2 class="my-3">List of plans</h2>
6+
{{daikoku-include-block "6203d2de140100e435e7bdd0"}}
7+
8+
9+
<h2 class="my-3">Complète Description</h2>
10+
<div>
11+
{{api.description}}
12+
</div>
13+
<button type="button" class="btn btn-secondary mt-3">
14+
<a href="{{daikoku-page-url "62027afe1501007a8439fa48"}}" style="color: #fff; text-decoration: none">Retour à la liste d'APIS</a>
15+
</button>
16+
17+
{{/daikoku-template-wrapper}}
18+
{{/daikoku-api}}

cli/my-first-cms/src/pages/APIS.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{#daikoku-template-wrapper "61fbaa95320100dbfca04d11" title="Nos APIS" desc="La liste complète de nos offres"}}
2+
3+
<div class="row">
4+
{{#daikoku-apis}}
5+
{{daikoku-include-block "62026d251501007a8439f599" slug="/{{api._id}}" content="{{api.description}}" title="{{api.name}}" version="{{api.currentVersion}}"}}
6+
{{/daikoku-apis}}
7+
</div>
8+
{{/daikoku-template-wrapper}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function askForApiKey(api, plan) {
2+
3+
const options = {
4+
credentials: 'include',
5+
headers: {
6+
Accept: 'application/json',
7+
'Content-type': 'application/json',
8+
}
9+
}
10+
11+
fetch('/api/me/teams/own', options)
12+
.then(r => r.json())
13+
.then(team => {
14+
console.log("askForApiKey", api, plan, team)
15+
fetch(`/api/apis/${api}/subscriptions`, {
16+
...options,
17+
method: 'POST',
18+
body: JSON.stringify({
19+
plan,
20+
teams: [team._id]
21+
})
22+
})
23+
.then(r => {
24+
if(r.status === 200) {
25+
r.json()
26+
.then(subscriptions => {
27+
if(subscriptions[0].error) {
28+
const id = `subscription-error-${plan}`
29+
document.getElementById(id).innerHTML = subscriptions[0].error
30+
document.getElementById(id).style.display = 'block'
31+
} else {
32+
const keyId = `subscription-success-key-${plan}`
33+
const secretId = `subscription-success-secret-${plan}`
34+
document.getElementById(keyId).innerHTML = subscriptions[0].subscription.apiKey.clientId
35+
document.getElementById(secretId).innerHTML = subscriptions[0].subscription.apiKey.clientSecret
36+
document.getElementById(`subscription-success-${plan}`).style.display = 'block'
37+
}
38+
39+
})
40+
}
41+
})
42+
.catch(r => console.log(r))
43+
})
44+
}

cli/my-first-cms/src/pages/Card.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div class="col-sm-4">
2+
<div class="card mb-3">
3+
<h3 class="card-header">{{title}} {{#if version}} - ({{version}}) {{/if}}</h3>
4+
<img src="{{url}}" style="max-height: 200px; width: auto; object-fit: cover"/>
5+
<div class="card-body mb-2" style="max-height: 200px; overflow: scroll; overflow-x: hidden">
6+
<p class="card-text">{{content}}</p>
7+
{{#if sub_content}}
8+
{{sub_content}}
9+
{{/if}}
10+
</div>
11+
{{#unless teamView}}
12+
<div class="mx-auto my-3">
13+
<button type="button" class="btn btn-success">
14+
<a href="{{daikoku-page-url "6203bde7190100d46b9e3777"}}{{slug}}" style="color: #fff; text-decoration: none">Voir l'API</a>
15+
</button>
16+
</div>
17+
{{/unless}}
18+
</div>
19+
</div>
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<footer>
2+
<div class="container py-5">
3+
<div class="row py-4">
4+
<div class="col-lg-4 col-md-6 mb-4 mb-lg-0"><img
5+
style="border-radius: 25%"
6+
src="{{daikoku-asset-url 'dad1d1655-604b-4274-92e8-28e254b8c32e'}}"
7+
alt="" width="180" class="mb-3">
8+
<p class="font-italic text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.</p>
9+
<ul class="list-inline mt-4">
10+
<li class="list-inline-item"><a href="#" target="_blank" title="twitter"><i class="fab fa-twitter"></i></a></li>
11+
<li class="list-inline-item"><a href="#" target="_blank" title="facebook"><i class="fab fa-facebook"></i></a></li>
12+
<li class="list-inline-item"><a href="#" target="_blank" title="instagram"><i class="fab fa-instagram"></i></a></li>
13+
<li class="list-inline-item"><a href="#" target="_blank" title="pinterest"><i class="fab fa-pinterest"></i></a></li>
14+
<li class="list-inline-item"><a href="#" target="_blank" title="vimeo"><i class="fab fa-vimeo"></i></a></li>
15+
</ul>
16+
</div>
17+
<div class="col-lg-2 col-md-6 mb-4 mb-lg-0">
18+
<h6 class="text-uppercase font-weight-bold mb-4">APIS</h6>
19+
<ul class="list-unstyled mb-0">
20+
<li class="mb-2"><a href="#" class="text-muted">Contrats</a></li>
21+
<li class="mb-2"><a href="#" class="text-muted">Sinistres</a></li>
22+
<li class="mb-2"><a href="#" class="text-muted">Sports</a></li>
23+
<li class="mb-2"><a href="#" class="text-muted">Music</a></li>
24+
</ul>
25+
</div>
26+
<div class="col-lg-2 col-md-6 mb-4 mb-lg-0">
27+
<h6 class="text-uppercase font-weight-bold mb-4">MAIF</h6>
28+
<ul class="list-unstyled mb-0">
29+
<li class="mb-2"><a href="/auth/Local/login" class="text-muted">Login</a></li>
30+
<li class="mb-2"><a href="/auth/Local/register" class="text-muted">Register</a></li>
31+
</ul>
32+
</div>
33+
<div class="col-lg-4 col-md-6 mb-lg-0">
34+
<h6 class="text-uppercase font-weight-bold mb-4">Actualités</h6>
35+
<p class="text-muted mb-4">Lorem ipsum dolor sit amet, consectetur adipisicing elit. At itaque temporibus.</p>
36+
<div class="p-1 rounded border">
37+
<div class="input-group">
38+
<input type="email" placeholder="Enter your email address" aria-describedby="button-addon1" class="form-control border-0 shadow-0">
39+
<div class="input-group-append">
40+
<button id="button-addon1" type="submit" class="btn btn-link"><i class="fa fa-paper-plane"></i></button>
41+
</div>
42+
</div>
43+
</div>
44+
</div>
45+
</div>
46+
</div>

cli/my-first-cms/src/pages/Home.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{#daikoku-template-wrapper "61fbaa95320100dbfca04d11" title="Page d'accueil de mon tenant" desc="Les dernières actualités de notre tenant"}}
2+
3+
4+
<div id="news" class="row"></div>
5+
6+
<script src="{{daikoku-page-url "620267e81501007a8439f3fb"}}"></script>
7+
{{/daikoku-template-wrapper}}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{#daikoku-template-wrapper "61fbaa95320100dbfca04d11" title="Mes APIS" desc="Seulement celles pour lesquelles je suis autorisé"}}
2+
3+
<div class="row">
4+
{{#daikoku-owned-apis visibility="Private"}}
5+
{{daikoku-include-block "62026d251501007a8439f599" slug="/{{api._id}}" content="{{api.description}}" title="{{api.name}}" version="{{api.currentVersion}}"}}
6+
{{/daikoku-owned-apis}}
7+
</div>
8+
{{/daikoku-template-wrapper}}
9+

0 commit comments

Comments
 (0)