コード例 #1
0
    def install(self):
        self._discovery = self.resolve(discovery)
        self._switchstats = self.resolve(switchstats)

        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/topology
        topologypath = (webservice.WSPathStaticString("topology"), )

        # /ws.v1/topology/links
        linkspath =  topologypath + \
                     ( webservice.WSPathStaticString("links"), )
        reg(self._get_links, "GET", linkspath, """Get list of links.""")

        # /ws.v1/topology/switch/
        switchpath = topologypath + \
                     ( webservice.WSPathStaticString("switch"), )

        # /ws.v1/topology/switch/<switch name>
        switchnamepath = switchpath + \
                        (WSPathExistingSwitchName(self._switchstats) ,)

        # /ws.v1/topology/switch/<switch name>/links
        switchlinkspath =  switchnamepath + \
                     ( webservice.WSPathStaticString("links"), )
        reg(self._get_switch_links, "GET", switchlinkspath,
            """Get list of links.""")
コード例 #2
0
    def install(self):
        dm = self.resolve(directorymanager)
        self.bindings_dir = self.resolve(BindingsDirectory)
        self.pypf = self.resolve(PyPF)
        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        #GET /ws.v1/host/<dir name>/<principal name>/os_fingerprint
        path = ( webservice.WSPathStaticString("host"), ) + \
                         (WSPathExistingDirName(dm, "<dir name>"),) + \
                         (WSPathArbitraryString("<principal name>"),) + \
                         (webservice.WSPathStaticString("os_fingerprint"),)

        reg(
            self._get_fingerprints, "GET", path,
            """Returns all OS fingerprints seen for this active host, grouped by IP address"""
        )

        #GET /ws.v1/debug/os_fingerprint
        path = ( webservice.WSPathStaticString("debug"), ) + \
                         (webservice.WSPathStaticString("os_fingerprint"),)

        reg(self._get_all_fingerprints, "GET", path,
            """Returns all OS fingerprints currently known by the system""")
コード例 #3
0
    def install(self):
        dm = self.resolve(directorymanager)

        self.register_handler(Host_event.static_get_name(), self.host_event)
        self.register_handler(Principal_name_event.static_get_name(),
                              self.principal_name_event)
        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        #GET /ws.v1/host/<dir name>/<principal name>/last_seen
        path = ( webservice.WSPathStaticString("host"), ) + \
                         (WSPathExistingDirName(dm, "<dir name>"),) + \
                         (WSPathArbitraryString("<principal name>"),) + \
                         (webservice.WSPathStaticString("last_seen"),)

        reg(
            self._get_last_seen_str, "GET", path,
            """Get string indicated the last time this host was seen on the network."""
        )

        # we persistently store data in simple_config, so we don't
        # lose all data if nox is restarted
        self.simple_config = self.resolve(simple_config)
        d = self.simple_config.get_config("hosttrackerws")
        d.addCallback(self.load_from_config)  #initial load
        self.post_callback(PERIODIC_SAVE_INTERVAL, self.periodic_save)
コード例 #4
0
    def install(self):

        self.switchstats = self.resolve(switchstats)
        self.cswitchstats = self.resolve(pycswitchstats)
        self.dm = self.resolve(directorymanager)
        self.cpu = self.resolve(cpustats)

        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/nox
        noxpath = (webservice.WSPathStaticString("nox"), )

        # /ws.v1/nox/stat
        noxstatpath = noxpath + \
                        ( webservice.WSPathStaticString("stat"), )
        reg(self._get_nox_stat, "GET", noxstatpath, """Get nox stats""")

        # /ws.v1/nox/version
        noxversionpath = noxpath + \
                        ( webservice.WSPathStaticString("version"), )
        reg(self._get_nox_version, "GET", noxversionpath,
            """Get nox version""")

        # /ws.v1/nox/uptime
        noxuptimepath = noxpath + \
                        ( webservice.WSPathStaticString("uptime"), )
        reg(self._get_nox_uptime, "GET", noxuptimepath, """Get nox uptime""")

        # /ws.v1/nox/cpu/stats
        noxcpupath = noxpath + \
                        ( webservice.WSPathStaticString("cpu"), )
        noxcpupathstats = noxcpupath + \
                        ( webservice.WSPathStaticString("stat"), )
        reg(self._get_nox_cpu_stats, "GET", noxcpupathstats,
            """Get nox cpu stat""")

        # heavy hitters
        noxhitterspath = noxpath + (
            webservice.WSPathStaticString("heavyhitters"), )

        # /ws.v1/nox/heavyhitters/switch_p_s
        noxhitters_switch = noxhitterspath + \
                        ( webservice.WSPathStaticString("switch_p_s"), )
        reg(self._get_nox_hitters_switch_p_s, "GET", noxhitters_switch,
            """Get heavy hitters list for switch flows/s""")

        # /ws.v1/nox/heavyhitters/port_err
        noxhitters_port_err = noxhitterspath + \
                        ( webservice.WSPathStaticString("port_err"), )
        reg(self._get_nox_hitters_port_err, "GET", noxhitters_port_err,
            """Get heavy hitters list for port errors""")

        # /ws.v1/nox/heavyhitters/port_bw
        noxhitters_port_bw = noxhitterspath + \
                        ( webservice.WSPathStaticString("port_bw"), )
        reg(self._get_nox_hitters_port_bw, "GET", noxhitters_port_bw,
            """Get heavy hitters list for port bandwidth""")
