コード例 #1
0
    def __init__(self):
        self.lfsbuilder_src_directory = os.path.dirname(
            os.path.realpath(__file__))
        self.temporal_folder = os.path.join(self.lfsbuilder_src_directory,
                                            "tmp")
        self.basic_parser = None
        self.build_parser = None
        self.download_parser = None
        self.xml_parser = None
        self.cli = cli.Cli()
        self.actual_owner_uid = pwd.getpwuid(os.stat(__file__).st_uid).pw_name
        self.actual_owner_gid = grp.getgrgid(os.stat(__file__).st_gid).gr_name

        # Parse sys.args and use dispatcher pattern to
        # invoke method named as command
        self.basic_parser = self.cli.configure_basic_parser()
        self.all_args = self.basic_parser.parse_args()
        self.build_args = None
        self.download_args = None
        self.xml_args = None

        # Set boolean configuration flags
        self.set_config_option(self.all_args)

        if not hasattr(self, self.all_args.command[0]):
            printer.warning(
                "Unknown command '{c}'".format(c=self.all_args.command[0]))
            self.basic_parser.print_help()
            sys.exit(1)

        # .- Create 'tmp' directory
        tools.create_directory(self.temporal_folder)

        # Run command
        getattr(self, self.all_args.command[0])()
コード例 #2
0
def running_device_id(logged_in_single_user):
    authset = crypto.rand_id_data()
    keypair = crypto.get_keypair_rsa()
    dapi = api.DevicesDevauth()
    r = dapi.post_auth_request(authset, keypair[1], keypair[0])
    assert r.status_code == 401

    # Get and accept the device
    token = Path(DEFAULT_TOKEN_PATH).read_text()
    mapi = api.ManagementDevauth(token)
    r = mapi.get_devices()
    assert r.status_code == 200
    devices = r.json()
    device_id = devices[0]["id"]
    authset_id = devices[0]["auth_sets"][0]["id"]
    r = mapi.set_device_auth_status(device_id, authset_id, "accepted")
    assert r.status_code == 204

    # Device should now be listed as accepted
    c = cli.Cli()
    r = c.run("--server", "https://mender-api-gateway", "--skip-verify",
              "devices", "list")
    assert r.returncode == 0, r.stderr
    expect_output(r.stdout, "Status: accepted")

    return device_id
コード例 #3
0
    def test_configuration_parameter_override(self, single_user):
        """test that parameters listed in the configuration file can be overridden on the CLI

        All parameters in the configuration are wrong, and should therefore be
        overridden by the CLI parameters

        """

        conf = """
        {
            "username": "******",
            "password": "******",
            "server": "https://wrong.server.com"
        }
        """

        self._write_mender_cli_conf(conf)

        c = cli.Cli()
        r = c.run(
            "login",
            "--server",
            "https://mender-api-gateway",
            "--skip-verify",
            "--username",
            "*****@*****.**",
            "--password",
            "youcantguess",
        )

        assert r.returncode == 0, r.stderr
コード例 #4
0
ファイル: asb-ng.py プロジェクト: mlk-89/asb-ng
def main():

    mylog = lg.asblog()
    mylog.config('asb-ng.log')

    mycli = cli.Cli()
    mycli.cmdloop()
コード例 #5
0
ファイル: test_artifact.py プロジェクト: siredmar/mender-cli
    def test_ok(self, logged_in_single_user, valid_artifact):
        c = cli.Cli()
        r = c.run('--server', 'https://mender-api-gateway', \
                  '--skip-verify', \
                  'artifacts', 'upload', \
                  '--description', 'foo',
                  valid_artifact)

        assert r.returncode == 0, r.stderr
        expect_output(r.stdout, 'upload successful')

        token = Path(DEFAULT_TOKEN_PATH).read_text()

        dapi = api.Deployments(token)
        r = dapi.get_artifacts()

        assert r.status_code == 200

        artifacts = r.json()
        assert len(artifacts) == 1

        artifact = artifacts[0]

        assert artifact['name'] == 'artifact-foo'
        assert artifact['description'] == 'foo'
        assert artifact['device_types_compatible'] == ['device-foo']
