# ---------------------------------------------------------------------------------------------------------------- # resources... # APIAuth... api_auth = APIAuth.load(Host) if api_auth is None: print("APIAuth not available.", file=sys.stderr) exit(1) if cmd.verbose: print(api_auth, file=sys.stderr) sys.stderr.flush() # manager... manager = DeviceManager(HTTPClient(), api_auth.api_key) # check for existing registration... device = manager.find(api_auth.org_id, cmd.client_id) if device is None: print("Device not found.", file=sys.stderr) exit(1) # ---------------------------------------------------------------------------------------------------------------- # run... if cmd.set(): # update Device... updated = ProjectSource.update(device, cmd.lat, cmd.lng, cmd.postcode, cmd.description)
# APIAuth... api_auth = APIAuth.load(Host) if api_auth is None: print("osio_client_auth: APIAuth not available.", file=sys.stderr) exit(1) if cmd.verbose: print("osio_client_auth: %s" % api_auth, file=sys.stderr) # User manager... user_manager = UserManager(HTTPClient(), api_auth.api_key) # Device manager... device_manager = DeviceManager(HTTPClient(), api_auth.api_key) # check for existing registration... device = device_manager.find_for_name(api_auth.org_id, Host.name()) # check for existing ClientAuth... client_auth = ClientAuth.load(Host) # ---------------------------------------------------------------------------------------------------------------- # remove non-matching record... if device and client_auth: if device.client_id != client_auth.client_id: ClientAuth.delete(Host) client_auth = None
# ---------------------------------------------------------------------------------------------------------------- # resources... # APIAuth... api_auth = APIAuth.load(Host) if api_auth is None: print("device_topics: APIAuth not available.", file=sys.stderr) exit(1) if cmd.verbose: print("device_topics: %s" % api_auth, file=sys.stderr) sys.stderr.flush() # managers... device_manager = DeviceManager(HTTPClient(), api_auth.api_key) # check for existing registration... device = device_manager.find(api_auth.org_id, cmd.client_id) if device is None: print("device_topics: Device not found.", file=sys.stderr) exit(1) topic_manager = TopicManager(HTTPClient(), api_auth.api_key) # ---------------------------------------------------------------------------------------------------------------- # run... # time... if cmd.use_offset():
if cmd.verbose: print("device_list: %s" % api_auth, file=sys.stderr) # ClientAuth... client_auth = ClientAuth.load(Host) if client_auth is None: print("device_list: ClientAuth not available.", file=sys.stderr) exit(1) if cmd.verbose: print("device_list: %s" % client_auth, file=sys.stderr) sys.stderr.flush() # manager... manager = DeviceManager(api_auth.api_key) # ---------------------------------------------------------------------------------------------------------------- # run... if cmd.org: devices = manager.find_all_for_org(api_auth.org_id) else: devices = manager.find_all_for_user(client_auth.user_id) for device in devices: print(JSONify.dumps(device)) if cmd.verbose: print("device_list: total: %d" % len(devices), file=sys.stderr)
print(api_auth) # ClientAuth... client_auth = ClientAuth.load(Host) if client_auth is None: print("ClientAuth not available.", file=sys.stderr) exit(1) print(client_auth) # manager... http_client = HTTPClient() manager = DeviceManager(http_client, api_auth.api_key) print(manager) print("-") # -------------------------------------------------------------------------------------------------------------------- # run... print("find:") device = manager.find(api_auth.org_id, client_auth.client_id) print(device) print("-")
print("APIAuth not available.", file=sys.stderr) exit(1) print(api_auth) # ClientAuth... client_auth = ClientAuth.load(Host) if client_auth is None: print("ClientAuth not available.", file=sys.stderr) exit(1) print(client_auth) # manager... manager = DeviceManager(api_auth.api_key) print(manager) # -------------------------------------------------------------------------------------------------------------------- # run... device = manager.find(api_auth.org_id, client_auth.client_id) print(device) print("-") try: manager.update(api_auth.org_id, client_auth.client_id, device) except ClientException as exc:
# APIAuth... api_auth = APIAuth.load(Host) if api_auth is None: print("osio_client_auth: APIAuth not available.", file=sys.stderr) exit(1) if cmd.verbose: print("osio_client_auth: %s" % api_auth, file=sys.stderr) # User manager... user_manager = UserManager(api_auth.api_key) # Device manager... device_manager = DeviceManager(api_auth.api_key) # check for existing registration... device = device_manager.find_for_name(api_auth.org_id, system_id.box_label()) # ---------------------------------------------------------------------------------------------------------------- # validate... # TODO: check whether remote device and local client auth match if device is None: if cmd.set() and not cmd.is_complete(): print( "osio_client_auth: No device is registered - you must therefore set a user and location.", file=sys.stderr)