コード例 #5
0
def reg_each_principal(reg_fn, handler, type, path_suffix, desc):

    values = ["switch", "location", "host", "user"]
    for v in values:
        if path_suffix:
            path = (webservice.WSPathStaticString(v), ) + path_suffix
        else:
            path = (webservice.WSPathStaticString(v), )

        reg_fn(handler, type, path, desc)
コード例 #6
0
    def install(self):

        self.ffa = self.resolve(flow_fetcher_app)

        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/nox
        noxpath = (webservice.WSPathStaticString("nox"), )

        # /ws.v1/nox/flowfetcher_test
        noxfftpath = noxpath + (
            webservice.WSPathStaticString("flowfetcher_test"), )
        reg(self._test_flow_fetcher, "PUT", noxfftpath,
            """Invoke Python flowfetcher test""")
コード例 #7
0
    def install(self):
        self.prt = self.resolve(pyrestracker)

        ws = self.resolve(str(webservice.webservice))
        print 'WS', ws
        v1 = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/restracker
        rtpath = (webservice.WSPathStaticString("restracker"), )

        # /ws.v1/restracker/host
        rthostpath = rtpath + \
                     ( webservice.WSPathStaticString("host"), )
        reg(
            self._get_rt_host, "GET", rthostpath,
            """Get number of packets per host for the current 10 second slice"""
        )
コード例 #8
0
    def register_web_services(self, web_service, db, dbschema, storage_op_cls):
        self.db = db
        self.dbschema = dbschema
        self.op_cls = storage_op_cls
        v1 = web_service.get_version("1")
        reg = v1.register_request

        basepath = (webservice.WSPathStaticString("storage"),
                    WSPathSchemaDBName(self.dbschema))

        path = basepath + (webservice.WSPathStaticString("schema"), )
        reg(self._get_schema, "GET", path,
            """Get the schema for the given database instance.""")

        basepath += (webservice.WSPathStaticString("table"), )

        path = basepath + (WSPathNonexistentDBTable(self.dbschema), )
        reg(self._add_table, "PUT", path,
            """Create a new table for the given database.""")

        basepath += (WSPathExistingDBTable(self.dbschema), )
        reg(self._modify_table, "PUT", basepath,
            """Modify an existing table in the given database.""")
        reg(self._delete_table, "DELETE", basepath,
            """Delete an existing table in the given database.""")
        reg(self._get_all_table_rows, "GET", basepath,
            """Get all rows of an existing table in the given database.""")
        reg(self._add_table_row, "POST", basepath,
            """Add a new row to the given table and database.""")

        path = basepath + (webservice.WSPathStaticString("search"), )
        reg(
            self._search_table, "GET", path,
            """Search for matching rows of an existing table in the
            given database.""")

        basepath += (WSPathValidDBGUID(), )
        reg(self._get_table_row, "GET", basepath,
            """Get a specific row in the given table and database."""
            "")
        reg(self._update_table_row, "PUT", basepath,
            """Change an existing row in the given table and database.""")
        reg(self._delete_table_row, "DELETE", basepath,
            """Delete an existing row in the given table and database.""")
