Spaces:
Sleeping
Sleeping
Moibe commited on
Commit ·
76fd605
1
Parent(s): 56a70c2
Megacambio en paradigma
Browse files- avaimet.py +20 -9
- funciones.py +11 -5
- globales.py +2 -2
- main.py +13 -19
- nycklar/nodes.py +5 -6
avaimet.py
CHANGED
|
@@ -1,48 +1,60 @@
|
|
| 1 |
import os
|
| 2 |
import tools
|
| 3 |
import paramiko
|
| 4 |
-
import compiler
|
| 5 |
import nycklar.nodes as nodes
|
| 6 |
|
| 7 |
#AVAIMET CONTIENE LAS FUNCIONES QUE INTERACTUAN CON EL SERVIDOR REMOTO.
|
| 8 |
|
| 9 |
def conecta():
|
| 10 |
|
|
|
|
| 11 |
#Digital Signature.
|
| 12 |
ssh = paramiko.SSHClient()
|
|
|
|
|
|
|
|
|
|
| 13 |
ssh.load_host_keys("nycklar/itrst")
|
| 14 |
|
|
|
|
|
|
|
| 15 |
#Ahora obtendremos nuestra secret key para poder entrar a ese servidor.
|
| 16 |
project_dir = os.getcwd()
|
|
|
|
|
|
|
| 17 |
key_filename = os.path.join(project_dir, "nycklar", "go")
|
|
|
|
| 18 |
|
| 19 |
ssh.connect(nodes.realm, username=nodes.master, key_filename=key_filename)
|
|
|
|
| 20 |
sftp = ssh.open_sftp()
|
| 21 |
|
| 22 |
return ssh, sftp
|
| 23 |
|
| 24 |
def obtenDireccionArchivo(archivo):
|
| 25 |
-
#Archivo puede ser data.py o
|
| 26 |
|
| 27 |
# Ruta del archivo remoto (también general para todo lo que vive en holocards).
|
| 28 |
-
ruta_remota = nodes.
|
| 29 |
path_archivo = ruta_remota + archivo
|
| 30 |
|
| 31 |
return path_archivo
|
| 32 |
|
| 33 |
|
| 34 |
def obtenContenidoArchivo(sftp, dir_data):
|
| 35 |
-
|
|
|
|
| 36 |
with sftp.open(dir_data, 'rb') as archivo:
|
| 37 |
# Leer el contenido del archivo como bytes
|
|
|
|
| 38 |
contenido = archivo.read()
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
#Decodificar pq viene codificado del server (codificado en bytes) no encriptado.
|
| 43 |
texto = contenido.decode('utf-8')
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
return texto
|
| 48 |
|
|
@@ -55,7 +67,6 @@ def obtenCaja(userfile):
|
|
| 55 |
ruta_remota = nodes.avaimentekijä
|
| 56 |
#avaimentekijä es el repositorio de llaves sulkuusers.
|
| 57 |
|
| 58 |
-
#FUTURE: Separar en dos funciones la que compila y decompila el nombre, y la ue obtiene la caja.
|
| 59 |
caja = ruta_remota + username + ".txt"
|
| 60 |
|
| 61 |
return caja
|
|
|
|
| 1 |
import os
|
| 2 |
import tools
|
| 3 |
import paramiko
|
| 4 |
+
#import compiler
|
| 5 |
import nycklar.nodes as nodes
|
| 6 |
|
| 7 |
#AVAIMET CONTIENE LAS FUNCIONES QUE INTERACTUAN CON EL SERVIDOR REMOTO.
|
| 8 |
|
| 9 |
def conecta():
|
| 10 |
|
| 11 |
+
print("Estoy en aivamet.conecta")
|
| 12 |
#Digital Signature.
|
| 13 |
ssh = paramiko.SSHClient()
|
| 14 |
+
print("El paramiko ssh es:")
|
| 15 |
+
print(ssh)
|
| 16 |
+
|
| 17 |
ssh.load_host_keys("nycklar/itrst")
|
| 18 |
|
| 19 |
+
print("Load host keys loadedas...")
|
| 20 |
+
|
| 21 |
#Ahora obtendremos nuestra secret key para poder entrar a ese servidor.
|
| 22 |
project_dir = os.getcwd()
|
| 23 |
+
|
| 24 |
+
#Ruta de go.
|
| 25 |
key_filename = os.path.join(project_dir, "nycklar", "go")
|
| 26 |
+
|
| 27 |
|
| 28 |
ssh.connect(nodes.realm, username=nodes.master, key_filename=key_filename)
|
| 29 |
+
|
| 30 |
sftp = ssh.open_sftp()
|
| 31 |
|
| 32 |
return ssh, sftp
|
| 33 |
|
| 34 |
def obtenDireccionArchivo(archivo):
|
| 35 |
+
#Archivo puede ser data.py o flagsnovelty.py
|
| 36 |
|
| 37 |
# Ruta del archivo remoto (también general para todo lo que vive en holocards).
|
| 38 |
+
ruta_remota = nodes.users_data
|
| 39 |
path_archivo = ruta_remota + archivo
|
| 40 |
|
| 41 |
return path_archivo
|
| 42 |
|
| 43 |
|
| 44 |
def obtenContenidoArchivo(sftp, dir_data):
|
| 45 |
+
print("Estoy dentro de obtenContenido...")
|
| 46 |
+
|
| 47 |
with sftp.open(dir_data, 'rb') as archivo:
|
| 48 |
# Leer el contenido del archivo como bytes
|
| 49 |
+
print("Pude entrar al archivo...")
|
| 50 |
contenido = archivo.read()
|
| 51 |
+
print("Imprimiendo contenido: ", contenido)
|
| 52 |
+
print("El tipo de contenido obtenido es: ", type(contenido))
|
| 53 |
|
| 54 |
#Decodificar pq viene codificado del server (codificado en bytes) no encriptado.
|
| 55 |
texto = contenido.decode('utf-8')
|
| 56 |
+
print(texto)
|
| 57 |
+
print("El tipo de contenido obtenido es: ", type(texto))
|
| 58 |
|
| 59 |
return texto
|
| 60 |
|
|
|
|
| 67 |
ruta_remota = nodes.avaimentekijä
|
| 68 |
#avaimentekijä es el repositorio de llaves sulkuusers.
|
| 69 |
|
|
|
|
| 70 |
caja = ruta_remota + username + ".txt"
|
| 71 |
|
| 72 |
return caja
|
funciones.py
CHANGED
|
@@ -1,19 +1,25 @@
|
|
| 1 |
import ast
|
|
|
|
| 2 |
import tools
|
| 3 |
import avaimet
|
| 4 |
import globales
|
|
|
|
| 5 |
|
| 6 |
#Aquí van las funciones principales, las que son llamadas directo por la API.
|
| 7 |
#Las que interactuan con el servidor están en el módulo avaimet.
|
| 8 |
#Y las herramientas adicionales están en tools.
|
| 9 |
|
| 10 |
-
def getData():
|
| 11 |
-
#Genera conexión inicial.
|
|
|
|
|
|
|
| 12 |
sshListo, sftpListo = avaimet.conecta()
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#globales.data es el archivo que queremos obtener.
|
| 16 |
-
dir_data = avaimet.obtenDireccionArchivo(globales.data)
|
| 17 |
#Obtiene el json con los datos.
|
| 18 |
data = avaimet.obtenContenidoArchivo(sftpListo, dir_data)
|
| 19 |
#Cierra la conexión.
|
|
|
|
| 1 |
import ast
|
| 2 |
+
import time
|
| 3 |
import tools
|
| 4 |
import avaimet
|
| 5 |
import globales
|
| 6 |
+
import nycklar.nodes as nodes
|
| 7 |
|
| 8 |
#Aquí van las funciones principales, las que son llamadas directo por la API.
|
| 9 |
#Las que interactuan con el servidor están en el módulo avaimet.
|
| 10 |
#Y las herramientas adicionales están en tools.
|
| 11 |
|
| 12 |
+
def getData(aplicacion):
|
| 13 |
+
#Genera conexión inicial.
|
| 14 |
+
print("Estoy en getData...")
|
| 15 |
+
|
| 16 |
sshListo, sftpListo = avaimet.conecta()
|
| 17 |
+
|
| 18 |
+
#dir_data = avaimet.obtenDireccionArchivo() #Comenté éste pq me estaría ahorrando ésta función así:
|
| 19 |
+
dir_data = nodes.users_data + aplicacion + globales.data
|
| 20 |
+
|
| 21 |
+
print("Ésto es dir data...", dir_data)
|
| 22 |
|
|
|
|
|
|
|
| 23 |
#Obtiene el json con los datos.
|
| 24 |
data = avaimet.obtenContenidoArchivo(sftpListo, dir_data)
|
| 25 |
#Cierra la conexión.
|
globales.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
novelty = "novelty.py"
|
| 2 |
-
data = "data.py"
|
|
|
|
| 1 |
+
novelty = "/novelty.py"
|
| 2 |
+
data = "/data.py"
|
main.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
import funciones
|
|
|
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
|
@@ -7,36 +7,31 @@ app = FastAPI()
|
|
| 7 |
def start():
|
| 8 |
return {"Status":"Deployed"}
|
| 9 |
|
| 10 |
-
## GET DATA ##
|
| 11 |
#Vía Path
|
| 12 |
-
@app.get("/getData/")
|
| 13 |
-
def getData():
|
| 14 |
-
|
| 15 |
-
|
| 16 |
return data
|
| 17 |
|
| 18 |
#Vía Query
|
| 19 |
-
#Quizá no es necesaria vía Query porque no pide parámetros.
|
| 20 |
@app.get("/getDataQ/")
|
| 21 |
-
def getData():
|
| 22 |
-
data = funciones.getData()
|
| 23 |
-
print("Tipo de resultado:", type(data))
|
| 24 |
return data
|
| 25 |
|
| 26 |
-
|
| 27 |
## GET TOKENS ##
|
| 28 |
#Vía Path
|
| 29 |
@app.get("/getTokens/{userfile}")
|
| 30 |
def getTokens(userfile: str):
|
| 31 |
tokens = funciones.getTokens(userfile)
|
| 32 |
-
print("Tipo de resultado:", type(tokens))
|
| 33 |
return tokens
|
| 34 |
|
| 35 |
#Vía Query
|
| 36 |
@app.get("/getTokensQ/")
|
| 37 |
def getTokens(userfile: str = "gAAAAABmEZA4SLBC2YczouOrjIEi9WNCNGOIvyUcqBUnzxNsftXTdy54KaX9x8mAjFkABSI6FJrdZDQKk_5lpJOgJoMChxlniw=="):
|
| 38 |
tokens = funciones.getTokens(userfile)
|
| 39 |
-
print("Tipo de resultado:", type(tokens))
|
| 40 |
return tokens
|
| 41 |
|
| 42 |
## AUTHORIZE WORK ##
|
|
@@ -44,14 +39,13 @@ def getTokens(userfile: str = "gAAAAABmEZA4SLBC2YczouOrjIEi9WNCNGOIvyUcqBUnzxNsf
|
|
| 44 |
@app.get("/authorize/{tokens}/{work}")
|
| 45 |
def authorize(tokens: int, work: str):
|
| 46 |
autorizacion = funciones.authorize(tokens, work)
|
| 47 |
-
print("Tipo de resultado:", type(autorizacion))
|
| 48 |
return autorizacion
|
| 49 |
|
| 50 |
#Vía Query
|
| 51 |
@app.get("/authorizeQ/")
|
| 52 |
def authorize(tokens: int, work: str = "picswap"):
|
| 53 |
autorizacion = funciones.authorize(tokens,work)
|
| 54 |
-
print("Tipo de resultado:", type(autorizacion))
|
| 55 |
return autorizacion
|
| 56 |
|
| 57 |
|
|
@@ -60,14 +54,14 @@ def authorize(tokens: int, work: str = "picswap"):
|
|
| 60 |
@app.get("/debitTokens/{userfile}/{work}")
|
| 61 |
def debitTokens(userfile: str, work: str):
|
| 62 |
tokens = funciones.debitTokens(userfile,work)
|
| 63 |
-
print("Tipo de resultado:", type(tokens))
|
| 64 |
return tokens
|
| 65 |
|
| 66 |
#Vía Query
|
| 67 |
@app.get("/debitTokensQ/")
|
| 68 |
def debitTokens(userfile: str, work: str = "picswap"):
|
| 69 |
tokens = funciones.debitTokens(userfile,work)
|
| 70 |
-
print("Tipo de resultado:", type(tokens))
|
| 71 |
return tokens
|
| 72 |
|
| 73 |
## GET USER Novelty ##
|
|
@@ -75,12 +69,12 @@ def debitTokens(userfile: str, work: str = "picswap"):
|
|
| 75 |
@app.get("/getUserNovelty/{userfile}")
|
| 76 |
def getUserNovelty(userfile: str):
|
| 77 |
novelty = funciones.getUserNovelty(userfile)
|
| 78 |
-
print("Tipo de resultado:", type(novelty))
|
| 79 |
return novelty
|
| 80 |
|
| 81 |
#Vía Query
|
| 82 |
@app.get("/getUserNovelty/")
|
| 83 |
def getUserNovelty(userfile: str):
|
| 84 |
novelty = funciones.getUserNovelty(userfile)
|
| 85 |
-
print("Tipo de resultado:", type(novelty))
|
| 86 |
return novelty
|
|
|
|
|
|
|
| 1 |
import funciones
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
|
|
|
| 7 |
def start():
|
| 8 |
return {"Status":"Deployed"}
|
| 9 |
|
| 10 |
+
## GET DATA (USERS) ##
|
| 11 |
#Vía Path
|
| 12 |
+
@app.get("/getData/{aplicacion}")
|
| 13 |
+
def getData(aplicacion: str):
|
| 14 |
+
print("La app que recibí es: ", aplicacion)
|
| 15 |
+
data = funciones.getData(aplicacion)
|
| 16 |
return data
|
| 17 |
|
| 18 |
#Vía Query
|
|
|
|
| 19 |
@app.get("/getDataQ/")
|
| 20 |
+
def getData(aplicacion: str):
|
| 21 |
+
data = funciones.getData(aplicacion)
|
|
|
|
| 22 |
return data
|
| 23 |
|
|
|
|
| 24 |
## GET TOKENS ##
|
| 25 |
#Vía Path
|
| 26 |
@app.get("/getTokens/{userfile}")
|
| 27 |
def getTokens(userfile: str):
|
| 28 |
tokens = funciones.getTokens(userfile)
|
|
|
|
| 29 |
return tokens
|
| 30 |
|
| 31 |
#Vía Query
|
| 32 |
@app.get("/getTokensQ/")
|
| 33 |
def getTokens(userfile: str = "gAAAAABmEZA4SLBC2YczouOrjIEi9WNCNGOIvyUcqBUnzxNsftXTdy54KaX9x8mAjFkABSI6FJrdZDQKk_5lpJOgJoMChxlniw=="):
|
| 34 |
tokens = funciones.getTokens(userfile)
|
|
|
|
| 35 |
return tokens
|
| 36 |
|
| 37 |
## AUTHORIZE WORK ##
|
|
|
|
| 39 |
@app.get("/authorize/{tokens}/{work}")
|
| 40 |
def authorize(tokens: int, work: str):
|
| 41 |
autorizacion = funciones.authorize(tokens, work)
|
|
|
|
| 42 |
return autorizacion
|
| 43 |
|
| 44 |
#Vía Query
|
| 45 |
@app.get("/authorizeQ/")
|
| 46 |
def authorize(tokens: int, work: str = "picswap"):
|
| 47 |
autorizacion = funciones.authorize(tokens,work)
|
| 48 |
+
#print("Tipo de resultado:", type(autorizacion))
|
| 49 |
return autorizacion
|
| 50 |
|
| 51 |
|
|
|
|
| 54 |
@app.get("/debitTokens/{userfile}/{work}")
|
| 55 |
def debitTokens(userfile: str, work: str):
|
| 56 |
tokens = funciones.debitTokens(userfile,work)
|
| 57 |
+
#print("Tipo de resultado:", type(tokens))
|
| 58 |
return tokens
|
| 59 |
|
| 60 |
#Vía Query
|
| 61 |
@app.get("/debitTokensQ/")
|
| 62 |
def debitTokens(userfile: str, work: str = "picswap"):
|
| 63 |
tokens = funciones.debitTokens(userfile,work)
|
| 64 |
+
#print("Tipo de resultado:", type(tokens))
|
| 65 |
return tokens
|
| 66 |
|
| 67 |
## GET USER Novelty ##
|
|
|
|
| 69 |
@app.get("/getUserNovelty/{userfile}")
|
| 70 |
def getUserNovelty(userfile: str):
|
| 71 |
novelty = funciones.getUserNovelty(userfile)
|
| 72 |
+
#print("Tipo de resultado:", type(novelty))
|
| 73 |
return novelty
|
| 74 |
|
| 75 |
#Vía Query
|
| 76 |
@app.get("/getUserNovelty/")
|
| 77 |
def getUserNovelty(userfile: str):
|
| 78 |
novelty = funciones.getUserNovelty(userfile)
|
| 79 |
+
#print("Tipo de resultado:", type(novelty))
|
| 80 |
return novelty
|
nycklar/nodes.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
master = "moibe"
|
| 2 |
realm = "opal2.opalstack.com"
|
| 3 |
-
|
| 4 |
-
avaimentekijä = "/home/moibe/apps/holocards"
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
#user=b'gAAAAABmEZA4SLBC2YczouOrjIEi9WNCNGOIvyUcqBUnzxNsftXTdy54KaX9x8mAjFkABSI6FJrdZDQKk_5lpJOgJoMChxlniw=='
|
|
|
|
| 1 |
master = "moibe"
|
| 2 |
realm = "opal2.opalstack.com"
|
| 3 |
+
key=b'kiSHsm7Y0hbyNdcFIav6OMT39gi29nIzT-rCrr0Tyc8=' #importante conn con server no es decompiler.
|
| 4 |
+
avaimentekijä = "/home/moibe/apps/holocards" #avaimentekijä/keymaker, es el repositorio de llaves de la app q usa Sulku.
|
| 5 |
+
|
| 6 |
+
users_data = "/home/moibe/apps/holocards/sulkusers-data/"
|
| 7 |
+
users_credits = "/home/moibe/apps/holocards/sulku-data/"
|
|
|