Exemple #1
0
def init_for_twisted_amp(commands):
    from twisted.protocols import amp
    type_map = {
        'string': amp.String(),
        'unicode': amp.String(
        ),  # originally was amp.Unicode() - but I don't think Unicode is necessary for JSON strings
        'boolean': amp.Boolean(),
        'float': amp.Float(),
        'integer': amp.Integer()
    }

    def convert_args(argdata):
        return [(x[0], type_map[x[1]]) for x in argdata]

    CMD = {}
    for name, data in commands.iteritems():
        CMD[name] = type(
            name, (amp.Command, ), {
                'commandName': name,
                'arguments': convert_args(data['arguments']),
                'response': convert_args(data['response']),
                'errors': convert_args(data.get('errors', ())),
                'requiresAnswer': data.get('requiresAnswer', True)
            })
    return CMD
Exemple #2
0
class Authenticate(amp.Command):
    """Authenticate the remote side.

    The procedure is as follows:

    - When establishing a new connection, the region and the cluster call
      `Authenticate` on each other, passing a random chunk of data in
      `message`. This message must be unique to avoid replay attacks.

    - The remote side adds some salt to the message, and calculates an HMAC
      digest, keyed with the shared secret.

      The salt is intended to prevent replay attacks: it prevents an intruder
      from authenticating itself by calling `Authenticate` on the caller (or
      another endpoint in the same MAAS installation) and sending the same
      message, receiving the digest and passing it back to the caller.

    - The remote side returns this digest and the salt. The caller performs
      the same calculation, and compares the digests.

    - If the digests match, the connection is put into rotation.

    - If the digests do not match, the connection is closed immediately, and
      an error is logged.

    :since: 1.7
    """

    arguments = [(b"message", amp.String())]
    response = [
        (b"digest", amp.String()),
        (b"salt", amp.String()),  # Is 'salt' the right term here?
    ]
    errors = []
Exemple #3
0
class ListRelationsCommand(BaseCommand):
    # comma delimited strings
    arguments = [(
        "client_id",
        amp.String(),
    )]
    response = [("members", amp.String())]
Exemple #4
0
class StartController(amp.Command):
    arguments = [('search_type', amp.String()),
                 ('search_name', amp.String()),
                 ('network', amp.String()),
                 ('cloud_user', amp.String()),
                 ('cloud_pass', amp.String())]
    response = [('started', amp.Boolean())]
Exemple #5
0
class RelationSetCommand(BaseCommand):
    commandName = "relation_set"
    arguments = [(
        "client_id",
        amp.String(),
    ), ("json_blob", amp.String())]
    response = []
Exemple #6
0
class ContinuationCommand(amp.Command):
    arguments = [
        ('continuation', amp.String(optional=True)),
    ]
    response = [
        ('items', amp.ListOf(amp.String())),
        ('continuation', amp.String(optional=True)),
    ]
Exemple #7
0
class SetAutoScheduleModeCommand(amp.Command):
    arguments = [
        ('uid', amp.String()),
        ('autoScheduleMode', amp.String()),
    ]
    response = [
        ('success', amp.Boolean()),
    ]
Exemple #8
0
class ContainsUIDsCommand(amp.Command):
    arguments = [
        ('uid', amp.String()),
        ('testUid', amp.String()),
    ]
    response = [
        ('result', amp.Boolean()),
    ]
Exemple #9
0
class EventFired(amp.Command):
    """ 
    Received by client when an event he has
    registered as a listener to has fired
    """
    arguments = [("event_name", amp.String()),
                 ("data", amp.String())]
    response = []
Exemple #10
0
class ReSyncSession(amp.Command):
    arguments = [('sessId', amp.Integer()), ('ip', amp.String()),
                 ('hostname', amp.String()), ('delim', amp.String()),
                 ('playerId', amp.Integer()),
                 ('time_connected', amp.Integer()),
                 ('last_activity', amp.Float()), ('mxp', amp.Boolean())]
    response = []
    errors = {Exception: 'EXCEPTION'}
Exemple #11
0
class NewSession(amp.Command):
    arguments = [
        ('sessId', amp.Integer()),
        ('ip', amp.String()),
        ('delim', amp.String()),
    ]
    response = []
    errors = {Exception: 'EXCEPTION'}
Exemple #12
0
class RecordWithGUIDCommand(amp.Command):
    arguments = [
        ('guid', amp.String()),
        ('timeoutSeconds', amp.Integer(optional=True)),
    ]
    response = [
        ('fields', amp.String()),
    ]
Exemple #13
0
class WikiAccessForUIDCommand(amp.Command):
    arguments = [
        ('wikiUID', amp.String()),
        ('uid', amp.String()),
    ]
    response = [
        ('access', amp.String()),
    ]
Exemple #14
0
class VerifyPlaintextPasswordCommand(amp.Command):
    arguments = [
        ('uid', amp.String()),
        ('password', amp.String()),
    ]
    response = [
        ('authenticated', amp.Boolean()),
    ]
Exemple #15
0
class ExpandedMemberUIDsCommand(amp.Command):
    arguments = [
        ('uid', amp.String()),
    ]
    response = [
        ('items', amp.ListOf(amp.String())),
        ('continuation', amp.String(optional=True)),
    ]
Exemple #16
0
class SetMembersCommand(amp.Command):
    arguments = [
        ('uid', amp.String()),
        ('memberUIDs', amp.ListOf(amp.String())),
    ]
    response = [
        ('success', amp.Boolean()),
    ]