コード例 #9
0
    def install(self):
        dm = self.resolve(directorymanager)

        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        #PUT /ws.v1/debug/event/auth
        autheventpath    = ( webservice.WSPathStaticString("debug"), ) + \
                          ( webservice.WSPathStaticString("event"), ) +  \
                          ( webservice.WSPathStaticString("auth"), )
        reg(self._do_auth_event, "PUT", autheventpath,
            """Spawn an Auth event.""")

        # code below is for spawning a user-deauth from the UI
        self.bs = self.resolve(pybindings_storage)
        path = ( webservice.WSPathStaticString("user"), ) + \
                         (WSPathExistingDirName(dm, "<dir name>") ,) + \
                         (WSPathArbitraryString("<principal name>"),) + \
                         (webservice.WSPathStaticString("deauth"),)
        desc = "Deauthenticate the named user"
        reg(self._do_user_deauth, "GET", path, desc)
コード例 #10
0
    def install(self):
        self.cfg = self.resolve(local_config)
        self.storage = self.resolve(TransactionalStorage)
        self.register_for_bootstrap_complete(self.changed)
        self.register_handler(interface_change_event.static_get_name(),
                              self.changed)

        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/nox
        noxpath = (webservice.WSPathStaticString("nox"), )

        # /ws.v1/nox/stat
        noxstatpath = noxpath + (webservice.WSPathStaticString("dhcp"), )

        reg(self.get_dhcp_status, "GET", noxstatpath, """Get DHCP status""")

        # Store the defaults to the database, if necessary.
        p = Properties(self.storage, CONFIG_SECTION, DEFAULTS)
        return p.begin().\
            addCallback(lambda ign: p.commit())
コード例 #11
0
ファイル: logws.py プロジェクト: pombreda/snac
    def install(self):
        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/nox
        noxpath = (webservice.WSPathStaticString("nox"), )

        # /ws.v1/nox/dump/status
        noxdumpstatuspath = noxpath + \
            ( webservice.WSPathStaticString("dump"),
              webservice.WSPathStaticString("status") )
        reg(self.get_dump_status, "GET", noxdumpstatuspath,
            """Get current NOX dump status""")
        reg(self.put_dump_status, "PUT", noxdumpstatuspath,
            """Initiate the NOX dump process""")

        # /ws.v1/nox/dump/file
        noxdumpstatuspath = noxpath + \
            ( webservice.WSPathStaticString("dump"),
              webservice.WSPathStaticString("dump.tar.gz") )
        reg(self.get_dump_file, "GET", noxdumpstatuspath,
            """Get NOX dump file""")
コード例 #12
0
    def install(self):
        self.simple_config = self.resolve(simple_config)

        ws  = self.resolve(webservice.webservice)
        v1  = ws.get_version("1")
        reg = v1.register_request

        configpath    = ( webservice.WSPathStaticString("config"), ) + \
                        (webservice.WSPathArbitraryString("<section>"), )
        
        #PUT /ws.v1/config/<section>
        reg(self.put_config_from_request, "PUT", configpath,
            """Write each supplied value to this section's configuration.""")
        
        #GET /ws.v1/config/<section>
        reg(self.get_config_from_request, "GET", configpath,
            """Get all stored values for this section.""")
        
        config64path = ( webservice.WSPathStaticString("config_base64"), ) + \
                        (webservice.WSPathArbitraryString("<section>"), )
        
        # POST /ws.v1/config_base64/<section/ 
        reg(self.post_config_base64, "POST", config64path, 
         """Base 64 encode, then write each value supplied for this section""")
コード例 #13
0
    def install(self):
        
        ws  = self.resolve(str(webservice.webservice))
        v1  = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/nox
        noxpath = ( webservice.WSPathStaticString("nox"), )

        # /ws.v1/nox/components
        noxcomponentspath = noxpath + \
                        ( webservice.WSPathStaticString("components"), )
        reg(self._get_nox_components, "GET", noxcomponentspath,
            """Get list of nox components and their status""")

        # /ws.v1/component/<component name>
        noxcomponentnamepath = noxpath + \
                        ( webservice.WSPathStaticString("component"), 
                        WSPathExistingComponent(self))

        # /ws.v1/component/<component name>/status
        noxcomponentstatus = noxcomponentnamepath + \
                        ( webservice.WSPathStaticString("status"), )
        reg(self._get_nox_component_status, "GET", noxcomponentstatus,
            """Get status for given nox component""")

        # /ws.v1/component/<component name>/version
        # XXX Currently just return nox version 
        noxcomponentversion = noxcomponentnamepath + \
                        ( webservice.WSPathStaticString("version"), )
        reg(self._get_component_version, "GET", noxcomponentversion,
            """Get version for given nox component""")

        # /ws.v1/component/<component name>/uptime
        # XXX Currently just return nox uptime
        noxcomponentuptime = noxcomponentnamepath + \
                        ( webservice.WSPathStaticString("uptime"), )
        reg(self._get_component_uptime, "GET", noxcomponentuptime,
            """Get uptime for given nox component""")
