Browse Source

[1976] Configuring a class the first time

We can now create a list for a class and set it through configuration.
Michal 'vorner' Vaner 13 years ago
parent
commit
18da272708

+ 3 - 3
src/bin/auth/auth_srv.cc

@@ -1038,12 +1038,12 @@ AuthSrv::setClientList(const RRClass& rrclass,
     }
 }
 
-boost::shared_ptr<const ClientList>
-AuthSrv::getClientList(const RRClass& rrclass) const {
+boost::shared_ptr<ClientList>
+AuthSrv::getClientList(const RRClass& rrclass) {
     const map<RRClass, boost::shared_ptr<ClientList> >::const_iterator
         it(impl_->client_lists_.find(rrclass));
     if (it == impl_->client_lists_.end()) {
-        return (boost::shared_ptr<const ClientList>());
+        return (boost::shared_ptr<ClientList>());
     } else {
         return (it->second);
     }

+ 2 - 2
src/bin/auth/auth_srv.h

@@ -436,8 +436,8 @@ public:
     ///
     /// \param rrclass The class for which to get the list.
     /// \return The list, or NULL if no list is set for the class.
-    boost::shared_ptr<const isc::datasrc::ClientList>
-        getClientList(const isc::dns::RRClass& rrclass) const;
+    boost::shared_ptr<isc::datasrc::ClientList>
+        getClientList(const isc::dns::RRClass& rrclass);
 
     /// \brief Returns a list of classes that have a client list.
     ///

+ 18 - 2
src/bin/auth/datasrc_configurator.h

@@ -49,6 +49,7 @@ private:
     }
     static Server* server_;
     static isc::config::ModuleCCSession* session_;
+    typedef boost::shared_ptr<List> ListPtr;
 public:
     /// \brief Initializes the class.
     ///
@@ -108,8 +109,23 @@ public:
     /// \param config The configuration value to parse. It is in the form
     ///     as an update from the config manager.
     /// \throw InvalidOperation if it is called when not initialized.
-    static void reconfigure(const isc::data::ConstElementPtr& ) {
-
+    static void reconfigure(const isc::data::ConstElementPtr& config) {
+        // TODO: The InvalidOperation thing
+        typedef std::map<std::string, isc::data::ConstElementPtr> Map;
+        const Map& map(config->mapValue());
+        for (Map::const_iterator it(map.begin()); it != map.end(); ++ it) {
+            isc::dns::RRClass rrclass(it->first);
+            ListPtr list(server_->getClientList(rrclass));
+            bool need_set(false);
+            if (!list) {
+                list.reset(new List);
+                need_set = true;
+            }
+            list->configure(*it->second, true);
+            if (need_set) {
+                server_->setClientList(rrclass, list);
+            }
+        }
     }
 };
 

+ 39 - 1
src/bin/auth/tests/datasrc_configurator_unittest.cc

@@ -19,27 +19,51 @@
 
 #include <gtest/gtest.h>
 #include <memory>
+#include <boost/shared_ptr.hpp>
 
 using namespace isc;
 using namespace isc::cc;
 using namespace isc::config;
 using namespace isc::data;
+using namespace isc::dns;
 using namespace std;
+using namespace boost;
 
 namespace {
 
 class DatasrcConfiguratorTest;
 
 class FakeList {
-
+public:
+    void configure(const Element& configuration, bool allow_cache) {
+        EXPECT_TRUE(allow_cache);
+        conf_ = configuration.get(0)->get("type")->stringValue();
+    }
+    const string& getConf() const {
+        return (conf_);
+    }
+private:
+    string conf_;
 };
 
+typedef shared_ptr<FakeList> ListPtr;
+
 // We use the test fixture as both parameters, this makes it possible
 // to easily fake all needed methods and look that they were called.
 typedef DataSourceConfiguratorGeneric<DatasrcConfiguratorTest,
         FakeList> Configurator;
 
 class DatasrcConfiguratorTest : public ::testing::Test {
+public:
+    // These pretend to be the server
+    ListPtr getClientList(const RRClass& rrclass) {
+        log_ += "get " + rrclass.toText() + "\n";
+        return (lists_[rrclass]);
+    }
+    void setClientList(const RRClass& rrclass, const ListPtr& list) {
+        log_ += "set " + rrclass.toText() + " " + list->getConf() + "\n";
+        lists_[rrclass] = list;
+    }
 protected:
     DatasrcConfiguratorTest() :
         session(ElementPtr(new ListElement), ElementPtr(new ListElement),
@@ -77,6 +101,8 @@ protected:
     FakeSession session;
     auto_ptr<ModuleCCSession> mccs;
     const string specfile;
+    map<RRClass, ListPtr> lists_;
+    string log_;
 };
 
 // Check the initialization (and deinitialization)
@@ -97,4 +123,16 @@ TEST_F(DatasrcConfiguratorTest, initialization) {
     EXPECT_TRUE(session.haveSubscription("data_sources", "*"));
 }
 
+// Push there a configuration with a single list.
+TEST_F(DatasrcConfiguratorTest, createList) {
+    const ElementPtr
+        config(Element::fromJSON("{\"IN\": [{\"type\": \"xxx\"}]}"));
+    session.addMessage(createCommand("config_update", config), "data_sources",
+                       "*");
+    mccs->checkCommand();
+    // Check it called the correct things (check that there's no IN yet and
+    // set a new one.
+    EXPECT_EQ("get IN\nset IN xxx\n", log_);
+}
+
 }