예제 #1
0
def get_agent():
    # Load a plaintext Device Profile, or SEP, from disk if on Linux (e.g., no default persistor).
    persistor = None
    if platform.system == 'Linux':
        SEP_FILE_PATH = os.path.expanduser("~/.ionicsecurity/profiles.pt")
        persistor = ionicsdk.DeviceProfilePersistorPlaintextFile(SEP_FILE_PATH)
        print("A plaintext SEP will be loaded from {0}".format(SEP_FILE_PATH))

    # Initialize the Ionic Agent (must be done before most Ionic operations).
    agent = ionicsdk.Agent(None, persistor)

    # Check if there are profiles and that there is one set as active.
    if not agent.hasanyprofiles() or not agent.hasactiveprofile():
        if not agent.hasanyprofiles():
            print("There are no device profiles on this device.")
        if not agent.hasactiveprofile():
            print(
                "There is not an active device profile selected on this device."
            )
        print(
            "Register (and select an active profile) this device before continuing."
        )
        sys.exit(-1)

    return agent
예제 #2
0
import sys
import ionicsdk

persistorPath = '../../sample-data/persistors/sample-persistor.pt'

# initialize agent with plaintext persistor
try:
    persistor = ionicsdk.DeviceProfilePersistorPlaintextFile(persistorPath)
    agent = ionicsdk.Agent(None, persistor)
except ionicsdk.exceptions.IonicException as e:
    print("Error initializing agent: {0}".format(e.message))
    sys.exit(-2)

# display all profiles in persistor
profiles = agent.getallprofiles()
for profile in profiles:
    print("---")
    print("Id       : " + profile.deviceid)
    print("Name     : " + profile.name)
    print("Keyspace : " + profile.keyspace)
    print("ApiUrl   : " + profile.server)
예제 #3
0
# By using this code, I agree to the Terms & Conditions (https://www.ionic.com/terms-of-use/)
# and the Privacy Policy (https://www.ionic.com/privacy-notice/).

import ionicsdk

import sys
import platform
import os.path

INPUT_STRING = "Hello World!"

# Load a plaintext Device Profile, or SEP, from disk if on Linux (e.g., no default persistor).
persistor = None
if platform.system == 'Linux':
  SEP_FILE_PATH = os.path.expanduser("~/.ionicsecurity/profiles.pt")
  persistor = ionicsdk.DeviceProfilePersistorPlaintextFile(SEP_FILE_PATH)
  print("A plaintext SEP will be loaded from {0}".format(SEP_FILE_PATH))

# Initialize the Ionic Agent (must be done before most Ionic operations).
try:
  agent = ionicsdk.Agent(None, persistor)
except ionicsdk.exceptions.IonicException as e:
  print("Error initializing agent: {0}".format(e.message))
  sys.exit(-3)

# Check if there are profiles.
if not agent.hasanyprofiles() or not agent.hasactiveprofile():
  if not agent.hasanyprofiles():
    print("There are no device profiles on this device.")
  if not agent.hasactiveprofile():
    print("There is not an active device profile selected on this device.")