コード例 #14
0
    def __init__(self, dm, bindings_dir, reg):
        self.bindings_dir = bindings_dir
        self.dm = dm

        #HACK: b/c the number of ldap can be huge, we
        # don't query the total number of users each time
        # the webservice is called.  Instead we do it at most every
        # USER_COUNT_INTERVAL_SEC seconds.  As a point of reference,
        # if LDAP is 25K users, my dev machine spikes to 50% CPU usage
        # each time it pulls all names from LDAP
        self.last_total_user_count_search = 0
        self.cached_total_user_count = 0

        entity_count_path = (
            webservice.WSPathStaticString("bindings"),
            webservice.WSPathStaticString("entity_counts"),
        )
        desc = "Get the number of currently active hosts, users, " \
              "locations, and switches"
        reg(self.handle_get_entity_counts, "GET", entity_count_path, desc)

        link_path = (webservice.WSPathStaticString("link"), )
        desc = "See all active network links (uni-directional)"
        reg(self.get_all_links, "GET", link_path, desc)

        principals = ["host", "user", "location"]
        for p1 in principals:
            activepath = ( webservice.WSPathStaticString(p1), ) + \
                           (WSPathExistingDirName(dm, "<dir name>") ,) + \
                           (WSPathArbitraryString("<principal name>"),) + \
                           (webservice.WSPathStaticString("active"),)
            desc = "Determine if %s name is currently active" % (p1)
            fn = (lambda p: lambda x, y: self.handle_is_active(x, y, p))(p1)
            reg(fn, "GET", activepath, desc)
            for p2 in principals:
                if p1 != p2:

                    path = activepath + (webservice.WSPathStaticString(p2), )
                    desc = "Find all %ss associated with the named %s" % (p2,
                                                                          p1)
                    fn = (lambda u,v: \
                      lambda x,y: self.handle_name_for_name(x,y,u,v))(p1,p2)
                    reg(fn, "GET", path, desc)

        path = ( webservice.WSPathStaticString("host"), ) + \
                         (WSPathExistingDirName(dm, "<dir name>") ,) + \
                         (WSPathArbitraryString("<principal name>"),) + \
                         (webservice.WSPathStaticString("active"),) + \
                         (webservice.WSPathStaticString("interface"),)
        desc = "List active network interfaces associated with the named host"
        reg(self.handle_interface_request, "GET", path, desc)

        path = ( webservice.WSPathStaticString("host"), ) + \
                         (WSPathExistingDirName(dm, "<dir name>"),) + \
                         (WSPathArbitraryString("<principal name>"),) + \
                         (webservice.WSPathStaticString("interface"),) + \
                         (WSPathArbitraryString("<interface name>"),)
        desc = "Get information for a named host interface"
        reg(self.handle_interface_request, "GET", path, desc)
