runit-cli 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- runit-cli-0.3.2/LICENSE +21 -0
- runit-cli-0.3.2/MANIFEST.in +4 -0
- runit-cli-0.3.2/PKG-INFO +127 -0
- runit-cli-0.3.2/README.md +99 -0
- runit-cli-0.3.2/runit/Request.py +24 -0
- runit-cli-0.3.2/runit/__init__.py +10 -0
- runit-cli-0.3.2/runit/cli.py +355 -0
- runit-cli-0.3.2/runit/constants.py +54 -0
- runit-cli-0.3.2/runit/core.py +128 -0
- runit-cli-0.3.2/runit/exceptions.py +8 -0
- runit-cli-0.3.2/runit/languages/__init__.py +36 -0
- runit-cli-0.3.2/runit/languages/javascript.py +16 -0
- runit-cli-0.3.2/runit/languages/multi.py +102 -0
- runit-cli-0.3.2/runit/languages/php.py +15 -0
- runit-cli-0.3.2/runit/languages/python.py +15 -0
- runit-cli-0.3.2/runit/languages/runtime.py +88 -0
- runit-cli-0.3.2/runit/modules/__init__.py +1 -0
- runit-cli-0.3.2/runit/modules/account.py +336 -0
- runit-cli-0.3.2/runit/runit.py +466 -0
- runit-cli-0.3.2/runit/templates/.runitignore +8 -0
- runit-cli-0.3.2/runit/templates/404.html +40 -0
- runit-cli-0.3.2/runit/templates/javascript/main.js +15 -0
- runit-cli-0.3.2/runit/templates/javascript/package.json +16 -0
- runit-cli-0.3.2/runit/templates/javascript/runit.json +14 -0
- runit-cli-0.3.2/runit/templates/multi/application.py +31 -0
- runit-cli-0.3.2/runit/templates/multi/composer.json +12 -0
- runit-cli-0.3.2/runit/templates/multi/index.php +22 -0
- runit-cli-0.3.2/runit/templates/multi/main.js +15 -0
- runit-cli-0.3.2/runit/templates/multi/package.json +16 -0
- runit-cli-0.3.2/runit/templates/multi/request.php +15 -0
- runit-cli-0.3.2/runit/templates/multi/requirements.txt +0 -0
- runit-cli-0.3.2/runit/templates/multi/test.php +3 -0
- runit-cli-0.3.2/runit/templates/php/composer.json +12 -0
- runit-cli-0.3.2/runit/templates/php/index.php +22 -0
- runit-cli-0.3.2/runit/templates/php/runit.json +14 -0
- runit-cli-0.3.2/runit/templates/python/application.py +31 -0
- runit-cli-0.3.2/runit/templates/python/requirements.txt +1 -0
- runit-cli-0.3.2/runit/templates/python/runit.json +14 -0
- runit-cli-0.3.2/runit/templates/request.php +15 -0
- runit-cli-0.3.2/runit/templates/runit.json +15 -0
- runit-cli-0.3.2/runit/test.py +27 -0
- runit-cli-0.3.2/runit/tools/javascript/loader.js +10 -0
- runit-cli-0.3.2/runit/tools/javascript/runner.js +23 -0
- runit-cli-0.3.2/runit/tools/php/loader.php +19 -0
- runit-cli-0.3.2/runit/tools/php/runner.php +33 -0
- runit-cli-0.3.2/runit/tools/python/loader.py +15 -0
- runit-cli-0.3.2/runit/tools/python/runner.py +26 -0
- runit-cli-0.3.2/runit_cli.egg-info/PKG-INFO +127 -0
- runit-cli-0.3.2/runit_cli.egg-info/SOURCES.txt +53 -0
- runit-cli-0.3.2/runit_cli.egg-info/dependency_links.txt +1 -0
- runit-cli-0.3.2/runit_cli.egg-info/entry_points.txt +2 -0
- runit-cli-0.3.2/runit_cli.egg-info/requires.txt +6 -0
- runit-cli-0.3.2/runit_cli.egg-info/top_level.txt +1 -0
- runit-cli-0.3.2/setup.cfg +4 -0
- runit-cli-0.3.2/setup.py +43 -0
runit-cli-0.3.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Amos Amissah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
runit-cli-0.3.2/PKG-INFO
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: runit-cli
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: Develop serverless applications
|
|
5
|
+
Author: Amos Amissah
|
|
6
|
+
Author-email: theonlyamos@gmail.com
|
|
7
|
+
Project-URL: Source, https://github.com/theonlyamos/runit/
|
|
8
|
+
Project-URL: Tracker, https://github.com/theonlyamos/runit/issues
|
|
9
|
+
Keywords: python3 runit developer serverless architecture docker
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: requests
|
|
23
|
+
Requires-Dist: python-dotenv
|
|
24
|
+
Requires-Dist: fastapi
|
|
25
|
+
Requires-Dist: passlib
|
|
26
|
+
Requires-Dist: docker
|
|
27
|
+
Requires-Dist: uvicorn
|
|
28
|
+
|
|
29
|
+
# Runit CLI 
|
|
30
|
+
The Runit Command Line Interface (CLI) Tools can be used to test, manage, and deploy your Runit project from the command line.
|
|
31
|
+
- Create new runit project
|
|
32
|
+
- Run a local web server for your runit project
|
|
33
|
+
- publish code and assets to your runit-server domain
|
|
34
|
+
- Interact with data in your runit-server database
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Supported Languages
|
|
38
|
+
  
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
### Python Package
|
|
42
|
+
You can install the Runit CLI using pip (Python package manager). Note that you will need to install [Python](https://python.org).
|
|
43
|
+
To download and install the runit CLI run the following command:
|
|
44
|
+
```shell
|
|
45
|
+
pip install runit
|
|
46
|
+
```
|
|
47
|
+
This will provide you with the globally accessible ```runit``` command.
|
|
48
|
+
|
|
49
|
+
### Install from source
|
|
50
|
+
```shell
|
|
51
|
+
git clone https://github.com/theonlyamos/runit.git
|
|
52
|
+
cd runit
|
|
53
|
+
pip install .
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
Run the below command to print out usage message.
|
|
58
|
+
```shell
|
|
59
|
+
runit --help
|
|
60
|
+
```
|
|
61
|
+

|
|
62
|
+
|
|
63
|
+
**Create New Project**
|
|
64
|
+
Run the following in the command line to create a new runit project.
|
|
65
|
+
> Supported languages include: [Python](), [Javascript](), [PHP]()
|
|
66
|
+
```shell
|
|
67
|
+
runit new <project-name> --language <langugage>
|
|
68
|
+
```
|
|
69
|
+
Run ```runit new --help``` for all options
|
|
70
|
+
|
|
71
|
+
**Run project locally**
|
|
72
|
+
***Access functions on local server****
|
|
73
|
+
Running the command ```runit``` in a project directory spins up a local webserver which can be used to access the funtions in project.
|
|
74
|
+
```shell
|
|
75
|
+
cd <project-directory>
|
|
76
|
+
runit
|
|
77
|
+
```
|
|
78
|
+
Point your browser to the address provided followed by the function name to access that function.
|
|
79
|
+
```http://localhost:5000/``` will be the default address.
|
|
80
|
+
Visiting ```http://localhost:5000/hello_world``` will run the ```hello_world``` function in the project.
|
|
81
|
+
|
|
82
|
+
***Run function and print output to shell***
|
|
83
|
+
Output function result to shell. Required arguments include:
|
|
84
|
+
> ```--function <function_name>```: Function name to call
|
|
85
|
+
> ```--shell```: sets shell output to true
|
|
86
|
+
> [Optional] ```--arguments|-x```: Arguments for the function if required. Can be called multiple times for multiple arguments
|
|
87
|
+
|
|
88
|
+
```shell
|
|
89
|
+
cd <project-directory>
|
|
90
|
+
runit --function <hello_world> --shell
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Publishing Project
|
|
94
|
+
Before you can publish any of your projects, you must setup the backend for your runit. You must also be logged in.
|
|
95
|
+
|
|
96
|
+
**Setup Backend Details**
|
|
97
|
+
The backend must be running ***[runit-server](https://github.com/theonlyamos/runit-server)***.
|
|
98
|
+
Run ```runit setup --help``` for help message.
|
|
99
|
+
***Follow the prompts to complete the setup after running the below comman.***
|
|
100
|
+
```shell
|
|
101
|
+
runit setup
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Account Login**
|
|
105
|
+
```shell
|
|
106
|
+
runit login --help
|
|
107
|
+
```
|
|
108
|
+
```shell
|
|
109
|
+
runit login --email <email@example.org> --password <supersecretpass>
|
|
110
|
+
```
|
|
111
|
+
**or**
|
|
112
|
+
***Follow the commands after running below command***
|
|
113
|
+
```shell
|
|
114
|
+
runit login
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Deploy/Publish Project**
|
|
118
|
+
```shell
|
|
119
|
+
cd <project-directory>
|
|
120
|
+
runit publish
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+

|
|
125
|
+
|
|
126
|
+
**Free Software, Hell Yeah!**
|
|
127
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Runit CLI 
|
|
2
|
+
The Runit Command Line Interface (CLI) Tools can be used to test, manage, and deploy your Runit project from the command line.
|
|
3
|
+
- Create new runit project
|
|
4
|
+
- Run a local web server for your runit project
|
|
5
|
+
- publish code and assets to your runit-server domain
|
|
6
|
+
- Interact with data in your runit-server database
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Supported Languages
|
|
10
|
+
  
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
### Python Package
|
|
14
|
+
You can install the Runit CLI using pip (Python package manager). Note that you will need to install [Python](https://python.org).
|
|
15
|
+
To download and install the runit CLI run the following command:
|
|
16
|
+
```shell
|
|
17
|
+
pip install runit
|
|
18
|
+
```
|
|
19
|
+
This will provide you with the globally accessible ```runit``` command.
|
|
20
|
+
|
|
21
|
+
### Install from source
|
|
22
|
+
```shell
|
|
23
|
+
git clone https://github.com/theonlyamos/runit.git
|
|
24
|
+
cd runit
|
|
25
|
+
pip install .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
Run the below command to print out usage message.
|
|
30
|
+
```shell
|
|
31
|
+
runit --help
|
|
32
|
+
```
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
**Create New Project**
|
|
36
|
+
Run the following in the command line to create a new runit project.
|
|
37
|
+
> Supported languages include: [Python](), [Javascript](), [PHP]()
|
|
38
|
+
```shell
|
|
39
|
+
runit new <project-name> --language <langugage>
|
|
40
|
+
```
|
|
41
|
+
Run ```runit new --help``` for all options
|
|
42
|
+
|
|
43
|
+
**Run project locally**
|
|
44
|
+
***Access functions on local server****
|
|
45
|
+
Running the command ```runit``` in a project directory spins up a local webserver which can be used to access the funtions in project.
|
|
46
|
+
```shell
|
|
47
|
+
cd <project-directory>
|
|
48
|
+
runit
|
|
49
|
+
```
|
|
50
|
+
Point your browser to the address provided followed by the function name to access that function.
|
|
51
|
+
```http://localhost:5000/``` will be the default address.
|
|
52
|
+
Visiting ```http://localhost:5000/hello_world``` will run the ```hello_world``` function in the project.
|
|
53
|
+
|
|
54
|
+
***Run function and print output to shell***
|
|
55
|
+
Output function result to shell. Required arguments include:
|
|
56
|
+
> ```--function <function_name>```: Function name to call
|
|
57
|
+
> ```--shell```: sets shell output to true
|
|
58
|
+
> [Optional] ```--arguments|-x```: Arguments for the function if required. Can be called multiple times for multiple arguments
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
cd <project-directory>
|
|
62
|
+
runit --function <hello_world> --shell
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Publishing Project
|
|
66
|
+
Before you can publish any of your projects, you must setup the backend for your runit. You must also be logged in.
|
|
67
|
+
|
|
68
|
+
**Setup Backend Details**
|
|
69
|
+
The backend must be running ***[runit-server](https://github.com/theonlyamos/runit-server)***.
|
|
70
|
+
Run ```runit setup --help``` for help message.
|
|
71
|
+
***Follow the prompts to complete the setup after running the below comman.***
|
|
72
|
+
```shell
|
|
73
|
+
runit setup
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Account Login**
|
|
77
|
+
```shell
|
|
78
|
+
runit login --help
|
|
79
|
+
```
|
|
80
|
+
```shell
|
|
81
|
+
runit login --email <email@example.org> --password <supersecretpass>
|
|
82
|
+
```
|
|
83
|
+
**or**
|
|
84
|
+
***Follow the commands after running below command***
|
|
85
|
+
```shell
|
|
86
|
+
runit login
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Deploy/Publish Project**
|
|
90
|
+
```shell
|
|
91
|
+
cd <project-directory>
|
|
92
|
+
runit publish
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+

|
|
97
|
+
|
|
98
|
+
**Free Software, Hell Yeah!**
|
|
99
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
class Request:
|
|
5
|
+
def __init__(self):
|
|
6
|
+
req = requests.get(os.getenv('RUNIT_SERVERNAME', 'localhost:9000')+'get_app_requests/', headers={'Accept': 'application/json'})
|
|
7
|
+
self.parameters = req.json()
|
|
8
|
+
|
|
9
|
+
def args(self):
|
|
10
|
+
return self.parameters
|
|
11
|
+
|
|
12
|
+
def get(self, name=None):
|
|
13
|
+
if name == None:
|
|
14
|
+
return self.parameters['GET']
|
|
15
|
+
return self.parameters['GET'][name] \
|
|
16
|
+
if name in self.parameters['GET'].keys() \
|
|
17
|
+
else ''
|
|
18
|
+
|
|
19
|
+
def post(self, name=None):
|
|
20
|
+
if name == None:
|
|
21
|
+
return self.parameters['POST']
|
|
22
|
+
return self.parameters['POST'][name] \
|
|
23
|
+
if name in self.parameters['POST'].keys() \
|
|
24
|
+
else ''
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from .constants import TEMPLATES_FOLDER
|
|
2
|
+
from .constants import STARTER_FILES
|
|
3
|
+
from .constants import EXTENSIONS
|
|
4
|
+
from .constants import EXT_TO_LANG
|
|
5
|
+
from .constants import EXT_TO_RUNTIME
|
|
6
|
+
from .constants import NOT_FOUND_FILE
|
|
7
|
+
from .constants import CONFIG_FILE
|
|
8
|
+
from .constants import STARTER_CONFIG_FILE
|
|
9
|
+
from .constants import LANGUAGE_TO_RUNTIME
|
|
10
|
+
from .runit import RunIt
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import shelve
|
|
4
|
+
import getpass
|
|
5
|
+
import argparse
|
|
6
|
+
import logging
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Type, Optional
|
|
9
|
+
from threading import Thread
|
|
10
|
+
|
|
11
|
+
from fastapi import FastAPI, Request
|
|
12
|
+
from fastapi.responses import HTMLResponse
|
|
13
|
+
from dotenv import load_dotenv, set_key, find_dotenv, dotenv_values
|
|
14
|
+
import json
|
|
15
|
+
|
|
16
|
+
from .languages import LanguageParser
|
|
17
|
+
from .modules import Account
|
|
18
|
+
from .runit import RunIt
|
|
19
|
+
from .constants import (
|
|
20
|
+
VERSION, CURRENT_PROJECT, CURRENT_PROJECT_DIR,
|
|
21
|
+
EXT_TO_RUNTIME, LANGUAGE_TO_RUNTIME, RUNIT_HOMEDIR,
|
|
22
|
+
SERVER_HOST, SERVER_PORT, CONFIG_FILE
|
|
23
|
+
)
|
|
24
|
+
from .exceptions import (
|
|
25
|
+
ProjectExistsError,
|
|
26
|
+
ProjectNameNotSpecified
|
|
27
|
+
)
|
|
28
|
+
from .core import WebServer
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
logging.basicConfig(
|
|
32
|
+
format='%(asctime)s - %(levelname)s - [%(filename)s:%(lineno)d] - %(message)s',
|
|
33
|
+
datefmt='%d-%b-%y %H:%M:%S',
|
|
34
|
+
level=logging.DEBUG
|
|
35
|
+
)
|
|
36
|
+
logger = logging.getLogger('runit.log')
|
|
37
|
+
|
|
38
|
+
load_dotenv()
|
|
39
|
+
|
|
40
|
+
def start_webserver(project: RunIt, host: str = SERVER_HOST, port: int = SERVER_PORT):
|
|
41
|
+
web_server = WebServer(project)
|
|
42
|
+
web_server.start(host, port)
|
|
43
|
+
|
|
44
|
+
def create_config(args):
|
|
45
|
+
config = {}
|
|
46
|
+
config['name'] = args.name
|
|
47
|
+
config['language'] = args.language
|
|
48
|
+
config['runtime'] = args.runtime if args.runtime else LANGUAGE_TO_RUNTIME[args.language]
|
|
49
|
+
config['private'] = args.private
|
|
50
|
+
config['author'] = {}
|
|
51
|
+
config['author']['name'] = getpass.getuser()
|
|
52
|
+
config['author']['email'] = "name@example.com"
|
|
53
|
+
|
|
54
|
+
user = Account.user()
|
|
55
|
+
os.chdir(CURRENT_PROJECT_DIR)
|
|
56
|
+
if user is not None:
|
|
57
|
+
config['author']['name'] = user['name']
|
|
58
|
+
config['author']['email'] = user['email']
|
|
59
|
+
|
|
60
|
+
return config
|
|
61
|
+
|
|
62
|
+
def create_project(config):
|
|
63
|
+
return RunIt(**config)
|
|
64
|
+
|
|
65
|
+
def create_new_project(args):
|
|
66
|
+
global CURRENT_PROJECT
|
|
67
|
+
'''
|
|
68
|
+
Method for creating new project or
|
|
69
|
+
function from command line arguments
|
|
70
|
+
|
|
71
|
+
@param args Arguments from argparse
|
|
72
|
+
@return None
|
|
73
|
+
'''
|
|
74
|
+
try:
|
|
75
|
+
if args.name:
|
|
76
|
+
name = RunIt.set_project_name(args.name)
|
|
77
|
+
if RunIt.exists(name):
|
|
78
|
+
raise ProjectExistsError(f'{name} project already exists')
|
|
79
|
+
|
|
80
|
+
config = create_config(args)
|
|
81
|
+
CURRENT_PROJECT = create_project(config)
|
|
82
|
+
logging.info(CURRENT_PROJECT)
|
|
83
|
+
else:
|
|
84
|
+
raise ProjectNameNotSpecified('Project name not specified')
|
|
85
|
+
except Exception as e:
|
|
86
|
+
logger.error(str(e))
|
|
87
|
+
|
|
88
|
+
def run_project(args):
|
|
89
|
+
global CONFIG_FILE
|
|
90
|
+
CONFIG_FILE = args.config
|
|
91
|
+
|
|
92
|
+
RunIt.DOCKER = args.docker
|
|
93
|
+
RunIt.KUBERNETES = args.kubernetes
|
|
94
|
+
|
|
95
|
+
if not CONFIG_FILE and not args.file:
|
|
96
|
+
raise FileNotFoundError
|
|
97
|
+
else:
|
|
98
|
+
if not RunIt.has_config_file() and not args.file:
|
|
99
|
+
raise FileNotFoundError
|
|
100
|
+
elif args.file:
|
|
101
|
+
filename = args.file
|
|
102
|
+
runtime = EXT_TO_RUNTIME[os.path.splitext(filename)[1]]
|
|
103
|
+
LanguageParser.run_file(filename, runtime)
|
|
104
|
+
else:
|
|
105
|
+
project = RunIt(**RunIt.load_config())
|
|
106
|
+
|
|
107
|
+
if args.shell:
|
|
108
|
+
print(project.serve(args.function, args.arguments))
|
|
109
|
+
else:
|
|
110
|
+
start_webserver(project, args.host, args.port)
|
|
111
|
+
|
|
112
|
+
def clone(args):
|
|
113
|
+
CURDIR = os.path.realpath(os.curdir)
|
|
114
|
+
Account.isauthenticated({})
|
|
115
|
+
user = Account.user()
|
|
116
|
+
|
|
117
|
+
project_path = os.path.join(CURDIR, args.project_name)
|
|
118
|
+
if not os.path.exists(project_path):
|
|
119
|
+
os.mkdir(project_path)
|
|
120
|
+
|
|
121
|
+
print(f'[+] Cloning project into {args.project_name}...')
|
|
122
|
+
downloaded_file = Account.clone_project(args.project_name)
|
|
123
|
+
|
|
124
|
+
filepath = os.path.join(project_path, f"{args.project_name}.zip")
|
|
125
|
+
with open(filepath, 'wb') as zip_file:
|
|
126
|
+
zip_file.write(downloaded_file)
|
|
127
|
+
print('[!] Cloning complete')
|
|
128
|
+
RunIt.extract_project(filepath)
|
|
129
|
+
os.chdir(project_path)
|
|
130
|
+
runit = RunIt(**RunIt.load_config())
|
|
131
|
+
print(runit)
|
|
132
|
+
Thread(target=runit.install_dependency_packages, args=()).start()
|
|
133
|
+
|
|
134
|
+
def publish(args):
|
|
135
|
+
global CONFIG_FILE
|
|
136
|
+
CONFIG_FILE = args.config
|
|
137
|
+
|
|
138
|
+
global BASE_HEADERS
|
|
139
|
+
# token = load_token()
|
|
140
|
+
|
|
141
|
+
# headers = {}
|
|
142
|
+
# headers['Authorization'] = f"Bearer {token}"
|
|
143
|
+
|
|
144
|
+
Account.isauthenticated({})
|
|
145
|
+
user = Account.user()
|
|
146
|
+
|
|
147
|
+
os.chdir(CURRENT_PROJECT_DIR)
|
|
148
|
+
|
|
149
|
+
config = RunIt.load_config()
|
|
150
|
+
if not config:
|
|
151
|
+
raise FileNotFoundError
|
|
152
|
+
|
|
153
|
+
project = RunIt(**config)
|
|
154
|
+
if user:
|
|
155
|
+
project.author['name'] = user['name']
|
|
156
|
+
project.author['email'] = user['email']
|
|
157
|
+
|
|
158
|
+
project.update_config()
|
|
159
|
+
print('[-] Preparing project for upload...')
|
|
160
|
+
filename = project.compress()
|
|
161
|
+
print('[#] Project files compressed')
|
|
162
|
+
#print(project.config)
|
|
163
|
+
|
|
164
|
+
print('[-] Uploading file....', end='\r')
|
|
165
|
+
file = open(filename, 'rb')
|
|
166
|
+
files = {'file': file}
|
|
167
|
+
result = Account.publish_project(files, project.config)
|
|
168
|
+
file.close()
|
|
169
|
+
os.chdir(CURRENT_PROJECT_DIR)
|
|
170
|
+
os.unlink(filename)
|
|
171
|
+
|
|
172
|
+
if 'msg' in result.keys():
|
|
173
|
+
print(result['msg'])
|
|
174
|
+
exit(1)
|
|
175
|
+
elif 'message' in result.keys():
|
|
176
|
+
print(result['message'])
|
|
177
|
+
exit(1)
|
|
178
|
+
|
|
179
|
+
print('[#] Files Uploaded!!!')
|
|
180
|
+
if 'project_id' in result.keys():
|
|
181
|
+
project._id = result['project_id']
|
|
182
|
+
project.homepage = result['homepage']
|
|
183
|
+
project.update_config()
|
|
184
|
+
print('[*] Project config updated')
|
|
185
|
+
# if find_dotenv():
|
|
186
|
+
# set_key(find_dotenv(), 'RUNIT_PROJECT_ID', result['project_id'])
|
|
187
|
+
|
|
188
|
+
print('[*] Project published successfully')
|
|
189
|
+
print('[!] Access your functions with the urls below:')
|
|
190
|
+
|
|
191
|
+
for func_url in result['functions']:
|
|
192
|
+
print(f"[-] {func_url}")
|
|
193
|
+
|
|
194
|
+
def setup_runit(args):
|
|
195
|
+
'''
|
|
196
|
+
Setup Runit server side api settings
|
|
197
|
+
|
|
198
|
+
@params args
|
|
199
|
+
@return None
|
|
200
|
+
'''
|
|
201
|
+
try:
|
|
202
|
+
if not find_dotenv():
|
|
203
|
+
env_path = Path(RUNIT_HOMEDIR) / '.env'
|
|
204
|
+
env_path.touch()
|
|
205
|
+
set_key(find_dotenv(), 'RUNIT_API_ENDPOINT', '')
|
|
206
|
+
set_key(find_dotenv(), 'RUNIT_PROJECT_ID', '')
|
|
207
|
+
|
|
208
|
+
settings = dotenv_values(find_dotenv())
|
|
209
|
+
|
|
210
|
+
if args.api:
|
|
211
|
+
settings['RUNIT_API_ENDPOINT'] = args.api
|
|
212
|
+
else:
|
|
213
|
+
for key, value in settings.items():
|
|
214
|
+
new_value = input(f'{key} [{value}]: ').strip()
|
|
215
|
+
if new_value:
|
|
216
|
+
settings[key] = new_value
|
|
217
|
+
else:
|
|
218
|
+
logger.debug(f'{key} cannot be empty')
|
|
219
|
+
logger.info(f'Setting {key} to default [{value}]')
|
|
220
|
+
|
|
221
|
+
for key, value in settings.items():
|
|
222
|
+
set_key(find_dotenv(), key, value)
|
|
223
|
+
except Exception as e:
|
|
224
|
+
logger.error(str(e))
|
|
225
|
+
|
|
226
|
+
def load_token(access_token = None):
|
|
227
|
+
with shelve.open('account') as account:
|
|
228
|
+
if access_token is None and 'access_token' in account.keys():
|
|
229
|
+
return account['access_token']
|
|
230
|
+
if access_token:
|
|
231
|
+
account['access_token'] = access_token
|
|
232
|
+
else:
|
|
233
|
+
account['access_token'] = ''
|
|
234
|
+
return None
|
|
235
|
+
|
|
236
|
+
def is_file(string):
|
|
237
|
+
if (os.path.isfile(os.path.join(os.curdir, string))):
|
|
238
|
+
return open(string, 'rt')
|
|
239
|
+
return False
|
|
240
|
+
|
|
241
|
+
def get_functions(args):
|
|
242
|
+
config = RunIt.load_config()
|
|
243
|
+
if not config:
|
|
244
|
+
raise FileNotFoundError
|
|
245
|
+
|
|
246
|
+
project = RunIt(**config)
|
|
247
|
+
print(project.get_functions())
|
|
248
|
+
|
|
249
|
+
def print_help():
|
|
250
|
+
global parser
|
|
251
|
+
parser.print_help()
|
|
252
|
+
|
|
253
|
+
def get_arguments():
|
|
254
|
+
global parser
|
|
255
|
+
global VERSION
|
|
256
|
+
|
|
257
|
+
subparsers = parser.add_subparsers()
|
|
258
|
+
new_parser = subparsers.add_parser('new', help='Create new project or function')
|
|
259
|
+
new_parser.add_argument("name", type=str, nargs="?",
|
|
260
|
+
help="Name of the new project")
|
|
261
|
+
new_parser.add_argument('-l', '--language', type=str, choices=['multi', 'python', 'php', 'javascript'],
|
|
262
|
+
help="Language of the new project", default="multi")
|
|
263
|
+
new_parser.add_argument('-r','--runtime', type=str,
|
|
264
|
+
help="Runtime of the project language. E.g: python3.11, node, php8")
|
|
265
|
+
new_parser.add_argument('--private', action='store_true',
|
|
266
|
+
help="Make project publicly accessible or not. Default is public.")
|
|
267
|
+
new_parser.set_defaults(func=create_new_project)
|
|
268
|
+
|
|
269
|
+
# run_parser = subparsers.add_parser('run', help='Run current|specified project|function')
|
|
270
|
+
# run_parser.add_argument('function', default='index', type=str, nargs='?', help='Name of function to run')
|
|
271
|
+
# run_parser.add_argument('--file', type=str, nargs='?', help='Name of file to run')
|
|
272
|
+
# run_parser.add_argument('--shell', action='store_true', help='Run function only in shell')
|
|
273
|
+
# run_parser.add_argument('-x', '--arguments', action='append', default=[], help='Comma separated function arguments')
|
|
274
|
+
# run_parser.set_defaults(func=run_project)
|
|
275
|
+
|
|
276
|
+
login_parser = subparsers.add_parser('login', help="User account login")
|
|
277
|
+
login_parser.add_argument('--email', type=str, help="Account email address")
|
|
278
|
+
login_parser.add_argument('--password', type=str, help="Account password")
|
|
279
|
+
login_parser.set_defaults(func=Account.login)
|
|
280
|
+
|
|
281
|
+
register_parser = subparsers.add_parser('register', help="Register new account")
|
|
282
|
+
register_parser.add_argument('--name', type=str, help="Account user's name")
|
|
283
|
+
register_parser.add_argument('--email', type=str, help="Account email address")
|
|
284
|
+
register_parser.add_argument('--password', type=str, help="Account password")
|
|
285
|
+
register_parser.set_defaults(func=Account.register)
|
|
286
|
+
|
|
287
|
+
account_parser = subparsers.add_parser('account', help='Get Current logged in user info')
|
|
288
|
+
account_parser.add_argument('-i', '--info', action='store_true', help="Print out current account info")
|
|
289
|
+
account_parser.set_defaults(func=Account.info)
|
|
290
|
+
|
|
291
|
+
projects_parser = subparsers.add_parser('projects', help='Manage projects')
|
|
292
|
+
projects_parser.add_argument('-l', '--list', action='store_true', help="List account projects")
|
|
293
|
+
projects_parser.add_argument('--id', type=str, help="Project ID")
|
|
294
|
+
projects_parser.set_defaults(func=Account.projects)
|
|
295
|
+
|
|
296
|
+
projects_subparser = projects_parser.add_subparsers()
|
|
297
|
+
|
|
298
|
+
new_project_parser = projects_subparser.add_parser('new', help="Create new Project")
|
|
299
|
+
new_project_parser.add_argument('name', type=str, help="Name of project")
|
|
300
|
+
new_project_parser.set_defaults(func=create_new_project)
|
|
301
|
+
|
|
302
|
+
update_project_parser = projects_subparser.add_parser('update', help="Update Project by Id")
|
|
303
|
+
update_project_parser.add_argument('--id', required=True, help="Id of the project to be updated")
|
|
304
|
+
update_project_parser.add_argument('-d', '--data', required=True, type=str, action='append', help='A dictionary or string. E.g: name="new name" or {"name": "new name"}')
|
|
305
|
+
update_project_parser.set_defaults(func=Account.update_project)
|
|
306
|
+
|
|
307
|
+
delete_project_parser = projects_subparser.add_parser('rm', help="Delete Project")
|
|
308
|
+
delete_project_parser.add_argument('--id', required=True, help="Id of the project to be deleted")
|
|
309
|
+
delete_project_parser.set_defaults(func=Account.delete_project)
|
|
310
|
+
|
|
311
|
+
functions_parser = subparsers.add_parser('functions', help='Manage functions')
|
|
312
|
+
functions_parser.add_argument('-l', '--list', action='store_true', help="List project functions")
|
|
313
|
+
functions_parser.add_argument('--id', type=str, help="Function ID")
|
|
314
|
+
functions_parser.add_argument('-p', '--project', type=str, help="Project ID")
|
|
315
|
+
functions_parser.set_defaults(func=get_functions)
|
|
316
|
+
|
|
317
|
+
setup_parser = subparsers.add_parser('setup', help='Runit server-side configuration')
|
|
318
|
+
setup_parser.add_argument('--api', type=str, help="Runit server-side api endpoint")
|
|
319
|
+
setup_parser.set_defaults(func=setup_runit)
|
|
320
|
+
|
|
321
|
+
publish_parser = subparsers.add_parser('publish', help='Publish current project')
|
|
322
|
+
publish_parser.set_defaults(func=publish)
|
|
323
|
+
|
|
324
|
+
clone_parser = subparsers.add_parser('clone', help='Publish project to current directory')
|
|
325
|
+
clone_parser.add_argument('project_name', type=str, help='Name of project to clone')
|
|
326
|
+
clone_parser.set_defaults(func=clone)
|
|
327
|
+
|
|
328
|
+
parser.add_argument('--docker', action='store_true', help="Run program in docker container")
|
|
329
|
+
parser.add_argument('--kubernetes', action='store_true', help="Run program using kubernetes")
|
|
330
|
+
parser.add_argument('-f', '--function', default='index', type=str, nargs='?', help='Name of function to run')
|
|
331
|
+
parser.add_argument('--file', type=str, nargs='?', help='Name of file to run')
|
|
332
|
+
parser.add_argument('--shell', action='store_true', help='Run function only in shell')
|
|
333
|
+
parser.add_argument('--host', type=str, default='127.0.0.1', help='Host address to run project on')
|
|
334
|
+
parser.add_argument('--port', type=int, default=5000, help='Host port to run project on')
|
|
335
|
+
parser.add_argument('-x', '--arguments', action='append', default=[], help='Comma separated function arguments')
|
|
336
|
+
parser.add_argument('-c','--config', type=is_file, default='runit.json',
|
|
337
|
+
help="Configuration File, defaults to 'runit.json'")
|
|
338
|
+
parser.add_argument('-v','--version', action='version', version=f'%(prog)s {VERSION}')
|
|
339
|
+
parser.set_defaults(func=run_project)
|
|
340
|
+
return parser.parse_args()
|
|
341
|
+
|
|
342
|
+
def main():
|
|
343
|
+
global parser
|
|
344
|
+
try:
|
|
345
|
+
parser = argparse.ArgumentParser(description="A terminal client for runit")
|
|
346
|
+
args = get_arguments()
|
|
347
|
+
args.func(args)
|
|
348
|
+
|
|
349
|
+
except FileNotFoundError:
|
|
350
|
+
print('No runit project or file to run\n')
|
|
351
|
+
parser.print_help()
|
|
352
|
+
sys.exit(1)
|
|
353
|
+
|
|
354
|
+
if __name__ == "__main__":
|
|
355
|
+
main()
|