コード例 #6
0
ファイル: test_artifact.py プロジェクト: simbazad/mender-cli
    def test_error_no_server(self, valid_artifact, clean_deployments_db):
        c = cli.Cli()
        r = c.run('--skip-verify', \
                  'artifacts', 'upload', \
                  '--description', 'foo',
                  valid_artifact)

        assert r.returncode!=0
        expect_output(r.stderr, '"server" not set')
コード例 #7
0
ファイル: test_artifact.py プロジェクト: siredmar/mender-cli
    def test_error_no_login(self, valid_artifact):
        c = cli.Cli()
        r = c.run('--server', 'https://mender-api-gateway', \
                  '--skip-verify', \
                  'artifacts', 'upload', \
                  '--description', 'foo',
                  valid_artifact)

        assert r.returncode != 0
        expect_output(r.stderr, 'FAILURE', 'Please Login first')
コード例 #8
0
    def test_error_no_server(self, single_user):
        c = cli.Cli()

        r = c.run('login', \
                  '--skip-verify', \
                  '--username', '*****@*****.**', \
                  '--password', 'youcantguess')

        assert r.returncode != 0

        expect_output(r.stderr, '"server" not set')
コード例 #9
0
ファイル: test_artifact.py プロジェクト: siredmar/mender-cli
def logged_in_single_user(single_user):
    c = cli.Cli()
    r = c.run('login', \
              '--server', 'https://mender-api-gateway', \
              '--skip-verify', \
              '--username', '*****@*****.**', \
              '--password', 'youcantguess')

    assert r.returncode == 0, r.stderr
    yield
    os.remove(DEFAULT_TOKEN_PATH)
コード例 #10
0
    def test_error_wrong_creds(self, single_user):
        c = cli.Cli()

        r = c.run('login', \
                  '--server', 'https://mender-api-gateway', \
                  '--skip-verify', \
                  '--username', '*****@*****.**', \
                  '--password', 'youcantguess')

        assert r.returncode != 0

        expect_output(r.stderr, 'FAILURE: login failed with status 401')
コード例 #11
0
ファイル: docker.py プロジェクト: tranchitella/mender-cli
def exec(service, files, *argv):
    c = cli.Cli('/usr/bin/docker-compose')

    # set by run-test-environment
    args = ['-p', 'acceptance-tests']

    for f in files:
        args += ['-f', f]

    args += ['exec', '-T', service] + list(argv)

    return c.run(*args)
コード例 #12
0
ファイル: client.py プロジェクト: peterbrittain/piconga
    def __init__(self, username, password):
        """Constructor.  Create the three subcomponents."""

        self._cli = cli.Cli()
        self._django_sr = django_sendrcv.DjangoSendRcv(base_url)
        self._tornado_sr = tornado_sendrcv.TornadoSendRcv()

        # Store off the username and password.
        self._username = username
        self._password = password

        return
コード例 #13
0
    def test_login_from_configuration_file(self, single_user):
        """test that the configuration file parameters are respected"""
        # Wrong username and password
        conf = """
        {
            "username": "******",
            "password": "******",
            "server": "https://mender-api-gateway"
        }
        """

        self._write_mender_cli_conf(conf)

        c = cli.Cli()
        r = c.run("login", "--skip-verify")

        assert r.returncode != 0, r.stderr

        expect_output(r.stderr, "FAILURE: login failed with status 401")

        # correct username and password, wrong server
        conf = """
        {
            "username": "******",
            "password": "******",
            "server": "https://wrong.server.com"
        }
        """

        self._write_mender_cli_conf(conf)

        r = c.run("login", "--skip-verify")

        assert r.returncode != 0, r.stderr

        expect_output(r.stderr, "FAILURE:", "request failed")

        # correct username, password and server
        conf = """
        {
            "username": "******",
            "password": "******",
            "server": "https://mender-api-gateway"
        }
        """

        self._write_mender_cli_conf(conf)

        r = c.run("login", "--skip-verify")

        assert r.returncode == 0, r.stderr