コード例 #15
0
    def __init__(self, dm, reg):
        self.dm = dm

        grouptypes = ["host", "user", "location", "switch"]
        addrgrouptypes = ["dladdr", "nwaddr"]
        for gt in grouptypes + addrgrouptypes:
            path = ( webservice.WSPathStaticString("group"), ) + \
                       (WSPathStaticString(gt) ,)
            desc = "List the names of all %s groups" % (gt)
            reg(self.get_all_groups, "GET", path, desc)

        for gt in grouptypes + addrgrouptypes:
            path =         ( webservice.WSPathStaticString("group"), ) + \
                           ( webservice.WSPathStaticString(gt), ) + \
                           (WSPathExistingDirName(dm,"<group dir>") ,) + \
                           (WSPathArbitraryString("<group name>"),)
            desc = "Get all members and subgroups in a %s group" % gt
            reg(lambda x, y: self.group_op_start(x, y, "get"), "GET", path,
                desc)
            desc = "Delete a %s group" % gt
            reg(lambda x, y: self.group_op_start(x, y, "del"), "DELETE", path,
                desc)
            desc = "Add a %s group" % gt
            reg(lambda x, y: self.group_op_start(x, y, "add"), "PUT", path,
                desc)

            parent_path = path + (webservice.WSPathStaticString("parent"), )
            desc = "Get immediate parent groups of a %s group" % gt
            reg(self.get_group_parents, "GET", parent_path, desc)

        for gt in grouptypes:
            classes = ["subgroup", "principal"]
            for c in classes:
                path1 =         ( webservice.WSPathStaticString("group"), ) + \
                             ( webservice.WSPathStaticString(gt), ) + \
                             (WSPathExistingDirName(dm,"<group dir>") ,) + \
                             (WSPathArbitraryString("<group name>"),) + \
                             ( webservice.WSPathStaticString(c), )
                get_desc = "Get a list of all %ss in the named group" % c
                fn = (lambda z: lambda x, y: self.group_op_start(x, y, z))(c)
                reg(fn, "GET", path1, get_desc)

                path2 =   path1 + (WSPathExistingDirName(dm,"<member dir>") ,) + \
                             (WSPathArbitraryString("<member name>"),)
                get_desc = "Test if a %s is in the named group (no recursion)" % c
                reg(lambda x, y: self.member_op_start(x, y, ""), "GET", path2,
                    get_desc)
                put_desc = "Add a %s to the named group" % c
                reg(lambda x, y: self.member_op_start(x, y, "add"), "PUT",
                    path2, put_desc)
                del_desc = "Delete a %s of the named group" % c
                reg(lambda x, y: self.member_op_start(x, y, "del"), "DELETE",
                    path2, del_desc)

        for gt in addrgrouptypes:
            basepath = ( webservice.WSPathStaticString("group"), ) + \
                       ( webservice.WSPathStaticString(gt), ) + \
                       (WSPathExistingDirName(dm,"<group dir>") ,) + \
                       (WSPathArbitraryString("<group name>"),)
            get_desc = "Get a list of all subgroups in the named group"
            fn = (lambda z: lambda x, y: self.group_op_start(x, y, z)
                  )("subgroup")
            reg(fn, "GET",
                basepath + (webservice.WSPathStaticString("subgroup"), ),
                get_desc)
            get_desc = "Get a list of all addresses in the named group"
            fn = (lambda z: lambda x, y: self.group_op_start(x, y, z)
                  )("principal")
            reg(fn, "GET",
                basepath + (webservice.WSPathStaticString("address"), ),
                get_desc)

            sgmpath = basepath + ( webservice.WSPathStaticString("subgroup"), ) +\
                      (WSPathExistingDirName(dm,"<member dir>") ,) +\
                      (WSPathArbitraryString("<member name>"),)
            desc = "Test if a subgroup is in the named group (no recursion)"
            reg(lambda x, y: self.member_op_start(x, y, ""), "GET", sgmpath,
                desc)
            desc = "Add a subgroup to the named group"
            reg(lambda x, y: self.member_op_start(x, y, "add"), "PUT", sgmpath,
                desc)
            desc = "Delete a subgroup of the named group"
            reg(lambda x, y: self.member_op_start(x, y, "del"), "DELETE",
                sgmpath, desc)

            if gt == 'nwaddr':
                member_desc = "an IP address or address block"
            else:
                member_desc = "a MAC address"
            ampath = basepath + ( webservice.WSPathStaticString("address"), ) +\
                     (WSPathArbitraryString("<member name>"),)
            desc = "Test if %s is in the named group (no recursion)" % member_desc
            reg(lambda x, y: self.member_op_start(x, y, ""), "GET", ampath,
                desc)
            desc = "Add %s to the named group" % member_desc
            reg(lambda x, y: self.member_op_start(x, y, "add"), "PUT", ampath,
                desc)
            desc = "Delete %s of the named group" % member_desc
            reg(lambda x, y: self.member_op_start(x, y, "del"), "DELETE",
                ampath, desc)

            addrpath = ( webservice.WSPathStaticString(gt), ) + \
                       (WSPathArbitraryString("<address>"),) + \
                       ( webservice.WSPathStaticString("group"), )
            desc = "Get all groups for %s" % member_desc
            reg(self.get_addr_groups_op, "GET", addrpath, desc)
