From 9ffb7cb36349d00ab31538c85bae597e5d10062b Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Fri, 30 Jun 2017 13:46:26 +0200 Subject: HONEYCOMB-360 - Common northbound configuration Change-Id: Iefa1c4a7388c628c9527a00b13be59d98db640ec Signed-off-by: Jan Srnicek Signed-off-by: Marek Gradzki --- .../base-distro-test-modules/base-modules | 1 + .../src/test/resources/credentials.json | 4 +++ .../src/test/resources/honeycomb.json | 5 +--- infra/minimal-distribution-core/pom.xml | 7 +++++ .../distro/cfgattrs/HoneycombConfiguration.java | 6 ----- .../distro/netconf/NetconfSshServerProvider.java | 9 ++++--- .../infra/distro/restconf/JettyServerProvider.java | 9 +++++-- .../base-distro-test-modules/base-modules | 1 + .../src/test/resources/credentials.json | 4 +++ .../src/test/resources/honeycomb.json | 5 +--- infra/minimal-distribution/pom.xml | 8 ++++++ .../config/honeycomb.json | 5 +--- infra/northbound/asciidoc/Readme.adoc | 3 +++ infra/northbound/common/asciidoc/Readme.adoc | 3 +++ infra/northbound/common/pom.xml | 4 +++ .../northbound/CredentialsConfiguration.java | 30 ++++++++++++++++++++++ .../fd/honeycomb/northbound/CredentialsModule.java | 27 +++++++++++++++++++ .../config/credentials.json | 4 +++ 18 files changed, 112 insertions(+), 23 deletions(-) create mode 100644 infra/bgp-distribution-test/src/test/resources/credentials.json create mode 100644 infra/minimal-distribution-test/src/test/resources/credentials.json create mode 100644 infra/northbound/asciidoc/Readme.adoc create mode 100644 infra/northbound/common/asciidoc/Readme.adoc create mode 100644 infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsConfiguration.java create mode 100644 infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsModule.java create mode 100644 infra/northbound/common/src/main/resources/honeycomb-minimal-resources/config/credentials.json diff --git a/infra/bgp-distribution-test/src/test/resources/base-distro-test-modules/base-modules b/infra/bgp-distribution-test/src/test/resources/base-distro-test-modules/base-modules index 18602a0ad..c476fccca 100644 --- a/infra/bgp-distribution-test/src/test/resources/base-distro-test-modules/base-modules +++ b/infra/bgp-distribution-test/src/test/resources/base-distro-test-modules/base-modules @@ -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 index 000000000..93b908fd3 --- /dev/null +++ b/infra/bgp-distribution-test/src/test/resources/credentials.json @@ -0,0 +1,4 @@ +{ + "username": "admin", + "password": "admin" +} \ No newline at end of file diff --git a/infra/bgp-distribution-test/src/test/resources/honeycomb.json b/infra/bgp-distribution-test/src/test/resources/honeycomb.json index a0b2a633c..8ff269a1c 100644 --- a/infra/bgp-distribution-test/src/test/resources/honeycomb.json +++ b/infra/bgp-distribution-test/src/test/resources/honeycomb.json @@ -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 diff --git a/infra/minimal-distribution-core/pom.xml b/infra/minimal-distribution-core/pom.xml index 117ec1113..1763cce5e 100644 --- a/infra/minimal-distribution-core/pom.xml +++ b/infra/minimal-distribution-core/pom.xml @@ -138,6 +138,13 @@ ${osgi.core.version} + + + io.fd.honeycomb.northbound + common + ${project.version} + + ${project.groupId} diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java index cc46f7b8e..f7d5ca52a 100644 --- a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/cfgattrs/HoneycombConfiguration.java @@ -138,10 +138,6 @@ public class HoneycombConfiguration { public Optional netconfSshBindingPort; @InjectConfig("netconf-notification-stream-name") public Optional 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(); } } diff --git a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.java b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.java index ba36a266b..8d86677d3 100644 --- a/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.java +++ b/infra/minimal-distribution-core/src/main/java/io/fd/honeycomb/infra/distro/netconf/NetconfSshServerProvider.java @@ -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 { @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 { // 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 { 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("/*"); diff --git a/infra/minimal-distribution-test/src/test/resources/base-distro-test-modules/base-modules b/infra/minimal-distribution-test/src/test/resources/base-distro-test-modules/base-modules index 28b28446c..33912c7c8 100644 --- a/infra/minimal-distribution-test/src/test/resources/base-distro-test-modules/base-modules +++ b/infra/minimal-distribution-test/src/test/resources/base-distro-test-modules/base-modules @@ -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 index 000000000..93b908fd3 --- /dev/null +++ b/infra/minimal-distribution-test/src/test/resources/credentials.json @@ -0,0 +1,4 @@ +{ + "username": "admin", + "password": "admin" +} \ No newline at end of file diff --git a/infra/minimal-distribution-test/src/test/resources/honeycomb.json b/infra/minimal-distribution-test/src/test/resources/honeycomb.json index a0b2a633c..8ff269a1c 100644 --- a/infra/minimal-distribution-test/src/test/resources/honeycomb.json +++ b/infra/minimal-distribution-test/src/test/resources/honeycomb.json @@ -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 diff --git a/infra/minimal-distribution/pom.xml b/infra/minimal-distribution/pom.xml index 0d7167ed0..66f15f770 100644 --- a/infra/minimal-distribution/pom.xml +++ b/infra/minimal-distribution/pom.xml @@ -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, @@ -57,6 +58,13 @@ ${project.version} + + + io.fd.honeycomb.northbound + common + ${project.version} + + org.eclipse.jetty jetty-server diff --git a/infra/minimal-distribution/src/main/resources/honeycomb-minimal-resources/config/honeycomb.json b/infra/minimal-distribution/src/main/resources/honeycomb-minimal-resources/config/honeycomb.json index 1199f85bc..a5a18bd6d 100644 --- a/infra/minimal-distribution/src/main/resources/honeycomb-minimal-resources/config/honeycomb.json +++ b/infra/minimal-distribution/src/main/resources/honeycomb-minimal-resources/config/honeycomb.json @@ -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 index 000000000..c13db6628 --- /dev/null +++ b/infra/northbound/asciidoc/Readme.adoc @@ -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 index 000000000..8ad9d811a --- /dev/null +++ b/infra/northbound/common/asciidoc/Readme.adoc @@ -0,0 +1,3 @@ += common + +Provides common logic and configuration for northbound interfaces \ No newline at end of file diff --git a/infra/northbound/common/pom.xml b/infra/northbound/common/pom.xml index 37381a3b2..d8f09022c 100644 --- a/infra/northbound/common/pom.xml +++ b/infra/northbound/common/pom.xml @@ -36,5 +36,9 @@ com.google.inject guice + + net.jmob + guice.conf + \ 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 index 000000000..e1a688171 --- /dev/null +++ b/infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsConfiguration.java @@ -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 index 000000000..988076721 --- /dev/null +++ b/infra/northbound/common/src/main/java/io/fd/honeycomb/northbound/CredentialsModule.java @@ -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 index 000000000..93b908fd3 --- /dev/null +++ b/infra/northbound/common/src/main/resources/honeycomb-minimal-resources/config/credentials.json @@ -0,0 +1,4 @@ +{ + "username": "admin", + "password": "admin" +} \ No newline at end of file -- cgit 1.2.3-korg