コード例 #14
0
    def test_ok(self, single_user, cleanup_token):
        c = cli.Cli()

        r = c.run('login', \
                  '--server', 'https://mender-api-gateway', \
                  '--skip-verify', \
                  '--username', '*****@*****.**', \
                  '--password', 'youcantguess')

        assert r.returncode == 0, r.stderr

        self.__check_token_at(DEFAULT_TOKEN_PATH)
        expect_output(r.stdout, \
                             'login successful')
コード例 #15
0
    def __init__(self, addr, account=None, config="./config/client.conf"):

        logger.info('Starting session: addr %s, config %s', addr, config)

        self.changedir = category.changedir
        self.raddr = addr

        self.account = account
        self.sid = "0"
        self.project = None

        # connection groups
        self.connection_groups = {}
        self.current_group_gid = "0"

        # proxy chains
        self.proxychains = {}

        self.current_category = category.RemoteCategory(0, "dummy category", self)
        self.root_category = None
        self.history = []

        # get config options
        self._readConfig(config)

        # pass the server's cert fingerprint to out socket initialisation
        # function
        window._get_socket.cert_fingerprint = self._cert_fingerprint

        # the dictionary to hold windows as values. accessable via
        # rid as keys. a window's output and input buffers are stored
        # in the connections dict on creation
        self._win_by_wid = {}
        self._win_by_rid = {}
        self._win_used = None

        try:
            self.sock = window._get_socket(self, self.raddr, secure=self._ssl_enabled)
        except Exception as e:
            die('connection to ccd at %s:%d failed' % self.raddr, e=e, code=2)

        # proxy cache
        self.proxies = {}

        # add commandline interface
        self.cli = cli.Cli(self)
        readline.set_completer(self.cli.completer.complete)
        readline.parse_and_bind("tab: complete")
        readline.set_completer_delims(" ")
コード例 #16
0
def logged_in_single_user(single_user):
    c = cli.Cli()
    r = c.run(
        "login",
        "--server",
        "https://mender-api-gateway",
        "--skip-verify",
        "--username",
        "*****@*****.**",
        "--password",
        "youcantguess",
    )

    assert r.returncode == 0, r.stderr
    yield
    os.remove(DEFAULT_TOKEN_PATH)
コード例 #17
0
    def test_error_wrong_creds(self, single_user):
        c = cli.Cli()

        r = c.run(
            "login",
            "--server",
            "https://mender-api-gateway",
            "--skip-verify",
            "--username",
            "*****@*****.**",
            "--password",
            "youcantguess",
        )

        assert r.returncode != 0

        expect_output(r.stderr, "FAILURE: login failed with status 401")
コード例 #18
0
    def test_ok_custom_path(self, single_user, cleanup_token):
        c = cli.Cli()

        custom_path = '/tests/authtoken'

        r = c.run('login', \
                  '--server', 'https://mender-api-gateway', \
                  '--skip-verify', \
                  '--token', '/tests/authtoken', \
                  '--username', '*****@*****.**', \
                  '--password', 'youcantguess')

        assert r.returncode == 0, r.stderr

        self.__check_token_at(custom_path)
        expect_output(r.stdout, \
                             'login successful')
コード例 #19
0
    def test_ok(self, single_user, cleanup_token):
        c = cli.Cli()

        r = c.run(
            "login",
            "--server",
            "https://mender-api-gateway",
            "--skip-verify",
            "--username",
            "*****@*****.**",
            "--password",
            "youcantguess",
        )

        assert r.returncode == 0, r.stderr

        self.__check_token_at(DEFAULT_TOKEN_PATH)
        expect_output(r.stdout, "login successful")
