HONEYCOMB-360 - Common northbound configuration 64/7364/3
authorJan Srnicek <jsrnicek@cisco.com>
Fri, 30 Jun 2017 11:46:26 +0000 (13:46 +0200)
committerMarek Gradzki <mgradzki@cisco.com>
Fri, 30 Jun 2017 20:19:00 +0000 (22:19 +0200)
Change-Id: Iefa1c4a7388c628c9527a00b13be59d98db640ec
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
18 files changed:
infra/bgp-distribution-test/src/test/resources/base-distro-test-modules/base-modules
infra/bgp-distribution-test/src/test/resources/credentials.json [new file with mode: 0644]
infra/bgp-distribution-test/src/test/resources/honeycomb.json
infra/minimal-distribution-core/pom.xml
infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java
infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.java
infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/restconf/JettyServerProvider.java
infra/minimal-distribution-test/src/test/resources/base-distro-test-modules/base-modules
infra/minimal-distribution-test/src/test/resources/credentials.json [new file with mode: 0644]
infra/minimal-distribution-test/src/test/resources/honeycomb.json
infra/minimal-distribution/pom.xml
infra/minimal-distribution/src/main/resources/honeycomb-minimal-resources/config/honeycomb.json
infra/northbound/asciidoc/Readme.adoc [new file with mode: 0644]
infra/northbound/common/asciidoc/Readme.adoc [new file with mode: 0644]
infra/northbound/common/pom.xml
infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsConfiguration.java [new file with mode: 0644]
infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsModule.java [new file with mode: 0644]
infra/northbound/common/src/main/resources/honeycomb-minimal-resources/config/credentials.json [new file with mode: 0644]

index 18602a0..c476fcc 100644 (file)
@@ -7,6 +7,7 @@ io.fd.honeycomb.infra.distro.cfgattrs.CfgAttrsModule
 io.fd.honeycomb.infra.distro.data.ConfigAndOperationalPipelineModule
 io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule
 io.fd.honeycomb.infra.distro.initializer.InitializerPipelineModule
+io.fd.honeycomb.northbound.CredentialsModule
 io.fd.honeycomb.infra.distro.netconf.NetconfModule
 io.fd.honeycomb.infra.distro.netconf.NetconfReadersModule
 io.fd.honeycomb.infra.distro.restconf.RestconfModule
diff --git a/infra/bgp-distribution-test/src/test/resources/credentials.json b/infra/bgp-distribution-test/src/test/resources/credentials.json
new file mode 100644 (file)
index 0000000..93b908f
--- /dev/null
@@ -0,0 +1,4 @@
+{
+  "username": "admin",
+  "password": "admin"
+}
\ No newline at end of file
index a0b2a63..8ff269a 100644 (file)
@@ -33,8 +33,5 @@
   "netconf-ssh-enabled" : "true",
   "netconf-ssh-binding-address": "127.0.0.1",
   "netconf-ssh-binding-port": 2832,
-  "netconf-notification-stream-name": "honeycomb",
-
-  "username": "admin",
-  "password": "admin"
+  "netconf-notification-stream-name": "honeycomb"
 }
\ No newline at end of file
index 117ec11..1763cce 100644 (file)
             <version>${osgi.core.version}</version>
         </dependency>
 
+        <!-- Northbound -->
+        <dependency>
+            <groupId>io.fd.honeycomb.northbound</groupId>
+            <artifactId>common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
         <!-- HC -->
         <dependency>
             <groupId>${project.groupId}</groupId>
index cc46f7b..f7d5ca5 100644 (file)
@@ -138,10 +138,6 @@ public class HoneycombConfiguration {
     public Optional<Integer> netconfSshBindingPort;
     @InjectConfig("netconf-notification-stream-name")
     public Optional<String> netconfNotificationStreamName = Optional.of("honeycomb");
-    @InjectConfig("username")
-    public String username;
-    @InjectConfig("password")
-    public String password;
 
     @Override
     public String toString() {
@@ -178,8 +174,6 @@ public class HoneycombConfiguration {
                 .add("netconfSshBindingAddress", netconfSshBindingAddress)
                 .add("netconfSshBindingPort", netconfSshBindingPort)
                 .add("netconfNotificationStreamName", netconfNotificationStreamName)
-                .add("username", username)
-                .add("password", password)
                 .toString();
     }
 }
index ba36a26..8d86677 100644 (file)
@@ -21,6 +21,7 @@ import com.google.inject.Inject;
 import io.fd.honeycomb.infra.distro.InitializationException;
 import io.fd.honeycomb.infra.distro.ProviderTrait;
 import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration;
+import io.fd.honeycomb.northbound.CredentialsConfiguration;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.local.LocalAddress;
 import io.netty.channel.nio.NioEventLoopGroup;
@@ -51,6 +52,8 @@ public final class NetconfSshServerProvider extends ProviderTrait<NetconfSshServ
     private HoneycombConfiguration cfgAttributes;
     @Inject
     private NioEventLoopGroup nettyThreadgroup;
+    @Inject
+    private CredentialsConfiguration credentialsCfg;
 
     private ScheduledExecutorService pool =
             Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("netconf-ssh-%d").build());
