def verify_password(nickname, password): """ Password verification callback. --- securityDefinitions: UserSecurity: type: basic """ if not nickname or not password: return False api = Pepper('http://master:8080') try: auth = api.login(nickname, password, 'pam') except PepperException: return False user = User.query.filter_by(nickname=nickname).first() if not user: user = User.create({'nickname': nickname}) current_app.logger.debug('auth') current_app.logger.debug(auth) user.token = auth['token'] db.session.add(user) db.session.commit() g.current_user = user return True
def _connect(self): api = Pepper(('http://' + self.salt_connection_details.salt_master + ':' + str(self.salt_connection_details.port))) api.login(self.salt_connection_details.username, self.salt_connection_details.password, 'pam') return api
def get_events(): api = Pepper(url, ignore_ssl_errors=True) # TODO: find a way. user = User.objects.first() api.login( str(user.username), user.user_settings.token, os.environ.get("SALT_AUTH", "alcali"), ) response = api.req_stream("/events") return response
def api_connect(): # TODO fix this! user = get_current_user() api = Pepper(url, ignore_ssl_errors=True) login_ret = api.login( str(user.username), user.user_settings.token, os.environ.get("SALT_AUTH", "alcali"), ) user.user_settings.salt_permissions = json.dumps(login_ret["perms"]) user.save() return api
def api_connect(): user = get_current_user() api = Pepper(url, ignore_ssl_errors=True) try: login_ret = api.login( str(user.username), user.user_settings.token, os.environ.get("SALT_AUTH", "alcali"), ) except URLError: raise PepperException("URL Error") user.user_settings.salt_permissions = json.dumps(login_ret["perms"]) user.save() return api
from pepper import Pepper, BIN_SYMBOLS c = Pepper().convert def assert_unchanged(s): if c(s) != s: print "original:" print s print print "new: " print c(s) assert False u = assert_unchanged def test_print(): u("print 1, 2") u("print >> f, 'a'") u("print 'a',") def test_math(): assert c("1 + 3 + 2") == "(1 + 3) + 2" assert c("1 + 3 * 2") == "1 + (3 * 2)" assert c("(1 + 2) * 3") == "(1 + 2) * 3" for op in BIN_SYMBOLS.values(): u("1 {} 2".format(op))
#!/usr/bin/python3 from pepper import Pepper api = Pepper('http://192.168.122.198:8080') # api = Pepper('http://192.168.178.92:8080') # print(api) api.login('test', 'test', 'pam') # run a command on the minion #print(api.low([{'client': 'local','tgt': 'salt-master','fun': 'cmd.run','arg': 'salt state.apply utils test=True'}])) # run connectivy test # print(api.low([{'client': 'local', 'tgt': 'test-minion', 'fun': 'test.ping'}])) # #print(api.low([{'client': 'wheel', 'tgt': '*', 'fun': 'key.list_all'}])) # accept minion # print(api.low([{'client': 'wheel', 'tgt': '*', 'fun': 'key.accept', 'match': 'b9840e25adfd'}])) print( api.low([{ 'client': 'local', 'tgt': 'salt-master', 'fun': 'state.apply', 'arg': ["utils", "test=True"] }]))
def __init__(self): self.api = Pepper(settings.get_variable('NUTS_SALT_REST_API_URL'))
from django.conf import settings from model_manager.api.utils.decorators import timeout from pepper import Pepper @timeout(10) def _login(client): user = getattr(settings, 'SALT_API_USER', 'salt') password = getattr(settings, 'SALT_API_PASSWORD', 'salt') eauth = getattr(settings, 'SALT_API_EAUTH', 'pam') client.login(user, password, eauth) return True url = getattr(settings, 'SALT_API_URL') c = Pepper(url) _login(c)
import logging from datetime import datetime from django.conf import settings from django.core.exceptions import ImproperlyConfigured from model_manager.api.utils.decorators import timeout from pepper import Pepper from time import time LOG = logging.getLogger(__name__) SALT_API_URL = getattr(settings, 'SALT_API_URL', '127.0.0.1') try: SALT_CLIENT = Pepper(SALT_API_URL) except: LOG.error('Could not connect to Salt Master API.') SALT_CLIENT = None class SaltClientExtension(): @timeout(10) def _login(self): client = self.client if client.auth: ts = client.auth.get('expire', str(time())) expires = datetime.fromtimestamp(ts) now = datetime.now() if now > expires: return client username = getattr(settings, 'SALT_API_USER', 'salt') password = getattr(settings, 'SALT_API_PASSWORD', 'salt')
# from communicator import Communicator # from games.game import Game from pepper import Pepper import time p = Pepper() p.say_something() time.sleep(10) print(p.get_raw_audio()) # if __name__ == '__main__': # path = os.getcwd() # communicator = Communicator(path=path) # game = Game(path, p) # game.play() # import os # from flask import Flask # # from communicator import Communicator # from games.game import Game #
def _get_pepper(): """Return a pepper object with auth.""" api = Pepper('http://master:8080', debug_http=True) api.auth = {'token': g.current_user.token, 'user': g.current_user.nickname, 'eauth': 'pam'} return api