コード例 #20
0
ファイル: __main__.py プロジェクト: pombredanne/dft
def main():
    """
  Main entry point for the script. Create a parser, process the command line,
  and run it
  """

    # Create the Cli object in charge of parsing command line, then select and
    # call the run method
    parser = cli.Cli()

    # If a command has been passed on the cli, then forward it, otherwise use
    # default --help value to ensure to display help
    if len(sys.argv) >= 2:
        parser.parse(sys.argv[1])
    else:
        args = ["__help__", "-h"]
        parser.parse(args)

    # Once parsed call the runner method
    return parser.run()
コード例 #21
0
ファイル: artifact.py プロジェクト: siredmar/mender-cli
def create_artifact_file(outpath):
    with tempfile.NamedTemporaryFile(prefix='menderin') as infile:
        logging.info('writing mender artifact to %s', outpath)

        infile.write(b'bogus test data')
        infile.flush()

        c = cli.Cli(MENDER_ARTIFACT_TOOL)
        r = c.run('write', 'rootfs-image',
                  '--device-type', 'device-foo',\
                  '--file', infile.name, \
                  '--artifact-name', 'artifact-foo',\
                  '--output-path', outpath)

        if r.returncode != 0:
            msg = 'mender-artifact failed with code {}, \nstdout: \n{}stderr: {}\n'.format(
                r.returncode, r.stdout, r.stderr)
            logging.error(msg)
            raise RuntimeError(msg)

        logging.info('mender artifact written to %s', outpath)
コード例 #22
0
    def test_ok_custom_path(self, single_user, cleanup_token):
        c = cli.Cli()

        custom_path = "/tests/authtoken"

        r = c.run(
            "login",
            "--server",
            "https://mender-api-gateway",
            "--skip-verify",
            "--token",
            "/tests/authtoken",
            "--username",
            "*****@*****.**",
            "--password",
            "youcantguess",
        )

        assert r.returncode == 0, r.stderr

        self.__check_token_at(custom_path)
        expect_output(r.stdout, "login successful")
コード例 #23
0
import cli

interface = cli.Cli()
interface.run()
コード例 #24
0
ファイル: __init__.py プロジェクト: jjchromik/intravis
        metavar="BISIMULATION",
        default=0,
        help=
        'use bisimulation. "0": no bisimulation(default), "1": merge all IOAS, "2": merge overlapping IOAs'
    )
    parser.add_argument("-c",
                        dest='colored',
                        action="store_true",
                        default=False,
                        help='colored graph')
    parser.add_argument("-v",
                        dest='testingTrace',
                        default="",
                        metavar="FILE",
                        help='validate this trace against the training trace')

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(0)

    args = parser.parse_args()

    if args.outputpdf == "" and args.outputxml == "":
        parser.print_help()
        exit(1)

    cli = cli.Cli(args)
    exitcode = cli.run()

    exit(exitcode)
コード例 #25
0
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
import sys
import cli

if __name__ == "__main__":
    cli.Cli(sys.argv)
コード例 #26
0
 def start(self):
     cmd = cli.Cli(self)
     thread.start_new_thread(cmd.cmdloop, ())
     self.run()
コード例 #27
0
import cli
import gui
import shared

shared.init()

cliThread = cli.Cli()
cliThread.start()

gui = gui.Gui()
gui.run()

print('Exiting...')
コード例 #28
0
#!/usr/bin/env python3

import threading
import time

import cli as sonm

dwh = sonm.DWH()
cli = sonm.Cli()


def get_orders():
    reply = dwh.get_orders({
        "type":
        2,
        "status":
        2,
        "counterpartyID": ["0x0000000000000000000000000000000000000000"],
    })

    orders = reply.get("orders")
    suppliers = list()
    for order in orders:
        suppliers.append(order.get("order").get("authorID"))

    workers_addrs = list(set(suppliers))
    workers_count = len(workers_addrs)

    print("Total active ASK orders: %d" % len(orders))
    print("Total suppliers: %d" % workers_count)
    return workers_count, workers_addrs