def oisp_activation_code_generator(oisp_url): """Generates Activation Code""" try: client = oisp.Client(oisp_url) client.auth(username, password) accounts = client.get_accounts() index = 0 account = None if len(accounts) > 1: print("Please choose one from below" + " OISP account options") for acc in accounts: print(acc) index = int(input("Enter 0 for first account ID," + " 1 for second Account ID: ")) account = accounts[index] else: account = accounts[index] activation_code = account.get_activation_code() open("./activation-code", "w").write(activation_code) # Authentication Failure except Exception: print("Please generate activation-code again either" + " UserName or Password seems to be incorrect!") # This forces to generate token, in case of failure. if os.path.isfile("activation-code"): os.remove("./activation-code") sys.exit(1)
def get_oisp_user_token(uri, username, password, max_nr_tries=10): for _ in range(max_nr_tries): try: oisp_client = oisp.Client(uri) oisp_client.auth(username, password) return oisp_client.user_token.value except (requests.exceptions.ConnectionError, oisp.client.OICException): print("Can not connect to {}, retrying".format(uri), file=stderr) time.sleep(1) print("Failed to connect to OISP frontend", file=stderr) exit(1)
def test_auth_fail(self): wrong_password = "******" client = oisp.Client(config.api_url, proxies=config.proxies) login_sucessful_with_wrong_password = True try: client.auth(config.username, wrong_password) except oisp.client.OICException as e: self.assertEqual(e.code, oisp.client.OICException.NOT_AUTHORIZED) login_sucessful_with_wrong_password = False self.assertFalse(login_sucessful_with_wrong_password)
def __init__(self): self.__client__ = oisp.Client( api_root="http://cloudfest.streammyiot.com/v1/api") self.__client_username__ = "*****@*****.**" self.__client_password__ = "password" self.auth_client() self.__accounts__ = self.get_accounts() self.__account__ = self.__accounts__[0] self.set_account_to_use(self.__account__) self.__devices__ = self.get_devices() self.file = 'oisp_query_data_{}{}'.format(datetime.datetime.now(), ".npy") self.__minioClient__ = Minio( '212.227.4.254:9000', access_key='AKIAIOSFODNN7EXAMPLE', secret_key='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', secure=False)
def create_test(concurrency=DEFAULT_CONCURRENCY, timeout=DEFAULT_TIMEOUT, filename_suffix=None): if filename_suffix is None: filename_suffix = "" else: filename_suffix = "_" + filename_suffix filename_suffix += "_c{}_t{}".format(concurrency, timeout) client = oisp.Client(DASHBOARD_URL + "/v1/api") client.auth(USERNAME, PASSWORD) account_name = str(uuid.uuid4()) account = client.create_account(account_name) device_id = str(uuid.uuid4()) gateway_id = device_id device = account.create_device(gateway_id, device_id) device.activate() component_name = str(uuid.uuid4()) cid = device.add_component(component_name, "temperature.v1.0")["cid"] device.add_sample(cid, 10) device.submit_data() request = client.response.request script_filename = "runtest{}.sh".format(filename_suffix) payload_filename = "payload{}.json".format(filename_suffix) perc_filename = "perc{}.txt".format(filename_suffix) out_filename = "out{}.txt".format(filename_suffix) with open(payload_filename, "w") as payload_file: payload_file.write(request.body) with open(script_filename, "w") as test_script_file: test_script_file.write( """ab -l -p {} -T application/json -H "Authorization: {}" """ """ -n {} -t {} -e {} -c {} {} > {}""".format( payload_filename, request.headers["Authorization"], DEFAULT_NR_REQUESTS, timeout, perc_filename, concurrency, request.url, out_filename)) return script_filename
import oisp # Make sure to run python setup.py install before you begin # Config is just used for hostname and login data # Feel free to remove this line and replace those # variables in the following code, or fill your # login data in config.py import config # Connect to IoT Analytics host and authenticate print("Connecting to {} ...".format(config.api_url)) # All requests to host are managed by the Client class client = oisp.Client(api_root=config.api_url, proxies=config.proxies) # Authenticate by a username and a password. Currently, you can not create # a user with the Python API, use the dashboard to get started client.auth(config.username, config.password) # IOT Analytics Cloud uses JWT authentication. For most cases, you can rely on # the Python api to manage this, but if you need to, you can get the token # object using the following method. # Currently, tokens expire after one hour. You will need to recall the auth # method upon expiration. An AuthenticationError will be raised if a Token is no # longer valid. token = client.get_user_token() # Account's are organizational units. An account can be managed by multiple # users with different roles, and a user can manage multiple accounts.
assert key not in seen_keys, "Cyclic config" seen_keys.append(key) conf[key] = load_config_from_env(value[2:], seen_keys[:]) except TypeError: #value not indexable = not string or unicode pass return conf if __name__ == "__main__": print >> sys.stderr, "Starting deployment script" conf = load_config_from_env("OISP_RULEENGINE_CONFIG") rule_engine_jar_name = os.environ["RULE_ENGINE_PACKAGE_NAME"] uri = "http://{}/v1/api".format(conf["frontendUri"]) while True: try: oisp_client = oisp.Client(uri) oisp_client.auth(conf["username"], conf["password"]) break except (requests.exceptions.ConnectionError, oisp.client.OICException): print >> sys.stderr, "Can not connect to {}, retrying".format(uri) time.sleep(1) token = oisp_client.user_token.value #pprint.pprint(conf) app_conf = { "application_name": "rule_engine_dashboard", "dashboard_strict_ssl": False, "dashboard_url":
def test_auth_success(self): client = oisp.Client(config.api_url, proxies=config.proxies) client.auth(config.username, config.password)
def test_connection(self): client = oisp.Client(config.api_url, proxies=config.proxies)