コード例 #16
0
    def install(self):
        self._dm = self.resolve(directorymanager)

        ws = self.resolve(str(webservice.webservice))
        v1 = ws.get_version("1")
        reg = v1.register_request

        # we handle some bindings storage info in a separate class
        # we also use self.bindings_dir to respond to 'active=true' queries
        self.bindings_dir = self.resolve(BindingsDirectory)
        dm_ws_bindings(self._dm, self.bindings_dir, reg)

        # we handle special switch stats in a separate class
        # spawn one of those right now
        switch_data = self.resolve(switchstats)
        switch_ws = dm_ws_switch(self._dm, self.bindings_dir, switch_data)
        switch_ws.register_webservices(reg)

        # handle special location queries
        location_ws = dm_ws_location(self._dm, self.bindings_dir)
        location_ws.register_webservices(reg)

        # handle special user queries
        dm_ws_user(self._dm, self.bindings_dir, reg)

        # this class handles the /ws.v1/group URLs
        groups = dm_ws_groups(self._dm, reg)

        # /ws.v1/directory/type
        directory_type_path = (
            webservice.WSPathStaticString("directory"),
            webservice.WSPathStaticString("type"),
        )
        reg(self._get_dir_types, "GET", directory_type_path,
            """Get directory component types""")

        # PUT /ws.v1/directory/search_order
        search_order_path = (
            webservice.WSPathStaticString("directory"),
            webservice.WSPathStaticString("search_order"),
        )
        reg(self._change_search_order, "PUT", search_order_path,
            """Modify search order of the directories""")

        # /ws.v1/directory/instance
        directory_inst_path = (
            webservice.WSPathStaticString("directory"),
            webservice.WSPathStaticString("instance"),
        )
        reg(self._get_directories, "GET", directory_inst_path,
            """Get list of directories in search order.""")

        # /ws.v1/directory/instance/<dir name>/
        dirnamepath   = directory_inst_path + \
                        (WSPathArbitraryString("<dir name>") ,)

        # The following webservices all either search or add/modify/delete
        # principals. They can create the following HTTP error codes:
        #
        # 400 - A PUT to modify a principal did not contain any content
        # 404 - The principal does not exist in the specified directory
        # 409 - Attempting to add a principal that already exists.
        # 500 - The server experience an internal error while performing
        #       the requested operation.

        reg(self._get_dir, "GET", dirnamepath,
            """Get directory attributes by name""")
        reg(self._delete_dir, "DELETE", dirnamepath,
            """Delete the named directory""")
        reg(self._modify_dir, "PUT", dirnamepath,
            """Add or Modify the named directory""")

        single_principal_path = \
                      (WSPathExistingDirName(self._dm,"<dir name>") ,) + \
                      (WSPathArbitraryString("<principal name>") ,)

        # PUT /ws.v1/<principal type>/<dir name>/<principal name>
        # ADD URL: add a new principal name to a particular directory
        # MODIFY URL: add a new principal name to a particular directory
        reg_each_principal(reg, self._modify_principal, "PUT",
                           single_principal_path,
                           """Add or modify a principal.""")

        # DELETE /ws.v1/<principal type>/<dir name>/<principal name>
        def do_delete_principal(request, arg):
            return self._do_single_name_op(request, arg, "del_principal")

        reg_each_principal(reg, do_delete_principal, "DELETE",
                           single_principal_path,
                           """Delete an existing principal.""")

        # GET function:  Get directory data associated with a
        # particular name.  Returns JSON-encoding of a HostInfo,
        # SwitchInfo, LocationInfo, or UserInfo object.
        #GET /ws.v1/<principal type>/<dir name>/<principal name>
        def do_get_principal(request, arg):
            return self._do_single_name_op(request, arg, "get_principal")

        reg_each_principal(reg, do_get_principal, "GET", single_principal_path,
                           """Lookup principal data by name.""")

        # GET /ws.v1/<principal type/<dir name>/<principal name>/group
        def do_get_principal_groups(request, arg):
            dirname = arg.get('<dir name>', None)
            instance = self._dm.get_directory_instance(dirname)
            if instance is None:
                return webservice.notFound(
                    request, "Directory '%s' does not exist." % dirname)
            type_str = get_principal_type_from_args(arg)
            ptype = name_to_type_map.get(type_str)
            if ptype is None:
                return webservice.notFound(
                    request, "Invalid principal type %s" % type_str)
            if instance._instance.group_enabled(ptype) == Directory.NO_SUPPORT:
                return simplejson.dumps(())
            return self._do_single_name_op(request, arg,
                                           "get_group_membership")
        group_path = single_principal_path + \
                          (webservice.WSPathStaticString("group"),)
        reg_each_principal(reg, do_get_principal_groups, "GET", group_path,
                           """Get all groups that contain this principal.""")

        # SEARCH functions.  Search principals in all directories
        # in in a specific directory.  Returns a list of principal names.
        # GET /ws.v1/<principal type>
        # GET /ws.v1/<principal type>/<dir name>
        #
        # Query Params:
        # * supports standard 'start' 'count' for pagination
        # * supports 'sort_descending'
        # * if 'list' param is true, returns tuple of { 'name',
        #   'directory', and 'active' }, in which case it also
        # supports the 'sort_attribute' param.
        # * 'active': optional boolean param to filter results based
        # on whether the principal is currently active on the network.
        # * Also supports a wide number of other params to filter records
        # based on the contents of bindings storage and directories.
        # See the *Query objects in nox/lib/directory.py for details.
        reg_each_principal(reg, self._search_principals, "GET", None,
                           """Search principal data in all directories""")

        reg_each_principal(reg, self._search_principals, "GET",
                           (WSPathExistingDirName(self._dm, "<dir name>"), ),
                           """Search principal data in named directory""")

        # Requests deauthenticaiton of all bindings of host and user principals
        # DELETE /ws.v1/user/<dir name>/<principal name>/binding
        dirname = WSPathExistingDirName(self._dm, "<dir name>")
        principalname = WSPathArbitraryString("<principal name>")
        userpath = (webservice.WSPathStaticString("user"), dirname,
                    principalname)
        reg(self._do_delete_bindings, "DELETE",
            userpath + (webservice.WSPathStaticString("binding"), ),
            "Deauthenticate user from all active bindings.")
        # DELETE /ws.v1/host/<dir name>/<principal name>/binding
        hostpath = (webservice.WSPathStaticString("host"), dirname,
                    principalname)
        reg(self._do_delete_bindings, "DELETE",
            hostpath + (webservice.WSPathStaticString("binding"), ),
            "Deauthenticate user from all active bindings.")
