Feature/mirror (#1683)

Add mirror command and extension points.

Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
Co-authored-by: Sebastian Sdorra <sebastian.sdorra@cloudogu.com>
Co-authored-by: Konstantin Schaper <konstantin.schaper@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2021-06-04 14:05:47 +02:00
committed by GitHub
parent e55ba52ace
commit dd0975b49a
111 changed files with 6018 additions and 796 deletions

View File

@@ -0,0 +1,44 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.api.v2.resources;
import sonia.scm.repository.NamespaceAndName;
import javax.inject.Inject;
public class DefaultRepositoryLinkProvider implements RepositoryLinkProvider {
private final ResourceLinks resourceLinks;
@Inject
public DefaultRepositoryLinkProvider(ResourceLinks resourceLinks) {
this.resourceLinks = resourceLinks;
}
@Override
public String get(NamespaceAndName namespaceAndName) {
return resourceLinks.repository().self(namespaceAndName.getNamespace(), namespaceAndName.getName());
}
}

View File

@@ -42,6 +42,8 @@ import sonia.scm.Undecorated;
import sonia.scm.api.rest.ObjectMapperProvider;
import sonia.scm.api.v2.resources.BranchLinkProvider;
import sonia.scm.api.v2.resources.DefaultBranchLinkProvider;
import sonia.scm.api.v2.resources.DefaultRepositoryLinkProvider;
import sonia.scm.api.v2.resources.RepositoryLinkProvider;
import sonia.scm.cache.CacheManager;
import sonia.scm.cache.GuavaCacheManager;
import sonia.scm.config.ScmConfiguration;
@@ -263,6 +265,7 @@ class ScmServletModule extends ServletModule {
// bind api link provider
bind(BranchLinkProvider.class).to(DefaultBranchLinkProvider.class);
bind(RepositoryLinkProvider.class).to(DefaultRepositoryLinkProvider.class);
// bind url helper
bind(RootURL.class).to(DefaultRootURL.class);

View File

@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
import sonia.scm.repository.Person;
import sonia.scm.security.PublicKey;
import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -55,7 +56,7 @@ public class DefaultPublicKey implements PublicKey {
private final String raw;
private final Set<Person> contacts;
public DefaultPublicKey(String id, String owner, String raw, Set<Person> contacts) {
public DefaultPublicKey(String id, @Nullable String owner, String raw, Set<Person> contacts) {
this.id = id;
this.owner = owner;
this.raw = raw;
@@ -67,6 +68,12 @@ public class DefaultPublicKey implements PublicKey {
return id;
}
@Override
public Set<String> getSubkeys() {
Keys keys = Keys.resolve(raw);
return keys.getSubs();
}
@Override
public Optional<String> getOwner() {
if (owner == null) {

View File

@@ -0,0 +1,47 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.security.gpg;
import sonia.scm.security.NotPublicKeyException;
import sonia.scm.security.PublicKey;
import sonia.scm.security.PublicKeyParser;
import java.util.Collections;
import static sonia.scm.ContextEntry.ContextBuilder.noContext;
public class DefaultPublicKeyParser implements PublicKeyParser {
@Override
public PublicKey parse(String raw) {
if (!raw.contains("PUBLIC KEY")) {
throw new NotPublicKeyException(noContext(), "The provided key is not a public key");
}
Keys keys = Keys.resolve(raw);
String master = keys.getMaster();
return new DefaultPublicKey(master, null, raw, Collections.emptySet());
}
}

View File

@@ -27,11 +27,13 @@ package sonia.scm.security.gpg;
import com.google.inject.AbstractModule;
import sonia.scm.plugin.Extension;
import sonia.scm.security.GPG;
import sonia.scm.security.PublicKeyParser;
@Extension
public class GPGModule extends AbstractModule {
@Override
protected void configure() {
bind(GPG.class).to(DefaultGPG.class);
bind(PublicKeyParser.class).to(DefaultPublicKeyParser.class);
}
}