Skip to content

Commit

Permalink
feat(plugins): Binary publish proxy endpoint (#1066)
Browse files Browse the repository at this point in the history
* refactor(plugins): Rename gate-deck-plugins module to gate-plugins

* refactor(plugins): Move deck plugin proxy code to new package

* feat(plugins): Add endpoint to proxy plugin binary publishing

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
robzienert and mergify[bot] authored Feb 19, 2020
1 parent 8e51ed1 commit 384e331
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 22 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
continuation_indent_size = 4
21 changes: 21 additions & 0 deletions gate-api/gate-api.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020 Netflix, Inc.
*
* 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.
*/
apply plugin: 'java-library'

dependencies {
implementation platform("com.netflix.spinnaker.kork:kork-bom:$korkVersion")
api "com.netflix.spinnaker.kork:kork-plugins-api"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.netflix.spinnaker.gate.services.internal
import com.netflix.spinnaker.fiat.model.resources.ServiceAccount
import retrofit.client.Response
import retrofit.http.*
import retrofit.mime.TypedInput

interface Front50Service {
@GET("/credentials")
Expand Down Expand Up @@ -160,4 +161,13 @@ interface Front50Service {
// Plugins related
@GET('/pluginInfo')
List<Map> getPluginInfo(@Query("service") String service)

@POST("/pluginBinaries/{id}/{version}")
@Headers(["Content-Type: application/zip,application/octet-stream"])
Response uploadPluginBinary(
@Path("id") String pluginId,
@Path("version") String pluginVersion,
@Query("sha512sum") String sha512sum,
@Body TypedInput pluginBinary
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ apply from: "${project.rootDir}/gradle/kotlin.gradle"
apply from: "${project.rootDir}/gradle/kotlin-test.gradle"

dependencies {
implementation project(":gate-api")
implementation project(":gate-core")

implementation "com.netflix.spinnaker.kork:kork-plugins"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.spinnaker.gate.plugins
package com.netflix.spinnaker.gate.plugins.deck

import com.netflix.spinnaker.kork.exceptions.SystemException

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.spinnaker.gate.plugins
package com.netflix.spinnaker.gate.plugins.deck

import com.netflix.spectator.api.Id
import com.netflix.spectator.api.Registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.spinnaker.gate.plugins
package com.netflix.spinnaker.gate.plugins.deck

import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.kork.plugins.bundle.PluginBundleExtractor
Expand All @@ -26,15 +26,15 @@ import org.springframework.scheduling.annotation.EnableScheduling

@Configuration
@ConditionalOnProperty("spinnaker.extensibility.deck-proxy.enabled", matchIfMissing = true)
@ComponentScan("com.netflix.spinnaker.gate.plugins")
@ComponentScan("com.netflix.spinnaker.gate.plugins.deck")
@EnableScheduling
open class DeckPluginConfiguration {
@Bean
open fun deckPluginCache(
updateManager: SpinnakerUpdateManager,
registry: Registry
): DeckPluginCache =
DeckPluginCache(updateManager, PluginBundleExtractor(), registry)
DeckPluginCache(updateManager, PluginBundleExtractor(), registry)

@Bean
open fun deckPluginService(
Expand All @@ -44,5 +44,5 @@ open class DeckPluginConfiguration {

@Bean
open fun deckPluginsController(pluginService: DeckPluginService): DeckPluginsController =
DeckPluginsController(pluginService)
DeckPluginsController(pluginService)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.spinnaker.gate.plugins
package com.netflix.spinnaker.gate.plugins.deck

import com.netflix.spectator.api.Registry
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -78,9 +78,15 @@ class DeckPluginService(
fun from(file: File): PluginAsset {
return PluginAsset(
contentType = when {
file.toString().endsWith(".js") -> { "application/javascript" }
file.toString().endsWith(".css") -> { "text/css" }
file.toString().endsWith(".html") -> { "text/html" }
file.toString().endsWith(".js") -> {
"application/javascript"
}
file.toString().endsWith(".css") -> {
"text/css"
}
file.toString().endsWith(".html") -> {
"text/html"
}
else -> {
log.warn("Unhandled file extension to content-type mapping for file `{}`, falling back to text/plain", file.toString())
"text/plain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.spinnaker.gate.plugins
package com.netflix.spinnaker.gate.plugins.deck

/**
* A plugin manifest used by Deck to know what plugins should be installed and at what version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.spinnaker.gate.plugins
package com.netflix.spinnaker.gate.plugins.deck

import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import io.swagger.annotations.ApiOperation
Expand All @@ -26,7 +26,6 @@ import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.util.concurrent.TimeUnit
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@RestController
Expand Down Expand Up @@ -65,8 +64,7 @@ class DeckPluginsController(
@ExceptionHandler(CacheNotReadyException::class)
fun handleCacheNotReadyException(
e: Exception,
response: HttpServletResponse,
request: HttpServletRequest?
response: HttpServletResponse
) {
response.sendError(HttpStatus.SERVICE_UNAVAILABLE.value(), e.message)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2020 Netflix, Inc.
*
* 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 com.netflix.spinnaker.gate.plugins.publish

import com.netflix.spinnaker.gate.services.internal.Front50Service
import io.swagger.annotations.ApiOperation
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import retrofit.mime.TypedByteArray
import java.io.InputStream

@RestController
@RequestMapping("/plugins/upload")
class PluginBinaryController(
private val front50Service: Front50Service
) {

@ApiOperation(value = "Upload a plugin binary")
@PostMapping(
"/{pluginId}/{pluginVersion}",
consumes = ["application/zip", "application/octet-stream"]
)
fun publishBinary(
@RequestBody body: InputStream,
@PathVariable pluginId: String,
@PathVariable pluginVersion: String,
@RequestParam sha512sum: String
) {
front50Service.uploadPluginBinary(
pluginId,
pluginVersion,
sha512sum,
TypedByteArray("application/octet-stream", body.readBytes())
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2020 Netflix, Inc.
*
* 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 com.netflix.spinnaker.gate.plugins.publish

import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration

@Configuration
@ComponentScan("com.netflix.spinnaker.gate.plugins.publish")
open class PluginPublishConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.spinnaker.gate.plugins
package com.netflix.spinnaker.gate.plugins.deck

import com.netflix.spectator.api.NoopRegistry
import com.netflix.spectator.api.Registry
Expand Down
2 changes: 1 addition & 1 deletion gate-web/gate-web.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
dependencies {
implementation project(":gate-core")
implementation project(":gate-proxy")
implementation project(":gate-deck-plugins")
implementation project(":gate-plugins")
implementation project(":gate-integrations-gremlin")

implementation "com.squareup.retrofit:retrofit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import com.netflix.spinnaker.filters.AuthenticatedRequestFilter
import com.netflix.spinnaker.gate.config.PostConnectionConfiguringJedisConnectionFactory.ConnectionPostProcessor
import com.netflix.spinnaker.gate.converters.JsonHttpMessageConverter
import com.netflix.spinnaker.gate.converters.YamlHttpMessageConverter
import com.netflix.spinnaker.gate.plugins.DeckPluginConfiguration
import com.netflix.spinnaker.gate.plugins.deck.DeckPluginConfiguration
import com.netflix.spinnaker.gate.plugins.publish.PluginPublishConfiguration
import com.netflix.spinnaker.gate.retrofit.Slf4jRetrofitLogger
import com.netflix.spinnaker.gate.services.EurekaLookupService
import com.netflix.spinnaker.gate.services.internal.*
Expand Down Expand Up @@ -83,7 +84,7 @@ import static retrofit.Endpoints.newFixedEndpoint
@Configuration
@Slf4j
@EnableConfigurationProperties([FiatClientConfigurationProperties, DynamicRoutingConfigProperties])
@Import([PluginsAutoConfiguration, DeckPluginConfiguration])
@Import([PluginsAutoConfiguration, DeckPluginConfiguration, PluginPublishConfiguration])
class GateConfig extends RedisHttpSessionConfiguration {

@Value('${server.session.timeout-in-seconds:3600}')
Expand Down
5 changes: 3 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

rootProject.name = "gate"

include "gate-core",
"gate-deck-plugins",
include "gate-api",
"gate-core",
"gate-plugins",
"gate-basic",
"gate-bom",
"gate-iap",
Expand Down

0 comments on commit 384e331

Please sign in to comment.