コード例 #17
0
    def install(self):
        self.policy = self.resolve(str(sepl.policy.PyPolicyComponent))
        self.v1 = self.resolve(str(webservice.webservice)).get_version("1")

        self.v1.register_request(
            protocolsws.get_protocols, "GET",
            (webservice.WSPathStaticString('protocols'), ),
            "Get the set of currently defined protocol.")

        self.v1.register_request(protocolsws.get_protocol, "GET",
                                 (webservice.WSPathStaticString('protocols'),
                                  protocolsws.WSPathExistProtocolIdent()),
                                 "Get a protocol's definition.")

        self.v1.register_request(protocolsws.modify_protocol, "PUT",
                                 (webservice.WSPathStaticString('protocols'),
                                  protocolsws.WSPathProtocolIdent()),
                                 "Modify/create a protocol's definition.")

        self.v1.register_request(protocolsws.delete_protocol, "DELETE",
                                 (webservice.WSPathStaticString('protocols'),
                                  protocolsws.WSPathExistProtocolIdent()),
                                 "Delete a protocol's definition.")

        self.v1.register_request(self.get_policy_names, "GET",
                                 (webservice.WSPathStaticString('policy'),
                                  webservice.WSPathStaticString('names')),
                                 "Get name mappings.")

        self.v1.register_request(self.get_policy, "GET",
                                 (webservice.WSPathStaticString('policy'), ),
                                 "Get installed policy id.")

        self.v1.register_request(self.get_stats, "GET", (
            webservice.WSPathStaticString('policy'),
            webservice.WSPathStaticString('stats'),
        ), "Get basic policy stats.")

        self.v1.register_request(
            self.reset_stats, "DELETE", (
                webservice.WSPathStaticString('policy'),
                webservice.WSPathStaticString('stats'),
            ), "Reset all policy stats; returns stats "
            "prior to delete")

        self.v1.register_request(self.get_rule, "GET",
                                 (webservice.WSPathStaticString('policy'),
                                  WSPathExistingPolicyId(self.policy),
                                  webservice.WSPathStaticString('rule'),
                                  WSPathExistingRuleId(self.policy)),
                                 "Get rule id's defintion.")
        # disabled since we need .../rule/<rule id>/<other_stuff>
        # we may want to move this under ../<rule id>/attribute/...
        #self.v1.register_request(self.get_rule_param, "GET",
        #                         (webservice.WSPathStaticString('policy'),
        #                          WSPathExistingPolicyId(self.policy),
        #                          webservice.WSPathStaticString('rule'),
        #                          WSPathExistingRuleId(self.policy),
        #                          WSPathRuleParam()),
        #                         "Get rule id's parameter value.")
        self.v1.register_request(self.get_rules, "GET",
                                 (webservice.WSPathStaticString('policy'),
                                  WSPathExistingPolicyId(self.policy),
                                  webservice.WSPathStaticString('rules')),
                                 "Get policy id's rules.")
        self.v1.register_request(self.get_rule_stats, "GET",
                                 (webservice.WSPathStaticString('policy'),
                                  WSPathExistingPolicyId(self.policy),
                                  webservice.WSPathStaticString('rule'),
                                  WSPathExistingRuleId(self.policy),
                                  webservice.WSPathStaticString('stats')),
                                 "Get rule id's enforcement stats.")
        self.v1.register_request(self.put_rule, "PUT",
                                 (webservice.WSPathStaticString('policy'),
                                  WSPathExistingPolicyId(self.policy),
                                  webservice.WSPathStaticString('rule'),
                                  WSPathExistingRuleId(self.policy)),
                                 "Modify a rule's attributes or definition.")
        self.v1.register_request(self.put_record_rule_senders, "PUT",
                                 (webservice.WSPathStaticString('policy'),
                                  WSPathExistingPolicyId(self.policy),
                                  webservice.WSPathStaticString('rule'),
                                  WSPathExistingRuleId(self.policy),
                                  webservice.WSPathStaticString('stats')),
                                 "Configure stats collection for a rule.")
        self.v1.register_request(self.put_analysis, "PUT",
                                 (webservice.WSPathStaticString('policy'),
                                  WSPathExistingPolicyId(self.policy),
                                  webservice.WSPathStaticString('analysis'),
                                  webservice.WSPathStaticString('rules')),
                                 "Analyze a new policy relative to another.")
        self.v1.register_request(self.delete_rule, "DELETE",
                                 (webservice.WSPathStaticString('policy'),
                                  WSPathExistingPolicyId(self.policy),
                                  webservice.WSPathStaticString('rule'),
                                  WSPathExistingRuleId(self.policy)),
                                 "Delete a rule by id.")
        self.v1.register_request(self.post_rules, "POST",
                                 (webservice.WSPathStaticString('policy'), ),
                                 "Post a new policy.")