Exemple #17
0
class RecordWithShortNameCommand(amp.Command):
    arguments = [
        ('recordType', amp.String()),
        ('shortName', amp.String()),
        ('timeoutSeconds', amp.Integer(optional=True)),
    ]
    response = [
        ('fields', amp.String()),
    ]
Exemple #18
0
class MsgServer2Portal(amp.Command):
    """
    Message server -> portal
    """
    key = "MsgServer2Portal"
    arguments = [('hashid', amp.String()), ('data', amp.String()),
                 ('ipart', amp.Integer()), ('nparts', amp.Integer())]
    errors = [(Exception, 'EXCEPTION')]
    response = []
Exemple #19
0
class MsgLauncher2Portal(amp.Command):
    """
    Message Launcher -> Portal

    """
    key = "MsgLauncher2Portal"
    arguments = [('operation', amp.String()), ('arguments', amp.String())]
    errors = {Exception: 'EXCEPTION'}
    response = []
Exemple #20
0
class MsgStatus(amp.Command):
    """
    Check Status between AMP services

    """
    key = "MsgStatus"
    arguments = [('status', amp.String())]
    errors = {Exception: 'EXCEPTION'}
    response = [('status', amp.String())]
Exemple #21
0
class Count(amp.Command):
    arguments = [('n', amp.Integer())]
    response = [('oki', amp.Integer()), ('oks', amp.String()),
                ('oku', amp.Unicode()), ('okb', amp.Boolean()),
                ('okf', amp.Float()), ('okd', amp.Decimal()),
                ('okt', amp.DateTime()), ('okl1', amp.ListOf(amp.Integer())),
                ('okl2', amp.ListOf(amp.ListOf(amp.String()))),
                ('okla',
                 amp.AmpList([('a', amp.Integer()), ('b', amp.Unicode())]))]
Exemple #22
0
class MsgLauncher2Portal(amp.Command):
    """
    Message Launcher -> Portal

    """

    key = "MsgLauncher2Portal"
    arguments = [(b"operation", amp.String()), (b"arguments", amp.String())]
    errors = {Exception: b"EXCEPTION"}
    response = []
Exemple #23
0
class RelationGetCommand(BaseCommand):
    commandName = "relation_get"
    arguments = [(
        "client_id",
        amp.String(),
    ), (
        "unit_name",
        amp.String(),
    ), ("setting_name", amp.String())]
    response = [("data", amp.String())]
Exemple #24
0
class OnlineAccountVerifier_RegisterAddressToBallot(Command):
    arguments = [(b'ballot_id', amp.Integer()),
                 (b'pickled_signed_token', amp.String()),
                 (b'pickled_token', amp.String()),
                 (b'pickled_voter_address', amp.String())]
    response = [(b'ok', amp.Boolean())]
    errors = {
        #TODO add errors
        Exception: b'OnlineAccountVerifier_RegisterAddressToBallot'
    }
Exemple #25
0
class OnlineAccountVerifier_SignBlindToken(Command):
    arguments = [(b'user_id', amp.Integer()), (b'ballot_id', amp.Integer()),
                 (b'blind_token', amp.String())]
    response = [(b'ok', amp.String())]
    errors = {
        psycopg2.IntegrityError: b'IntegrityError',
        psycopg2.ProgrammingError: b'ProgrammingError',
        UserNotRegisterdForBallot: b'NotRegistered',
        Exception: b'OnlineAccountVerifier_SignBlindToken'
    }
Exemple #26
0
class AddClient(amp.Command):
    arguments = [('observer', amp.Boolean())]
    response = [
        ('added', amp.Boolean()),
        ('reason', amp.Unicode()),
        ('ready', amp.Boolean()),
        ('player_count', amp.Integer()),
        ('experiment_pickle', amp.String()),
        ('conditions_pickle', amp.String()),
    ]
Exemple #27
0
class MsgPortal2Server(amp.Command):
    """
    Message portal -> server
    """
    key = "MsgPortal2Server"
    arguments = [('sessid', amp.Integer()), ('ipart', amp.Integer()),
                 ('nparts', amp.Integer()), ('msg', amp.String()),
                 ('data', amp.String())]
    errors = [(Exception, 'EXCEPTION')]
    response = []
Exemple #28
0
class RecordsWithEmailAddressCommand(amp.Command):
    arguments = [
        ('emailAddress', amp.String()),
        ('limitResults', amp.Integer(optional=True)),
        ('timeoutSeconds', amp.Integer(optional=True)),
    ]
    response = [
        ('items', amp.ListOf(amp.String())),
        ('continuation', amp.String(optional=True)),
    ]
Exemple #29
0
class RegisterGame(amp.Command):
    '''
    Registers a game running on the client with the server.
    '''
    arguments = [('game', amp.String()), ('version', amp.String()),
                 ('port', amp.Integer())]
    response = []
    errors = {
        NotAuthenticated: 'NO_AUTH',
        PortUnreachable: 'BAD_PORT',
    }
Exemple #30
0
class RecordsMatchingTokensCommand(amp.Command):
    arguments = [
        ('tokens', amp.ListOf(amp.String())),
        ('context', amp.String(optional=True)),
        ('limitResults', amp.Integer(optional=True)),
        ('timeoutSeconds', amp.Integer(optional=True)),
    ]
    response = [
        ('items', amp.ListOf(amp.String())),
        ('continuation', amp.String(optional=True)),
    ]