def do_getcerts(self, inp): '''Get certs''' t = Texttable() for cert in session.query(CERT).all(): t.add_rows([['ID', 'Desc', 'CommonName', 'CA-ID'], str(cert).split(", ")]) print(t.draw())
def _print_cas(self): '''Print existing CAs''' t = Texttable() ca_list = session.query(CA).all() for ca in ca_list: t.add_rows([['ID', 'Desc', 'CommonName'], str(ca).split(", ")]) print(t.draw()) return len(ca_list)
def studiji(): studiji = session.query(Studiji).all() return jsonify([{ "id": studij.id, "naziv": studij.naziv, "godina": studij.godina, "url": studij.url } for studij in studiji])
def _print_certs(self): '''Print existing certs''' t = Texttable() cert_list = session.query(CERT).all() for cert in cert_list: t.add_rows([['ID', 'Desc', 'CommonName', 'CA-ID'], str(cert).split(", ")]) print(t.draw()) return len(cert_list)
def termini(studij_id): termini = session.query(Termin).filter_by(studiji_id=studij_id).all() return jsonify([{ "id": termin.id, "naslov": termin.title, "datum": termin.date, "trajanje": termin.duration, "pocetak": termin.startTime } for termin in termini])
def exists(user: User, post: Post) -> bool: """ Checks whether a post exists for a given user :param user: the user :param post: the post :return: True if the post exists, False if not """ db_post = session.query(DBPost).get( (user.id, post.post_id, post.board_url.short_url)) return db_post is not None
def do_getcertsforca(self, inp): '''Get all certs for an ca''' # Print existing CAs self._print_cas() # Let the user select the CA ca_id = input("Choose an CA by ID: ") # Print all CERTs for CA t = Texttable() for cert in session.query(CERT).filter(CERT.ca_id == ca_id).all(): t.add_rows([['ID', 'Desc', 'CommonName', 'CA-ID'], str(cert).split(", ")]) print(t.draw())
def do_exportca(self, inp): '''Export an key or cert of the ca''' num_cas = self._print_cas() ca_id = self._get_san_input_int("Choose an CA to export: ", num_cas) ca = session.query(CA).filter(CA.id == ca_id).one() # Ask user what to export t = Texttable() t.add_rows([['ID', 'Target'], ['1', 'private key (PEM)'], ['2', 'certificate (CRT)'], ['3', 'public key (PEM)']]) print(t.draw()) what_to_export = self._get_san_input_int("What to export :", 3) val = self._get_cert_info_as_string(ca, what_to_export) self._export_val(val)
def do_importcert(self, inp): '''Import an Cert''' # Get ca_id to export by user and extract from db self._print_cas() ca_id = input("CA to use for signing: ") ca = session.query(CA).filter(CA.id == ca_id).one() # Get the key and cert from file key, cert = self._load_key_and_cert_from_file() # Creat DB-Object and commit desc = input("Please enter an description: ") cert = CERT(desc, cert, key, ca) session.add(cert) session.commit()
def get_favorites(user: User) -> List[PostEntry]: """ Returns all favorites for a user :param user: the user :return: the favorites for the specified user """ posts = session.query(DBPost).filter(DBPost.user_id == user.id).order_by( DBPost.saved_at.asc()) logging.info(f'Fetched favorites, user={user}') return [ PostEntry(URL.find(db_post.url), db_post.post_id, db_post.saved_at) for db_post in posts ]
def do_gencert(self, inp): '''Add an CERT to an CA''' # Print existing CAs self._print_cas() # Get ca_id to export by user ca_id = input("CA to use for signing: ") # Extract from the DB ca = session.query(CA).filter(CA.id == ca_id).one() # Generate CERT, create an DB-Obj and add to session cert, key = gen_cert(ca=ca) desc = input("Please enter an description: ") cert = CERT(desc, cert, key, ca) session.add(cert) session.commit()
def remove_favorite(user: User, post: Post): """ Removes a favorite from a user This will not succeed if the user is not stored in the database Or if the user did not have the favorite :param user: the user :param post: the post :return: True if removing succeeds, False if not """ db_post = session.query(DBPost).get( (user.id, post.post_id, post.board_url.short_url)) session.delete(db_post) session.commit() logging.info( f'Removed favorite, user={user}, post_id={post.post_id}, url={post.board_url}' )
def father(): if request.method == 'POST': data = request.json logging.debug('Received data on /father: {}'.format(data)) father = Father(data['name'], data['last_name']) session.add(father) session.commit() return Response(status=200) else: ret = [] for elem in session.query(Father).all(): tmp = {} tmp['name'] = elem.name tmp['last_name'] = elem.last_name ret.append(tmp) # ret = "{}; {}".format(ret, entry.name) return json.dumps(ret)
def do_exportcert(self, inp): '''Export an key or cert of an client-cert''' num_certs = self._print_certs() cert_id = self._get_san_input_int("Choose an certificate to export: ", num_certs) cert = session.query(CERT).filter(CERT.id == cert_id).one() # Ask user what to export t = Texttable() t.add_rows([ ['ID', 'Target'], ['1', 'private key (PEM)'], ['2', 'certificate (CRT)'], ['3', 'public key (PEM)'], ['4', 'packed and pw-protected (PKCS12)'], ]) print(t.draw()) what_to_export = self._get_san_input_int("What to export :", 4) val = self._get_cert_info_as_string(cert, what_to_export) self._export_val(val)