Skip to content

Commit

Permalink
Merge branch 'master' into 'github'
Browse files Browse the repository at this point in the history
Master

See merge request CROC.DRPO_RnD/postgres-croc/sql-boot!6
  • Loading branch information
Gramin Maksim committed Nov 5, 2019
2 parents 9f91c47 + 39862ca commit 426c6f8
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.github.mgramin.sqlboot.rest.controllers
package com.github.mgramin.sqlboot.model.connection

import com.github.mgramin.sqlboot.model.connection.Endpoint
import com.github.mgramin.sqlboot.model.connection.EndpointList
import com.github.mgramin.sqlboot.model.connection.SimpleEndpointList
import com.github.mgramin.sqlboot.model.connection.SimpleEndpoint
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
Expand All @@ -53,11 +53,18 @@ import reactor.core.scheduler.Schedulers
@ComponentScan(basePackages = ["com.github.mgramin.sqlboot.model.resource_type"])
@EnableAutoConfiguration
@CrossOrigin
class DbConnectionsController @Autowired constructor(private val endpointList: EndpointList) {
class EndpointListController @Autowired constructor(private val endpointList: SimpleEndpointList) : EndpointList {

val allDbConnections: List<SimpleEndpoint>
@RequestMapping(value = ["/endpoints"])
get() = endpointList.endpoints
@RequestMapping(value = ["/endpoints"])
override fun getAll() = MaskedEndpointListWrapper(endpointList).getAll()

override fun getByName(name: String): Endpoint {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun getByMask(mask: String): List<Endpoint> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

@GetMapping(value = ["/endpoints/health"], produces = [MediaType.TEXT_EVENT_STREAM_VALUE])
@ResponseBody
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,11 @@
/*
* BSD 3-Clause License
*
* Copyright (c) 2019, CROC Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.github.mgramin.sqlboot.model.connection

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
import org.springframework.stereotype.Service
interface EndpointList {

/**
* @author Maksim Gramin (mgramin@gmail.com)
* @version $Id: 059927ff87fb2f47a67537fa336f6e838d08c1ea $
* @since 0.1
*/
@Service
@Configuration
@ConfigurationProperties(prefix = "conf")
open class EndpointList(val endpoints: List<SimpleEndpoint>) {
fun getAll(): List<Endpoint>

fun getByName(name: String) = endpoints.first { v -> v.name().equals(name, ignoreCase = true) }
fun getByName(name: String): Endpoint

fun getByMask(mask: String) = endpoints.filter { v -> v.name().matches(mask.toRegex()) }
fun getByMask(mask: String): List<Endpoint>

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.mgramin.sqlboot.model.connection

class MaskedEndpointListWrapper(private val origin: EndpointList) : EndpointList {

override fun getAll(): List<Endpoint> =
origin.getAll().map {
return@map SimpleEndpoint(
it.name(), it.host(), it.confDir(),
it.properties().filterNot { itt -> itt.key.contains("password", true) })
}

override fun getByName(name: String): Endpoint {
val origin = origin.getByName(name)
return SimpleEndpoint(
origin.name(), origin.host(), origin.confDir(),
origin.properties().filterNot { it.key.contains("password", true) })
}

override fun getByMask(mask: String): List<Endpoint> =
origin.getByMask(mask).map {
SimpleEndpoint(
it.name(), it.host(), it.confDir(),
it.properties().filterNot { itt -> itt.key.contains("password", true) })
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* BSD 3-Clause License
*
* Copyright (c) 2019, CROC Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.github.mgramin.sqlboot.model.connection

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
import org.springframework.stereotype.Service

/**
* @author Maksim Gramin (mgramin@gmail.com)
* @version $Id: 059927ff87fb2f47a67537fa336f6e838d08c1ea $
* @since 0.1
*/
@Service
@Configuration
@ConfigurationProperties(prefix = "conf")
open class SimpleEndpointList(val endpoints: List<SimpleEndpoint>) : EndpointList {

override fun getAll() = endpoints

override fun getByName(name: String): Endpoint = endpoints.first { v -> v.name().equals(name, ignoreCase = true) }

override fun getByMask(mask: String): List<Endpoint> = endpoints.filter { v -> v.name().matches(mask.toRegex()) }

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package com.github.mgramin.sqlboot.model.resourcetype.impl

import com.github.mgramin.sqlboot.exceptions.BootException
import com.github.mgramin.sqlboot.model.connection.Endpoint
import com.github.mgramin.sqlboot.model.connection.SimpleEndpoint
import com.github.mgramin.sqlboot.model.dialect.Dialect
import com.github.mgramin.sqlboot.model.resourcetype.Metadata
Expand All @@ -53,7 +54,7 @@ import java.nio.charset.StandardCharsets.UTF_8
* Created by MGramin on 11.07.2017.
*/
class FsResourceType(
private val endpoints: List<SimpleEndpoint>,
private val endpoints: List<Endpoint>,
private val dialects: List<Dialect>
) : ResourceType {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
package com.github.mgramin.sqlboot.rest.controllers

import com.github.mgramin.sqlboot.exceptions.BootException
import com.github.mgramin.sqlboot.model.connection.EndpointList
import com.github.mgramin.sqlboot.model.connection.SimpleEndpointList
import com.github.mgramin.sqlboot.model.dialect.DbDialectList
import com.github.mgramin.sqlboot.model.resourcetype.impl.FsResourceType
import com.github.mgramin.sqlboot.model.uri.Uri
Expand Down Expand Up @@ -65,7 +65,7 @@ import javax.servlet.http.HttpServletRequest
class ApiController {

@Autowired
private lateinit var endpointList: EndpointList
private lateinit var endpointList: SimpleEndpointList

@Autowired
private lateinit var dbDialectList: DbDialectList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
package com.github.mgramin.sqlboot.rest.controllers

import com.fasterxml.jackson.core.JsonProcessingException
import com.github.mgramin.sqlboot.model.connection.EndpointList
import com.github.mgramin.sqlboot.model.connection.SimpleEndpointList
import com.github.mgramin.sqlboot.model.resourcetype.impl.FsResourceType
import io.swagger.models.*
import io.swagger.models.parameters.Parameter
Expand Down Expand Up @@ -62,7 +62,7 @@ import javax.servlet.http.HttpServletRequest
@ComponentScan(basePackages = ["com.github.mgramin.sqlboot"])
@EnableAutoConfiguration
@CrossOrigin
class SwaggerController @Autowired constructor(private val endpointList: EndpointList) {
class SwaggerController @Autowired constructor(private val endpointList: SimpleEndpointList) {

@RequestMapping(method = [RequestMethod.GET, RequestMethod.POST], path = ["/api"], produces = [MediaType.APPLICATION_JSON_VALUE])
@Throws(JsonProcessingException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ import org.springframework.test.context.junit.jupiter.SpringExtension

@ExtendWith(SpringExtension::class)
@EnableAutoConfiguration
@ContextConfiguration(classes = [EndpointList::class], initializers = [ConfigFileApplicationContextInitializer::class])
internal class EndpointListTest {
@ContextConfiguration(classes = [SimpleEndpointList::class], initializers = [ConfigFileApplicationContextInitializer::class])
internal class SimpleEndpointListTest {

@Autowired
lateinit var endpointList: EndpointList
lateinit var endpointList: SimpleEndpointList

@ParameterizedTest
@ValueSource(strings = ["h2"])
Expand Down

0 comments on commit 426c6f8

Please sign in to comment.