Compare commits
11 Commits
master
...
system/geb
Author | SHA1 | Date | |
---|---|---|---|
2af21fb2a7 | |||
093e6f3bf2 | |||
55c2b2b14d | |||
1a4c24db00 | |||
59ca40d0c1 | |||
3d404e504f | |||
b8e0df9a39 | |||
a69e0fb49b | |||
92306fdb21 | |||
b38f4b7893 | |||
b66e5aa9cc |
28
bruno/GeBox/Instance/Add.bru
Normal file
28
bruno/GeBox/Instance/Add.bru
Normal file
@ -0,0 +1,28 @@
|
||||
meta {
|
||||
name: Add
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/instance/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: add
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"instance":"DAP Personal Website",
|
||||
"domain":"ditaajipratama.net",
|
||||
"product":1,
|
||||
"status":"pending"
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
23
bruno/GeBox/Instance/Detail.bru
Normal file
23
bruno/GeBox/Instance/Detail.bru
Normal file
@ -0,0 +1,23 @@
|
||||
meta {
|
||||
name: Detail
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/instance/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: detail
|
||||
}
|
||||
|
||||
body:json {
|
||||
{"key":1}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
29
bruno/GeBox/Instance/Edit.bru
Normal file
29
bruno/GeBox/Instance/Edit.bru
Normal file
@ -0,0 +1,29 @@
|
||||
meta {
|
||||
name: Edit
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/instance/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: edit
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"key":1,
|
||||
"instance":"DAP Personal Website",
|
||||
"domain":"ditaajipratama.net",
|
||||
"product":1,
|
||||
"status":"pending"
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
23
bruno/GeBox/Instance/List.bru
Normal file
23
bruno/GeBox/Instance/List.bru
Normal file
@ -0,0 +1,23 @@
|
||||
meta {
|
||||
name: List
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/instance/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: list
|
||||
}
|
||||
|
||||
body:json {
|
||||
{}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
25
bruno/GeBox/Instance/Remove.bru
Normal file
25
bruno/GeBox/Instance/Remove.bru
Normal file
@ -0,0 +1,25 @@
|
||||
meta {
|
||||
name: Remove
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/instance/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: remove
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"key":1
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
8
bruno/GeBox/Instance/folder.bru
Normal file
8
bruno/GeBox/Instance/folder.bru
Normal file
@ -0,0 +1,8 @@
|
||||
meta {
|
||||
name: Instance
|
||||
seq: 2
|
||||
}
|
||||
|
||||
auth {
|
||||
mode: inherit
|
||||
}
|
26
bruno/GeBox/Package/Add.bru
Normal file
26
bruno/GeBox/Package/Add.bru
Normal file
@ -0,0 +1,26 @@
|
||||
meta {
|
||||
name: Add
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: add
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"name":"My Package",
|
||||
"desc":null
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
23
bruno/GeBox/Package/Detail.bru
Normal file
23
bruno/GeBox/Package/Detail.bru
Normal file
@ -0,0 +1,23 @@
|
||||
meta {
|
||||
name: Detail
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: detail
|
||||
}
|
||||
|
||||
body:json {
|
||||
{"key":1}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
27
bruno/GeBox/Package/Edit.bru
Normal file
27
bruno/GeBox/Package/Edit.bru
Normal file
@ -0,0 +1,27 @@
|
||||
meta {
|
||||
name: Edit
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: edit
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"key":1,
|
||||
"name":"My Package",
|
||||
"desc":null
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
23
bruno/GeBox/Package/List.bru
Normal file
23
bruno/GeBox/Package/List.bru
Normal file
@ -0,0 +1,23 @@
|
||||
meta {
|
||||
name: List
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: list
|
||||
}
|
||||
|
||||
body:json {
|
||||
{}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
25
bruno/GeBox/Package/Remove.bru
Normal file
25
bruno/GeBox/Package/Remove.bru
Normal file
@ -0,0 +1,25 @@
|
||||
meta {
|
||||
name: Remove
|
||||
type: http
|
||||
seq: 6
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: remove
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"key":1
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
27
bruno/GeBox/Package/Version/Add.bru
Normal file
27
bruno/GeBox/Package/Version/Add.bru
Normal file
@ -0,0 +1,27 @@
|
||||
meta {
|
||||
name: Add
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/version/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: add
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"package":1,
|
||||
"version":"v0.1",
|
||||
"release":"2020-01-01 00:00:00"
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
23
bruno/GeBox/Package/Version/Detail.bru
Normal file
23
bruno/GeBox/Package/Version/Detail.bru
Normal file
@ -0,0 +1,23 @@
|
||||
meta {
|
||||
name: Detail
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/version/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: detail
|
||||
}
|
||||
|
||||
body:json {
|
||||
{"key":1}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
28
bruno/GeBox/Package/Version/Edit.bru
Normal file
28
bruno/GeBox/Package/Version/Edit.bru
Normal file
@ -0,0 +1,28 @@
|
||||
meta {
|
||||
name: Edit
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/version/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: edit
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"key":1,
|
||||
"package":1,
|
||||
"version":"v0.1",
|
||||
"release":"2020-01-01 00:00:00"
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
23
bruno/GeBox/Package/Version/List.bru
Normal file
23
bruno/GeBox/Package/Version/List.bru
Normal file
@ -0,0 +1,23 @@
|
||||
meta {
|
||||
name: List
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/version/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: list
|
||||
}
|
||||
|
||||
body:json {
|
||||
{"package":1}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
25
bruno/GeBox/Package/Version/Remove.bru
Normal file
25
bruno/GeBox/Package/Version/Remove.bru
Normal file
@ -0,0 +1,25 @@
|
||||
meta {
|
||||
name: Remove
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
post {
|
||||
url: http://localhost:11000/api/gebox/package/version/:alder
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
alder: remove
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"key":1
|
||||
}
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
8
bruno/GeBox/Package/Version/folder.bru
Normal file
8
bruno/GeBox/Package/Version/folder.bru
Normal file
@ -0,0 +1,8 @@
|
||||
meta {
|
||||
name: Version
|
||||
seq: 1
|
||||
}
|
||||
|
||||
auth {
|
||||
mode: inherit
|
||||
}
|
8
bruno/GeBox/Package/folder.bru
Normal file
8
bruno/GeBox/Package/folder.bru
Normal file
@ -0,0 +1,8 @@
|
||||
meta {
|
||||
name: Package
|
||||
seq: 1
|
||||
}
|
||||
|
||||
auth {
|
||||
mode: inherit
|
||||
}
|
8
bruno/GeBox/folder.bru
Normal file
8
bruno/GeBox/folder.bru
Normal file
@ -0,0 +1,8 @@
|
||||
meta {
|
||||
name: GeBox
|
||||
seq: 1
|
||||
}
|
||||
|
||||
auth {
|
||||
mode: inherit
|
||||
}
|
5
bruno/bruno.json
Normal file
5
bruno/bruno.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "1",
|
||||
"name": "CostaPy",
|
||||
"type": "collection"
|
||||
}
|
80
handler.py
80
handler.py
@ -5,12 +5,18 @@
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
|
||||
from bottle import Bottle, route
|
||||
from bottle import Bottle, route, request, response
|
||||
from config import directory
|
||||
|
||||
import templates.plain.main as template_public
|
||||
import modules.public.home as public_home
|
||||
|
||||
import modules.api.gebox.package as api_gebox_package
|
||||
import modules.api.gebox.version as api_gebox_version
|
||||
import modules.api.gebox.instance as api_gebox_instance
|
||||
|
||||
import json
|
||||
|
||||
app = Bottle()
|
||||
|
||||
@app.route('/')
|
||||
@ -21,3 +27,75 @@ def index():
|
||||
}
|
||||
}
|
||||
return public_home.main().html(params)
|
||||
|
||||
@app.route('/api/gebox/package/<alder>', method=['OPTIONS', 'POST'])
|
||||
def index(alder):
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
if alder == 'add':
|
||||
return json.dumps(api_gebox_package.package().add(params), indent = 2).encode()
|
||||
elif alder == 'list':
|
||||
return json.dumps(api_gebox_package.package().list(params), indent = 2).encode()
|
||||
elif alder == 'detail':
|
||||
return json.dumps(api_gebox_package.package().detail(params), indent = 2).encode()
|
||||
elif alder == 'edit':
|
||||
return json.dumps(api_gebox_package.package().edit(params), indent = 2).encode()
|
||||
elif alder == 'remove':
|
||||
return json.dumps(api_gebox_package.package().remove(params), indent = 2).encode()
|
||||
else:
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/gebox/package/version/<alder>', method=['OPTIONS', 'POST'])
|
||||
def index(alder):
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
if alder == 'add':
|
||||
return json.dumps(api_gebox_version.version().add(params), indent = 2).encode()
|
||||
elif alder == 'list':
|
||||
return json.dumps(api_gebox_version.version().list(params), indent = 2).encode()
|
||||
elif alder == 'detail':
|
||||
return json.dumps(api_gebox_version.version().detail(params), indent = 2).encode()
|
||||
elif alder == 'edit':
|
||||
return json.dumps(api_gebox_version.version().edit(params), indent = 2).encode()
|
||||
elif alder == 'remove':
|
||||
return json.dumps(api_gebox_version.version().remove(params), indent = 2).encode()
|
||||
else:
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/gebox/instance/<alder>', method=['OPTIONS', 'POST'])
|
||||
def index(alder):
|
||||
try:
|
||||
if request.method == 'OPTIONS':
|
||||
return None
|
||||
else:
|
||||
response.content_type = 'application/json'
|
||||
params = request.json
|
||||
if alder == 'add':
|
||||
return json.dumps(api_gebox_instance.instance().add(params), indent = 2).encode()
|
||||
elif alder == 'list':
|
||||
return json.dumps(api_gebox_instance.instance().list(params), indent = 2).encode()
|
||||
elif alder == 'detail':
|
||||
return json.dumps(api_gebox_instance.instance().detail(params), indent = 2).encode()
|
||||
elif alder == 'edit':
|
||||
return json.dumps(api_gebox_instance.instance().edit(params), indent = 2).encode()
|
||||
elif alder == 'remove':
|
||||
return json.dumps(api_gebox_instance.instance().remove(params), indent = 2).encode()
|
||||
else:
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e),flush=True)
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
143
modules/api/gebox/instance.py
Normal file
143
modules/api/gebox/instance.py
Normal file
@ -0,0 +1,143 @@
|
||||
import mysql.connector as mariadb
|
||||
|
||||
from bottle import request
|
||||
from config import database
|
||||
from scripts import loggorilla
|
||||
|
||||
import datetime
|
||||
|
||||
class instance:
|
||||
|
||||
def __init__(self):
|
||||
self.db_main = mariadb.connect(**database.db_main)
|
||||
self.cursor = self.db_main.cursor(dictionary=True)
|
||||
|
||||
def add(self, params):
|
||||
APIADDR = "/api/gebox/instance/add"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
instance = params["instance" ]
|
||||
domain = params["domain" ]
|
||||
product = params["product" ]
|
||||
status = params["status" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Activity: Insert")
|
||||
self.cursor.execute("INSERT INTO `gebox_instance` VALUES (DEFAULT, %s, %s, %s, %s ) ;", (instance, domain, product, status) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data added"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def list(self, params):
|
||||
APIADDR = "/api/gebox/instance/list"
|
||||
response = {}
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("select * from gebox_instance;")
|
||||
ls = self.cursor.fetchall()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data collected"
|
||||
response["data" ] = ls
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def detail(self, params):
|
||||
APIADDR = "/api/gebox/instance/detail"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("select * from gebox_instance where `id` = %s ;", (key,) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data collected"
|
||||
response["data" ] = row
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def edit(self, params):
|
||||
APIADDR = "/api/gebox/instance/edit"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
instance = params["instance" ]
|
||||
domain = params["domain" ]
|
||||
product = params["product" ]
|
||||
status = params["status" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Update")
|
||||
self.cursor.execute("update gebox_instance set `instance` = %s, `domain` = %s, `product` = %s, `status` = %s where `id` = %s ;", (instance, domain, product, status, key) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data edited"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def remove(self, params):
|
||||
APIADDR = "/api/gebox/instance/remove"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Delete")
|
||||
self.cursor.execute("delete from gebox_instance where `id` = %s ;", (key,) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data removed"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
139
modules/api/gebox/package.py
Normal file
139
modules/api/gebox/package.py
Normal file
@ -0,0 +1,139 @@
|
||||
import mysql.connector as mariadb
|
||||
|
||||
from bottle import request
|
||||
from config import database
|
||||
from scripts import loggorilla
|
||||
|
||||
import datetime
|
||||
|
||||
class package:
|
||||
|
||||
def __init__(self):
|
||||
self.db_main = mariadb.connect(**database.db_main)
|
||||
self.cursor = self.db_main.cursor(dictionary=True)
|
||||
|
||||
def add(self, params):
|
||||
APIADDR = "/api/gebox/package/add"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
name = params["name" ]
|
||||
desc = params["desc" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Activity: Insert")
|
||||
self.cursor.execute("INSERT INTO `gebox_package` VALUES (DEFAULT, %s, %s ) ;", (name, desc) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data added"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def list(self, params):
|
||||
APIADDR = "/api/gebox/package/list"
|
||||
response = {}
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("select * from gebox_package;")
|
||||
ls = self.cursor.fetchall()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data collected"
|
||||
response["data" ] = ls
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def detail(self, params):
|
||||
APIADDR = "/api/gebox/package/detail"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("select * from gebox_package where `id` = %s ;", (key,) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data collected"
|
||||
response["data" ] = row
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def edit(self, params):
|
||||
APIADDR = "/api/gebox/package/edit"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
name = params["name" ]
|
||||
desc = params["desc" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Update")
|
||||
self.cursor.execute("update gebox_package set `name` = %s, `desc` = %s where `id` = %s ;", (name, desc, key) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data edited"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def remove(self, params):
|
||||
APIADDR = "/api/gebox/package/remove"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Delete")
|
||||
self.cursor.execute("delete from gebox_package where `id` = %s ;", (key,) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data removed"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
143
modules/api/gebox/version.py
Normal file
143
modules/api/gebox/version.py
Normal file
@ -0,0 +1,143 @@
|
||||
import mysql.connector as mariadb
|
||||
|
||||
from bottle import request
|
||||
from config import database
|
||||
from scripts import loggorilla
|
||||
|
||||
import datetime
|
||||
|
||||
class version:
|
||||
|
||||
def __init__(self):
|
||||
self.db_main = mariadb.connect(**database.db_main)
|
||||
self.cursor = self.db_main.cursor(dictionary=True)
|
||||
|
||||
def add(self, params):
|
||||
APIADDR = "/api/gebox/package/version/add"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
package = params["package" ]
|
||||
version = params["version" ]
|
||||
release = params["release" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Insert")
|
||||
self.cursor.execute("INSERT INTO `gebox_package_version` VALUES (DEFAULT, %s, %s, %s ) ;", (package, version, release) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data added"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def list(self, params):
|
||||
APIADDR = "/api/gebox/package/version/list"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
package = params["package" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("select `id`, `package`, `version`, DATE_FORMAT(`release`, '%Y-%m-%d %H:%i:%S') AS `release` from gebox_package_version where `package` = %s;", (package,) )
|
||||
ls = self.cursor.fetchall()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data collected"
|
||||
response["data" ] = ls
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def detail(self, params):
|
||||
APIADDR = "/api/gebox/package/version/detail"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("select `id`, `package`, `version`, DATE_FORMAT(`release`, '%Y-%m-%d %H:%i:%S') AS `release` from gebox_package_version where `id` = %s ;", (key,) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data collected"
|
||||
response["data" ] = row
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def edit(self, params):
|
||||
APIADDR = "/api/gebox/package/version/edit"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
package = params["package" ]
|
||||
version = params["version" ]
|
||||
release = params["release" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Update")
|
||||
self.cursor.execute("update gebox_package_version set `package` = %s, `version` = %s, `release` = %s where `id` = %s ;", (package, version, release, key) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data edited"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
||||
def remove(self, params):
|
||||
APIADDR = "/api/gebox/package/version/remove"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define Models")
|
||||
key = params["key" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Delete")
|
||||
self.cursor.execute("delete from gebox_package_version where `id` = %s ;", (key,) )
|
||||
row = self.cursor.fetchone()
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data removed"
|
||||
except Exception as e:
|
||||
self.cursor.execute("ROLLBACK;")
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Set Response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
self.db_main.close()
|
||||
return response
|
||||
|
13
scripts/loggorilla.py
Normal file
13
scripts/loggorilla.py
Normal file
@ -0,0 +1,13 @@
|
||||
import datetime
|
||||
|
||||
def prcss(loc, msg):
|
||||
print(f"[loggorilla][{datetime.datetime.now()}][\033[32mprcss\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
|
||||
|
||||
def accss(loc, msg):
|
||||
print(f"[loggorilla][{datetime.datetime.now()}][\033[36maccss\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
|
||||
|
||||
def fyinf(loc, msg):
|
||||
print(f"[loggorilla][{datetime.datetime.now()}][\033[93mfyinf\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
|
||||
|
||||
def error(loc, msg):
|
||||
print(f"[loggorilla][{datetime.datetime.now()}][\033[31merror\033[39m][\033[95m{loc}\033[39m] {msg}", flush=True)
|
50
sql/gebox.sql
Normal file
50
sql/gebox.sql
Normal file
@ -0,0 +1,50 @@
|
||||
-- README
|
||||
-- Prefix idx_ = index
|
||||
-- Prefix fk_ = foreign
|
||||
-- Create an index for fast lookups
|
||||
-- Defining constraints separately for better readability & maintainability
|
||||
-- Prefix p_ = Procedure
|
||||
-- Prefix i_ = Input(s)
|
||||
-- Prefix v_ = Variable(s)
|
||||
-- Prefix o_ = Output(s)
|
||||
|
||||
-- Main table
|
||||
|
||||
create table if not exists `gebox_package` (
|
||||
`id` int(11) not null auto_increment primary key,
|
||||
`name` varchar(36) not null,
|
||||
`desc` longtext default null
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
create table if not exists `gebox_package_version` (
|
||||
`id` int(11) not null auto_increment primary key,
|
||||
`package` int(11) not null,
|
||||
`version` longtext not null,
|
||||
`release` datetime default null,
|
||||
key `idx_package` (`package`),
|
||||
constraint `gebox_instance_fk_package`
|
||||
foreign key (`package`) references `gebox_package` (`id`)
|
||||
on update cascade
|
||||
on delete cascade
|
||||
) engine=InnoDB default charset=utf8mb4;
|
||||
|
||||
-- Instance table
|
||||
|
||||
create table if not exists `gebox_instance` (
|
||||
`id` int(11) not null auto_increment primary key,
|
||||
--`profile` int(11) not null,
|
||||
`instance` varchar(36) not null,
|
||||
`domain` longtext not null,
|
||||
`product` int(11) not null,
|
||||
`status` text default 'pending',
|
||||
--key `idx_profile` (`profile`),
|
||||
key `idx_product` (`product`),
|
||||
--constraint `gebox_instance_fk_profile`
|
||||
-- foreign key (`profile`) references `auth_profile` (`id`)
|
||||
-- on update cascade
|
||||
-- on delete cascade,
|
||||
constraint `gebox_instance_fk_product`
|
||||
foreign key (`product`) references `gebox_package_version` (`id`)
|
||||
on update restrict
|
||||
on delete restrict
|
||||
) engine=InnoDB default charset=utf8mb4;
|
Loading…
Reference in New Issue
Block a user