Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_json_load(self):
f = open(path.join(self.test_dir, 'sample_psk_file2.txt'), 'w')
config = {'identity': 'hashstring',
'key': 'secretkey'}
data = json.dumps(config, sort_keys=True, indent=4)
f.write(data)
f.close()
json_data = load_json(path.join(self.test_dir,
'sample_psk_file2.txt'))
self.assertEqual(json_data,
{'identity': 'hashstring', 'key': 'secretkey'})
async def run():
# Assign configuration variables.
# The configuration check takes care they are present.
conf = load_json(CONFIG_FILE)
try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
api_factory = APIFactory(host=args.host, psk_id=identity, psk=psk)
except KeyError:
identity = uuid.uuid4().hex
api_factory = APIFactory(host=args.host, psk_id=identity)
try:
psk = await api_factory.generate_psk(args.key)
print('Generated PSK: ', psk)
conf[args.host] = {'identity': identity,
'key': psk}
save_json(CONFIG_FILE, conf)
import argparse
import uuid
if __name__ == '__main__':
CONFIG_FILE = 'tradfri_standalone_psk.conf'
logging.basicConfig(level=logging.DEBUG)
parser = argparse.ArgumentParser()
parser.add_argument('host', metavar='IP', type=str,
help='IP Address of your Tradfri gateway')
parser.add_argument('-K', '--key', dest='key', required=False,
help='Security code found on your Tradfri gateway')
args = parser.parse_args()
if args.host not in load_json(CONFIG_FILE) and args.key is None:
print("Please provide the 'Security Code' on the back of your "
"Tradfri gateway:", end=" ")
key = input().strip()
if len(key) != 16:
raise PytradfriError("'Security Code' has to be exactly" +
"16 characters long.")
else:
args.key = key
conf = load_json(CONFIG_FILE)
try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
api_factory = APIFactory(host=args.host, psk_id=identity, psk=psk)
except KeyError:
async def run(shutdown):
# Assign configuration variables.
# The configuration check takes care they are present.
conf = load_json(CONFIG_FILE)
try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
api_factory = APIFactory(host=args.host, psk_id=identity, psk=psk)
except KeyError:
identity = uuid.uuid4().hex
api_factory = APIFactory(host=args.host, psk_id=identity)
try:
psk = await api_factory.generate_psk(args.key)
print('Generated PSK: ', psk)
conf[args.host] = {'identity': identity,
'key': psk}
save_json(CONFIG_FILE, conf)
async def run():
# Assign configuration variables.
# The configuration check takes care they are present.
conf = load_json(CONFIG_FILE)
try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
api_factory = APIFactory(host=args.host, psk_id=identity, psk=psk)
except KeyError:
identity = uuid.uuid4().hex
api_factory = APIFactory(host=args.host, psk_id=identity)
try:
psk = await api_factory.generate_psk(args.key)
print('Generated PSK: ', psk)
conf[args.host] = {'identity': identity,
'key': psk}
save_json(CONFIG_FILE, conf)
import json
import uuid
import argparse
CONFIG_FILE = 'tradfri_standalone_psk.conf'
parser = argparse.ArgumentParser()
parser.add_argument('host', metavar='IP', type=str,
help='IP Address of your Tradfri gateway')
parser.add_argument('-K', '--key', dest='key', required=False,
help='Security code found on your Tradfri gateway')
args = parser.parse_args()
if args.host not in load_json(CONFIG_FILE) and args.key is None:
print("Please provide the 'Security Code' on the back of your "
"Tradfri gateway:", end=" ")
key = input().strip()
if len(key) != 16:
raise PytradfriError("Invalid 'Security Code' provided.")
else:
args.key = key
conf = load_json(CONFIG_FILE)
try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
api_factory = APIFactory(host=args.host, psk_id=identity, psk=psk)
except KeyError:
async def run():
# Assign configuration variables.
# The configuration check takes care they are present.
conf = load_json(CONFIG_FILE)
try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
api_factory = APIFactory(host=args.host, psk_id=identity, psk=psk)
except KeyError:
identity = uuid.uuid4().hex
api_factory = APIFactory(host=args.host, psk_id=identity)
try:
psk = await api_factory.generate_psk(args.key)
print('Generated PSK: ', psk)
conf[args.host] = {'identity': identity,
'key': psk}
save_json(CONFIG_FILE, conf)
import argparse
logging.basicConfig(level=logging.INFO)
CONFIG_FILE = 'tradfri_standalone_psk.conf'
parser = argparse.ArgumentParser()
parser.add_argument('host', metavar='IP', type=str,
help='IP Address of your Tradfri gateway')
parser.add_argument('-K', '--key', dest='key', required=False,
help='Key found on your Tradfri gateway')
args = parser.parse_args()
if args.host not in load_json(CONFIG_FILE) and args.key is None:
print("Please provide the 'Security Code' on the back of your "
"Tradfri gateway:", end=" ")
key = input().strip()
if len(key) != 16:
raise PytradfriError("Invalid 'Security Code' provided.")
else:
args.key = key
async def run(shutdown):
# Assign configuration variables.
# The configuration check takes care they are present.
conf = load_json(CONFIG_FILE)
try:
identity = conf[args.host].get('identity')
from pytradfri.util import load_json, save_json
import asyncio
import uuid
import argparse
CONFIG_FILE = 'tradfri_standalone_psk.conf'
parser = argparse.ArgumentParser()
parser.add_argument('host', metavar='IP', type=str,
help='IP Address of your Tradfri gateway')
parser.add_argument('-K', '--key', dest='key', required=False,
help='Key found on your Tradfri gateway')
args = parser.parse_args()
if args.host not in load_json(CONFIG_FILE) and args.key is None:
print("Please provide the 'Security Code' on the back of your "
"Tradfri gateway:", end=" ")
key = input().strip()
if len(key) != 16:
raise PytradfriError("Invalid 'Security Code' provided.")
else:
args.key = key
async def run():
# Assign configuration variables.
# The configuration check takes care they are present.
conf = load_json(CONFIG_FILE)
try:
identity = conf[args.host].get('identity')
def run():
# Assign configuration variables.
# The configuration check takes care they are present.
conf = load_json(CONFIG_FILE)
try:
identity = conf[args.host].get('identity')
psk = conf[args.host].get('key')
api_factory = APIFactory(host=args.host, psk_id=identity, psk=psk)
except KeyError:
identity = uuid.uuid4().hex
api_factory = APIFactory(host=args.host, psk_id=identity)
try:
psk = api_factory.generate_psk(args.key)
print('Generated PSK: ', psk)
conf[args.host] = {'identity': identity,
'key': psk}
save_json(CONFIG_FILE, conf)