Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.io.BufferedReader
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import com.cosmotech.api.utils.getAboutInfo

@Configuration
open class CsmOpenAPIConfiguration(val csmPlatformProperties: CsmPlatformProperties) {
Expand Down Expand Up @@ -38,12 +39,8 @@ open class CsmOpenAPIConfiguration(val csmPlatformProperties: CsmPlatformPropert

openAPI.info.version = apiVersion

if (!csmPlatformProperties.vcsRef.isNullOrBlank()) {
openAPI.info.description += " / ${csmPlatformProperties.vcsRef}"
}
if (!csmPlatformProperties.commitId.isNullOrBlank()) {
openAPI.info.description += " / ${csmPlatformProperties.commitId}"
}
val fullVersion = getAboutInfo().getJSONObject("version").getString("full")
openAPI.info.description += " ($fullVersion)"

// Remove any set of servers already defined in the input openapi.yaml,
// so as to have the base URL auto-generated based on the incoming requests
Expand Down
16 changes: 0 additions & 16 deletions src/main/kotlin/com/cosmotech/api/config/CsmPlatformProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties
/** Configuration Properties for the Cosmo Tech Platform */
@ConfigurationProperties(prefix = "csm.platform")
data class CsmPlatformProperties(

/** Platform summary */
val summary: String?,

/** Platform description */
val description: String?,

/** Platform version (MAJOR.MINOR.PATCH) */
val version: String?,

/** Platform exact commit ID */
val commitId: String? = null,

/** Platform exact Version-Control System reference */
val vcsRef: String? = null,

/** API Configuration */
val api: Api,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ internal fun endpointSecurityReaders(
customOrganizationViewer: String
) =
listOf(
CsmSecurityEndpointsRolesReader(
paths = listOf("/about"),
roles =
arrayOf(
ROLE_ORGANIZATION_USER,
ROLE_ORGANIZATION_VIEWER,
customOrganizationUser,
customOrganizationViewer),
customAdmin = customOrganizationAdmin),
CsmSecurityEndpointsRolesReader(
paths = PATHS_CONNECTORS,
roles =
Expand Down
22 changes: 22 additions & 0 deletions src/main/kotlin/com/cosmotech/api/utils/AboutInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Cosmo Tech.
// Licensed under the MIT license.
package com.cosmotech.api.utils

import java.io.BufferedReader
import org.json.JSONException
import org.json.JSONObject

fun getAboutInfo(): JSONObject {
val aboutJsonInputStream =
object{}::class.java.getResourceAsStream("/about.json")
?: throw IllegalStateException("Unable to read about info data from 'classpath:/about.json'")
val aboutJsonContent = aboutJsonInputStream.use { it.bufferedReader().use(BufferedReader::readText) }

try {
return JSONObject(aboutJsonContent)
}
catch (e: JSONException)
{
throw IllegalStateException("Unable to parse about info from 'classpath:/about.json'", e)
}
}