Exemple #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
Exemple #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)
Exemple #3
0
            writeTitleFile.close()
    else:
        writeTitleFile = open(fname, "w")
        try:
            encrypted_title = cipher.encryptstr("Question History:\n \n")
        except ionicsdk.exceptions.IonicException as e:
            print("Error encrypting title: {0}".format(e.message))
            sys.exit(-2)
        writeTitleFile.write(encrypted_title)
        writeTitleFile.close()


#main
#Initialize the Ionic Agent (must be done before most Ionic operations).
try:
    agent = ionicsdk.Agent()
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.")
    print(
        "Register (and select an active profile) this device before continuing."
    )
    sys.exit(-1)
Exemple #4
0
# (c) 2018 Ionic Security Inc.
# By using this code, I agree to the Terms & Conditions (https://dev.ionic.com/use.html)
# and the Privacy Policy (https://www.ionic.com/privacy-notice/).

import sys
import ionicsdk

# initialize agent with no persistor
try:
    agent = ionicsdk.Agent(loadprofiles=False)
except ionicsdk.exceptions.IonicException as e:
    print("Error initializing agent: {0}".format(e.message))
    sys.exit(-2)

# display all profiles
profiles = agent.getallprofiles()
print("Initialized agent with {} profiles".format(len(profiles)))