From f1b6e09c6af81a9169aff0be5f06523225fa10bd Mon Sep 17 00:00:00 2001 From: Sylvain Joubert Date: Thu, 6 Mar 2025 10:45:37 +0100 Subject: [PATCH 1/3] Remove some property fields - csm.platform.{summary,description,version} are not used - csm.platform.{commitId,vcsRef} should not be configurable at runtime, we'll inject them at build time from the build system --- .../api/config/CsmOpenAPIConfiguration.kt | 7 ------- .../api/config/CsmPlatformProperties.kt | 16 ---------------- 2 files changed, 23 deletions(-) diff --git a/src/main/kotlin/com/cosmotech/api/config/CsmOpenAPIConfiguration.kt b/src/main/kotlin/com/cosmotech/api/config/CsmOpenAPIConfiguration.kt index 347222c8..669e1043 100644 --- a/src/main/kotlin/com/cosmotech/api/config/CsmOpenAPIConfiguration.kt +++ b/src/main/kotlin/com/cosmotech/api/config/CsmOpenAPIConfiguration.kt @@ -38,13 +38,6 @@ 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}" - } - // 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 openAPI.servers = listOf() diff --git a/src/main/kotlin/com/cosmotech/api/config/CsmPlatformProperties.kt b/src/main/kotlin/com/cosmotech/api/config/CsmPlatformProperties.kt index 775f976a..81b741d9 100644 --- a/src/main/kotlin/com/cosmotech/api/config/CsmPlatformProperties.kt +++ b/src/main/kotlin/com/cosmotech/api/config/CsmPlatformProperties.kt @@ -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, From cce8b4ea42fd7e67023c42212fa6bdbc2943d843 Mon Sep 17 00:00:00 2001 From: Sylvain Joubert Date: Thu, 6 Mar 2025 17:00:55 +0100 Subject: [PATCH 2/3] Display full version from embedded version resource in the openapi description --- .../api/config/CsmOpenAPIConfiguration.kt | 4 ++++ .../com/cosmotech/api/utils/AboutInfo.kt | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/main/kotlin/com/cosmotech/api/utils/AboutInfo.kt diff --git a/src/main/kotlin/com/cosmotech/api/config/CsmOpenAPIConfiguration.kt b/src/main/kotlin/com/cosmotech/api/config/CsmOpenAPIConfiguration.kt index 669e1043..994e9ded 100644 --- a/src/main/kotlin/com/cosmotech/api/config/CsmOpenAPIConfiguration.kt +++ b/src/main/kotlin/com/cosmotech/api/config/CsmOpenAPIConfiguration.kt @@ -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) { @@ -38,6 +39,9 @@ open class CsmOpenAPIConfiguration(val csmPlatformProperties: CsmPlatformPropert openAPI.info.version = apiVersion + 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 openAPI.servers = listOf() diff --git a/src/main/kotlin/com/cosmotech/api/utils/AboutInfo.kt b/src/main/kotlin/com/cosmotech/api/utils/AboutInfo.kt new file mode 100644 index 00000000..5d55105f --- /dev/null +++ b/src/main/kotlin/com/cosmotech/api/utils/AboutInfo.kt @@ -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) + } +} From c3c2cb6dc333080ba24bcb6a47c10c2bc615337f Mon Sep 17 00:00:00 2001 From: Sylvain Joubert Date: Fri, 7 Mar 2025 11:22:53 +0100 Subject: [PATCH 3/3] Add security config for the new '/about' endpoint --- .../api/security/AbstractSecurityConfiguration.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/kotlin/com/cosmotech/api/security/AbstractSecurityConfiguration.kt b/src/main/kotlin/com/cosmotech/api/security/AbstractSecurityConfiguration.kt index 85dcdca8..25484f58 100644 --- a/src/main/kotlin/com/cosmotech/api/security/AbstractSecurityConfiguration.kt +++ b/src/main/kotlin/com/cosmotech/api/security/AbstractSecurityConfiguration.kt @@ -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 =