@@ -76,7 +79,7 @@ public final class NetconfSshServerProvider extends ProviderTrait<NetconfSshServ
         sshConfigBuilder.setBindingAddress(bindingAddress);
         sshConfigBuilder.setLocalAddress(localAddress);
         // Only simple authProvider checking ConfigAttributes, checking the config file
-        sshConfigBuilder.setAuthenticator(new SimplelAuthProvider(cfgAttributes));
+        sshConfigBuilder.setAuthenticator(new SimplelAuthProvider(credentialsCfg));
         sshConfigBuilder.setIdleTimeout(Integer.MAX_VALUE);
         sshConfigBuilder.setKeyPairProvider(new PEMGeneratorHostKeyProvider());
 
@@ -106,9 +109,9 @@ public final class NetconfSshServerProvider extends ProviderTrait<NetconfSshServ
 
     private static final class SimplelAuthProvider implements AuthProvider {
 
-        private final HoneycombConfiguration cfgAttributes;
+        private final CredentialsConfiguration cfgAttributes;
 
-        SimplelAuthProvider(final HoneycombConfiguration cfgAttributes) {
+        SimplelAuthProvider(final CredentialsConfiguration cfgAttributes) {
             this.cfgAttributes = cfgAttributes;
         }
 
index bc5fe8b..0c80873 100644 (file)
@@ -19,6 +19,7 @@ package io.fd.honeycomb.infra.distro.restconf;
 import com.google.inject.Inject;
 import io.fd.honeycomb.infra.distro.ProviderTrait;
 import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration;
+import io.fd.honeycomb.northbound.CredentialsConfiguration;
 import java.net.URL;
 import java.util.Collections;
 import org.eclipse.jetty.security.ConstraintMapping;
@@ -45,6 +46,9 @@ final class JettyServerProvider extends ProviderTrait<Server> {
     @Inject
     private HoneycombConfiguration cfg;
 
+    @Inject
+    private CredentialsConfiguration credentialsCfg;
+
     @Override
     protected Server create() {
         Server server = new Server(new QueuedThreadPool(cfg.restPoolMaxSize.get(), cfg.restPoolMinSize.get()));
@@ -52,7 +56,8 @@ final class JettyServerProvider extends ProviderTrait<Server> {
         // Load Realm for basic auth
         HashLoginService service = new HashLoginService(REALM);
         // Reusing the name as role
-        service.putUser(cfg.username, new Password(cfg.password), new String[]{cfg.username});
+        service.putUser(credentialsCfg.username, new Password(credentialsCfg.password),
+                new String[]{credentialsCfg.username});
         server.addBean(service);
 
         final URL resource = getClass().getResource("/");
@@ -73,7 +78,7 @@ final class JettyServerProvider extends ProviderTrait<Server> {
         Constraint constraint = new Constraint();
         constraint.setName("auth");
         constraint.setAuthenticate(true);
-        constraint.setRoles(new String[]{cfg.username});
+        constraint.setRoles(new String[]{credentialsCfg.username});
 
         ConstraintMapping mapping = new ConstraintMapping();
         mapping.setPathSpec("/*");
index 28b2844..33912c7 100644 (file)
@@ -2,6 +2,7 @@ io.fd.honeycomb.infra.distro.cfgattrs.CfgAttrsModule
 io.fd.honeycomb.infra.distro.data.ConfigAndOperationalPipelineModule
 io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule
 io.fd.honeycomb.infra.distro.initializer.InitializerPipelineModule
+io.fd.honeycomb.northbound.CredentialsModule
 io.fd.honeycomb.infra.distro.netconf.NetconfModule
 io.fd.honeycomb.infra.distro.netconf.NetconfReadersModule
 io.fd.honeycomb.infra.distro.restconf.RestconfModule
diff --git a/infra/minimal-distribution-test/src/test/resources/credentials.json b/infra/minimal-distribution-test/src/test/resources/credentials.json
new file mode 100644 (file)
index 0000000..93b908f
--- /dev/null
@@ -0,0 +1,4 @@
+{
+  "username": "admin",
+  "password": "admin"
+}
\ No newline at end of file
index a0b2a63..8ff269a 100644 (file)
@@ -33,8 +33,5 @@
   "netconf-ssh-enabled" : "true",
   "netconf-ssh-binding-address": "127.0.0.1",
   "netconf-ssh-binding-port": 2832,
-  "netconf-notification-stream-name": "honeycomb",
-
-  "username": "admin",
-  "password": "admin"
+  "netconf-notification-stream-name": "honeycomb"
 }
\ No newline at end of file
index 0d7167e..66f15f7 100644 (file)
@@ -36,6 +36,7 @@
             io.fd.honeycomb.infra.distro.data.ConfigAndOperationalPipelineModule,
             io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule,
             io.fd.honeycomb.infra.distro.initializer.InitializerPipelineModule,
+            io.fd.honeycomb.northbound.CredentialsModule,
             io.fd.honeycomb.infra.distro.netconf.NetconfModule,
             io.fd.honeycomb.infra.distro.netconf.NetconfReadersModule,
             io.fd.honeycomb.infra.distro.restconf.RestconfModule,
             <version>${project.version}</version>
         </dependency>
 
+        <!-- Northbound interfaces -->
+        <dependency>
+            <groupId>io.fd.honeycomb.northbound</groupId>
+            <artifactId>common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-server</artifactId>
index 1199f85..a5a18bd 100644 (file)
@@ -35,8 +35,5 @@
   "netconf-ssh-enabled" : "true",
   "netconf-ssh-binding-address": "0.0.0.0",
   "netconf-ssh-binding-port": 2831,
-  "netconf-notification-stream-name": "honeycomb",
-
-  "username": "admin",
-  "password": "admin"
+  "netconf-notification-stream-name": "honeycomb"
 }
\ No newline at end of file
diff --git a/infra/northbound/asciidoc/Readme.adoc b/infra/northbound/asciidoc/Readme.adoc
new file mode 100644 (file)
index 0000000..c13db66
--- /dev/null
@@ -0,0 +1,3 @@
+= northbound-aggegator
+
+Overview of northbound-aggegator
\ No newline at end of file
diff --git a/infra/northbound/common/asciidoc/Readme.adoc b/infra/northbound/common/asciidoc/Readme.adoc
new file mode 100644 (file)
index 0000000..8ad9d81
--- /dev/null
@@ -0,0 +1,3 @@
+= common
+
+Provides common logic and configuration for northbound interfaces
\ No newline at end of file
index 37381a3..d8f0902 100644 (file)
@@ -36,5 +36,9 @@
             <groupId>com.google.inject</groupId>
             <artifactId>guice</artifactId>
         </dependency>
+        <dependency>
+            <groupId>net.jmob</groupId>
+            <artifactId>guice.conf</artifactId>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsConfiguration.java b/infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsConfiguration.java
new file mode 100644 (file)
index 0000000..e1a6881
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.northbound;
+
+import net.jmob.guice.conf.core.BindConfig;
+import net.jmob.guice.conf.core.InjectConfig;
+import net.jmob.guice.conf.core.Syntax;
+
+@BindConfig(value = "credentials", syntax = Syntax.JSON)
+public class CredentialsConfiguration {
+
+    @InjectConfig("username")
+    public String username;
+    @InjectConfig("password")
+    public String password;
+}
diff --git a/infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsModule.java b/infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsModule.java
new file mode 100644 (file)
index 0000000..9880767
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.northbound;
+
+import com.google.inject.AbstractModule;
+
+public class CredentialsModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        requestInjection(CredentialsConfiguration.class);
+    }
+}
diff --git a/infra/northbound/common/src/main/resources/honeycomb-minimal-resources/config/credentials.json b/infra/northbound/common/src/main/resources/honeycomb-minimal-resources/config/credentials.json
new file mode 100644 (file)
index 0000000..93b908f
--- /dev/null
@@ -0,0 +1,4 @@
+{
+  "username": "admin",
+  "password": "admin"
+}
\ No newline at end of file