コード例 #18
0
    def install(self):

        self.cfg = self.resolve(local_config)

        ws = self.resolve(str(webservice.webservice))

        v1 = ws.get_version("1")
        reg = v1.register_request

        # /ws.v1/nox/local_config/hostname
        #nox_local_config_hostname = ( webservice.WSPathStaticString("nox"),
        #                              webservice.WSPathStaticString("local_config"),
        #                              webservice.WSPathStaticString("hostname"), )
        #reg(self.get_hostname, "GET", nox_local_config_hostname,
        #        """Get server hostname""")

        # GET /ws.v1/nox/local_config/active/interface/<interface>
        nox_local_config = (webservice.WSPathStaticString("nox"),
                            webservice.WSPathStaticString("local_config"),
                            webservice.WSPathStaticString("active"),
                            webservice.WSPathStaticString("interface"))
        reg(self.get_interfaces, "GET", nox_local_config,
            """Get active interfaces""")

        # GET /ws.v1/nox/local_config/interface/<interface>
        nox_local_config = (webservice.WSPathStaticString("nox"),
                            webservice.WSPathStaticString("local_config"),
                            webservice.WSPathStaticString("interface"),
                            WSPathValidInterfaceName(self))
        reg(self.get_interface, "GET", nox_local_config,
            """Get interface config""")

        # PUT /ws.v1/nox/local_config/interface/<interface>
        # fmt:
        # {
        #    "name": "eth0",
        #    "dhcp" : false, # if set, all address fields are ignored
        #    "ip4dns": "192.168.1.14",
        #    "ip4mask": "255.255.255.0",
        #    "ip4addr": "192.168.1.18",
        #    "ip4bcast": "192.168.1.255",
        #    "hwaddr": "00:a0:cc:28:a9:94",
        #    "ip4gw": "192.168.1.1"
        # }
        nox_local_config = (webservice.WSPathStaticString("nox"),
                            webservice.WSPathStaticString("local_config"),
                            webservice.WSPathStaticString("interface"),
                            WSPathValidInterfaceName(self))
        reg(self.put_interface, "PUT", nox_local_config,
            """Put interface config""")

        # PUT /ws.v1/nox/local_config/shutdown
        # fmt: 'system' or 'process'
        nox_shutdown = (webservice.WSPathStaticString("nox"),
                        webservice.WSPathStaticString("local_config"),
                        webservice.WSPathStaticString("shutdown"))
        reg(self.shutdown, "PUT", nox_shutdown,
            """Shutdown the system/process""")