diff --git a/NOTICE b/NOTICE index a07bd0175c61261da9a2b307eef2875327a4cd3c..f23dc44095f371086d63c8ee6bbab83a9f699041 100644 --- a/NOTICE +++ b/NOTICE @@ -83,7 +83,7 @@ The following software have components provided under the terms of this license: - Byte Buddy Java agent (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent) - ClassMate (from http://github.com/cowtowncoder/java-classmate) - Cloud Key Management Service (KMS) API (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms) -- Cloud Storage JSON API v1-rev20240202-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage) +- Cloud Storage JSON API (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage) - Collections (from https://repo1.maven.org/maven2/commons-collections/commons-collections) - Commons Digester (from http://commons.apache.org/digester/) - Converter: Jackson (from https://github.com/square/retrofit, https://repo1.maven.org/maven2/com/squareup/retrofit2/converter-jackson) diff --git a/README.md b/README.md index ef8491f997791998e85afeaff794838ff95e6ad0..54bf41a5ec348aee7c0c91ebc73f5a2e899c328d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## Running the Storage Service locally The Storage Service is a Maven multi-module project with each cloud implemention placed in its submodule. -### Azure +## Azure Instructions for running the Azure implementation locally can be found [here](./provider/storage-azure/README.md). @@ -21,6 +21,14 @@ Instructions for running and testing this service can be found [here](./provider All the Swagger and OpenAPI related common properties are managed here [swagger.properties](./storage-core/src/main/resources/swagger.properties) _Note: For Collaboration Filter exclusion, refer 'excluded paths' section in [docs/tutorial/CollaborationContext.md](./docs/tutorial/CollaborationContext.md#excluded-paths-a-nameexcluded-pathsa)_ + + +#### Server Url(full path vs relative path) configuration +- `api.server.fullUrl.enabled=true` It will generate full server url in the OpenAPI swagger +- `api.server.fullUrl.enabled=false` It will generate only the contextPath only +- default value is false (Currently only in Azure it is enabled) +[Reference]:(https://springdoc.org/faq.html#_how_is_server_url_generated) + ### Other platforms 1. Navigate to the module of the cloud of interest, for example, ```storage-azure```. Configure ```application.properties``` and optionally ```logback-spring.xml```. Intead of changing these files in the source, you can also provide external files at run time. diff --git a/provider/storage-azure/src/main/resources/application.properties b/provider/storage-azure/src/main/resources/application.properties index b888765d2f786b04b7fce8740850062f72fed340..12fe0bb806200748950d290e0533e1835022624b 100644 --- a/provider/storage-azure/src/main/resources/application.properties +++ b/provider/storage-azure/src/main/resources/application.properties @@ -1,4 +1,4 @@ -# Copyright � Microsoft Corporation +# Copyright � Microsoft Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -126,3 +126,6 @@ azure.pubsub.publish=true #Collaboration context featureflag name:partition specific featureFlag.strategy=dataPartition collaborationFilter.excludedPaths=info,liveness_check,swagger,swagger-ui/swagger-ui.css,swagger-ui/swagger-ui-standalone-preset.js,api-docs,api-docs.yaml,api-docs/swagger-config + +# To enable the full server path url in OpenAPI Swagger +api.server.fullUrl.enabled=${swaggerFullUrlEnabled:true} \ No newline at end of file diff --git a/storage-core/src/main/java/org/opengroup/osdu/storage/swagger/SwaggerConfiguration.java b/storage-core/src/main/java/org/opengroup/osdu/storage/swagger/SwaggerConfiguration.java index a8f4e98f2993c354dd8e279f81f7e20f9e465b9c..028be2f0abef3af733508a4af5ef19838604d915 100644 --- a/storage-core/src/main/java/org/opengroup/osdu/storage/swagger/SwaggerConfiguration.java +++ b/storage-core/src/main/java/org/opengroup/osdu/storage/swagger/SwaggerConfiguration.java @@ -1,65 +1,100 @@ package org.opengroup.osdu.storage.swagger; -import io.swagger.v3.oas.annotations.OpenAPIDefinition; -import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; -import io.swagger.v3.oas.annotations.info.Contact; -import io.swagger.v3.oas.annotations.info.Info; -import io.swagger.v3.oas.annotations.info.License; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; -import io.swagger.v3.oas.annotations.security.SecurityScheme; -import io.swagger.v3.oas.annotations.servers.Server; -import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; import io.swagger.v3.oas.models.media.StringSchema; import io.swagger.v3.oas.models.parameters.Parameter; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.oas.models.servers.Server; +import io.swagger.v3.oas.models.tags.Tag; import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.springdoc.core.customizers.OperationCustomizer; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -@OpenAPIDefinition( - info = @Info( - title = "${api.title}", - description = "${api.description}", - version = "${api.version}", - contact = @Contact(name = "${api.contact.name}", email = "${api.contact.email}"), - license = @License(name = "${api.license.name}", url = "${api.license.url}")), - servers = @Server(url = "${api.server.url}"), - security = @SecurityRequirement(name = "Authorization"), - tags = { - @Tag(name = "records", description = "Records management operations"), - @Tag(name = "query", description = "Querying Records operations"), - @Tag(name = "info", description = "Version info endpoint") - } -) -@SecurityScheme(name = "Authorization", scheme = "bearer", bearerFormat = "Authorization", type = SecuritySchemeType.HTTP) +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + @Configuration @Profile("!noswagger") public class SwaggerConfiguration { - @Bean - public OperationCustomizer customize() { - return (operation, handlerMethod) -> { - Parameter dataPartitionId = new Parameter() - .name(DpsHeaders.DATA_PARTITION_ID) - .description("Tenant Id") - .in("header") - .required(true) - .schema(new StringSchema()); - Parameter frameOfReference = new Parameter() - .name(DpsHeaders.FRAME_OF_REFERENCE) - .description("This value indicates whether normalization applies, should be either " + - "`none` or `units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;`") - .in("header") - .required(true) - .example("units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;") - .schema(new StringSchema()); - Operation currentOperation = operation.addParametersItem(dataPartitionId); - if(currentOperation.getOperationId().equals("fetchRecords")) - currentOperation = currentOperation.addParametersItem(frameOfReference); - return currentOperation; - }; - } -} + @Autowired + private SwaggerConfigurationProperties configurationProperties; + + @Bean + public OpenAPI customOpenAPI() { + + SecurityScheme securityScheme = new SecurityScheme() + .type(SecurityScheme.Type.HTTP) + .scheme("bearer") + .bearerFormat("Authorization") + .in(SecurityScheme.In.HEADER) + .name("Authorization"); + final String securitySchemeName = "Authorization"; + SecurityRequirement securityRequirement = new SecurityRequirement().addList(securitySchemeName); + Components components = new Components().addSecuritySchemes(securitySchemeName, securityScheme); + + OpenAPI openAPI = new OpenAPI() + .addSecurityItem(securityRequirement) + .components(components) + .info(apiInfo()) + .tags(tags()); + + if(configurationProperties.isApiServerFullUrlEnabled()) + return openAPI; + return openAPI + .servers(Arrays.asList(new Server().url(configurationProperties.getApiServerUrl()))); + } + + private List<Tag> tags() { + List<Tag> tags = new ArrayList<>(); + tags.add(new Tag().name("records").description("Records management operations")); + tags.add(new Tag().name("query").description("Querying Records operations")); + tags.add(new Tag().name("info").description("Version info endpoint")); + return tags; + } + + private Info apiInfo() { + return new Info() + .title(configurationProperties.getApiTitle()) + .description(configurationProperties.getApiDescription()) + .version(configurationProperties.getApiVersion()) + .license(new License().name(configurationProperties.getApiLicenseName()).url(configurationProperties.getApiLicenseUrl())) + .contact(new Contact().name(configurationProperties.getApiContactName()).email(configurationProperties.getApiContactEmail())); + } + + @Bean + public OperationCustomizer operationCustomizer() { + return (operation, handlerMethod) -> { + Parameter dataPartitionId = new Parameter() + .name(DpsHeaders.DATA_PARTITION_ID) + .description("Tenant Id") + .in("header") + .required(true) + .schema(new StringSchema()); + Parameter frameOfReference = new Parameter() + .name(DpsHeaders.FRAME_OF_REFERENCE) + .description("This value indicates whether normalization applies, should be either " + + "`none` or `units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;`") + .in("header") + .required(true) + .example("units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;") + .schema(new StringSchema()); + + Operation currentOperation = operation.addParametersItem(dataPartitionId); + if(currentOperation.getOperationId().equals("fetchRecords")) + currentOperation = currentOperation.addParametersItem(frameOfReference); + return currentOperation; + }; + } +} \ No newline at end of file diff --git a/storage-core/src/main/java/org/opengroup/osdu/storage/swagger/SwaggerConfigurationProperties.java b/storage-core/src/main/java/org/opengroup/osdu/storage/swagger/SwaggerConfigurationProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..4975cf9f30a79ab688f35d8a6cae2a2a4468873d --- /dev/null +++ b/storage-core/src/main/java/org/opengroup/osdu/storage/swagger/SwaggerConfigurationProperties.java @@ -0,0 +1,24 @@ +package org.opengroup.osdu.storage.swagger; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Getter +@Setter +@Component +@ConfigurationProperties(prefix = "swagger") +public class SwaggerConfigurationProperties { + + private String apiTitle; + private String apiDescription; + private String apiVersion; + private String apiContactName; + private String apiContactEmail; + private String apiLicenseName; + private String apiLicenseUrl; + private String apiServerUrl; + private boolean apiServerFullUrlEnabled; + +} \ No newline at end of file diff --git a/storage-core/src/main/resources/swagger.properties b/storage-core/src/main/resources/swagger.properties index 7d1e62833a69653ca2176d1d72bf678d84b4cdca..4c4d50b3521f04eaff00f2b4ab85f7f4d690a3c2 100644 --- a/storage-core/src/main/resources/swagger.properties +++ b/storage-core/src/main/resources/swagger.properties @@ -9,14 +9,15 @@ springdoc.swagger-ui.displayOperationId=true springdoc.api-docs.path=/api-docs #OpenAPI 3.0 - Storage properties -api.title=Storage Service -api.description=Storage service which handles the metadata ingestion in the OSDU data platform -api.version=2.0.0 -api.contact.name=OSDU Data Platform Team -api.contact.email=dps@OSDU.org -api.license.name=Apache 2.0 -api.license.url=https://www.apache.org/licenses/LICENSE-2.0.html -api.server.url=${server.servlet.contextPath} +swagger.apiTitle=Storage Service +swagger.apiDescription=Storage service which handles the metadata ingestion in the OSDU data platform +swagger.apiVersion=2.0.0 +swagger.apiContactName=OSDU Data Platform Team +swagger.apiContactEmail=dps@OSDU.org +swagger.apiLicenseName=Apache 2.0 +swagger.apiLicenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html +swagger.apiServerUrl=${server.servlet.contextPath:/api/storage/v2/} +swagger.apiServerFullUrlEnabled=${api.server.fullUrl.enabled:false} #Query API related properties queryApi.getAllRecords.summary=Get all record from kind