Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:italiangrid/storm-webdav into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
enricovianello committed Jun 21, 2023
2 parents cfdf68b + 9f04806 commit 0e77a05
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 2 deletions.
4 changes: 4 additions & 0 deletions etc/systemd/system/storm-webdav.service.d/storm-webdav.conf
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,7 @@ Environment="STORM_WEBDAV_TPC_MAX_CONNECTIONS_PER_ROUTE=25"
# Default: false
# Set to 'true' if you want to enable HTTP/2 (and remember to enable conscrypt too!)
# Environment="STORM_WEBDAV_ENABLE_HTTP2=false"

# Source file for the tape REST API well-known endpoint
# Default: '/etc/storm/webdav/wlcg-tape-rest-api.json'
# Environment="STORM_WEBDAV_TAPE_WELLKNOWN_SOURCE=/etc/storm/webdav/wlcg-tape-rest-api.json"
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,35 @@
@Validated
public class ServiceConfigurationProperties implements ServiceConfiguration {

@Validated
public static class TapeProperties {

@Validated
public static class TapeWellKnownProperties {

@NotEmpty
String source;

public String getSource() {
return source;
}

public void setSource(String source) {
this.source = source;
}
}

TapeWellKnownProperties wellKnown;

public TapeWellKnownProperties getWellKnown() {
return wellKnown;
}

public void setWellKnown(TapeWellKnownProperties wellKnown) {
this.wellKnown = wellKnown;
}
}

public enum ChecksumStrategy {
NO_CHECKSUM, EARLY, LATE
}
Expand Down Expand Up @@ -590,6 +619,8 @@ public void setTrustStore(VOMSTrustStoreProperties trustStore) {

private RedirectorProperties redirector;

private TapeProperties tape;

@NotEmpty
private List<String> hostnames;

Expand Down Expand Up @@ -846,4 +877,14 @@ public void setRedirector(RedirectorProperties redirector) {
public String getTlsProtocol() {
return getTls().getProtocol();
}


public TapeProperties getTape() {
return tape;
}


public void setTape(TapeProperties tape) {
this.tape = tape;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ SecurityFilterChain filterChain(HttpSecurity http, VOMSAuthenticationProvider vo

http.authorizeRequests()
.antMatchers(HttpMethod.GET, "/.well-known/oauth-authorization-server",
"/.well-known/openid-configuration")
"/.well-known/openid-configuration", "/.well-known/wlcg-tape-rest-api")
.permitAll();

AccessDeniedHandlerImpl handler = new AccessDeniedHandlerImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023.
*
* 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 org.italiangrid.storm.webdav.tape;

import static org.springframework.http.HttpStatus.NOT_FOUND;

import org.italiangrid.storm.webdav.tape.model.WlcgTapeRestApi;
import org.italiangrid.storm.webdav.tape.service.WlcgTapeRestApiService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

@RestController
public class WlcgTapeRestApiController {

private final WlcgTapeRestApiService service;

public WlcgTapeRestApiController(WlcgTapeRestApiService service) {
this.service = service;
}

@GetMapping({".well-known/wlcg-tape-rest-api"})
public WlcgTapeRestApi getMetadata() {

WlcgTapeRestApi metadata = service.getMetadata();
if (metadata == null) {
throw new ResponseStatusException(NOT_FOUND, "Unable to find resource");
}
return metadata;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023.
*
* 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 org.italiangrid.storm.webdav.tape.model;

import java.util.List;

import com.google.common.collect.Lists;

public class WlcgTapeRestApi {

private String sitename;
private String description;
private List<WlcgTapeRestApiEndpoint> endpoints = Lists.newArrayList();

public String getSitename() {
return sitename;
}

public void setSitename(String sitename) {
this.sitename = sitename;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public List<WlcgTapeRestApiEndpoint> getEndpoints() {
return endpoints;
}

public void setEndpoints(List<WlcgTapeRestApiEndpoint> endpoints) {
this.endpoints = endpoints;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023.
*
* 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 org.italiangrid.storm.webdav.tape.model;

import java.net.URI;
import java.util.Map;

public class WlcgTapeRestApiEndpoint {

private URI uri;
private String version;
private Map<String, String> metadata;

public URI getUri() {
return uri;
}

public void setUri(URI uri) {
this.uri = uri;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public Map<String, String> getMetadata() {
return metadata;
}

public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023.
*
* 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 org.italiangrid.storm.webdav.tape.service;

import java.io.File;
import java.io.IOException;

import org.italiangrid.storm.webdav.config.ServiceConfigurationProperties;
import org.italiangrid.storm.webdav.tape.model.WlcgTapeRestApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;

@Component
public class WlcgTapeRestApiService {

public static final Logger LOG = LoggerFactory.getLogger(WlcgTapeRestApiService.class);

private static final String LOG_INFO_LOADING = "Loading WLCG Tape REST API well-known endpoint from file '{}' ...";
private static final String LOG_ERROR_PREFIX = "Error loading WLCG Tape REST API well-known endpoint from file: {}";
private static final String LOG_INFO_NOFILEFOUND = "No WLCG Tape REST API well-known file found at '{}'";

private WlcgTapeRestApi metadata;

public WlcgTapeRestApiService(ServiceConfigurationProperties props) {

metadata = null;
File source = new File(props.getTape().getWellKnown().getSource());
if (source.exists()) {
LOG.info(LOG_INFO_LOADING, source);
try {
metadata = (new ObjectMapper()).readValue(source, WlcgTapeRestApi.class);
} catch (IOException e) {
LOG.error(LOG_ERROR_PREFIX, e.getMessage());
}
} else {
LOG.info(LOG_INFO_NOFILEFOUND, source);
}
}

public WlcgTapeRestApi getMetadata() {
return metadata;
}

}
5 changes: 4 additions & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ storm:
enabled: true
voms:
trust-store:
dir: src/test/resources/vomsdir
dir: src/test/resources/vomsdir
tape:
well-known:
source: src/test/resources/well-known/wlcg-tape-rest-api.json
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,7 @@ storm:
cache:
enabled: ${STORM_WEBDAV_VOMS_CACHE_ENABLE:true}
entry-lifetime-sec: ${STORM_WEBDAV_VOMS_CACHE_ENTRY_LIFETIME_SEC:300}

tape:
well-known:
source: ${STORM_WEBDAV_TAPE_WELLKNOWN_SOURCE:/etc/storm/webdav/wlcg-tape-rest-api.json}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023.
*
* 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 org.italiangrid.storm.webdav.test.tape;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.test.context.support.WithAnonymousUser;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

@RunWith(SpringRunner.class)
@AutoConfigureMockMvc
@ActiveProfiles({"dev"})
@SpringBootTest(properties = { "storm.tape.well-known.source=not-a-file" })
@WithAnonymousUser
class DisabledEndpointTest {

@Autowired
MockMvc mvc;

@Test
void testDisabledWellKnown() throws Exception {
mvc.perform(get("/.well-known/wlcg-tape-rest-api"))
.andExpect(status().isNotFound());
}
}
Loading

0 comments on commit 0e77a05

Please sign in to comment.