-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:italiangrid/storm-webdav into de…
…velop
- Loading branch information
Showing
14 changed files
with
440 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/org/italiangrid/storm/webdav/tape/WlcgTapeRestApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/org/italiangrid/storm/webdav/tape/model/WlcgTapeRestApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/org/italiangrid/storm/webdav/tape/model/WlcgTapeRestApiEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/org/italiangrid/storm/webdav/tape/service/WlcgTapeRestApiService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/org/italiangrid/storm/webdav/test/tape/DisabledEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
Oops, something went wrong.