Skip to content

Commit

Permalink
Merge branch 'release/0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
clivebor committed Jan 24, 2022
2 parents 137231a + 4dd419f commit 2b6d403
Show file tree
Hide file tree
Showing 370 changed files with 54,124 additions and 18,794 deletions.
2 changes: 1 addition & 1 deletion ahoy-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ARG JAR_FILE
ADD ${JAR_FILE} app.jar

# setup environment
ENV SPRING_PROFILES=prod
ENV SPRING_PROFILES=prod,keycloak
EXPOSE 8080

ENTRYPOINT ["sh","-c","java -Dspring.profiles.active=$SPRING_PROFILES -jar app.jar", "--spring.config.location=/tmp/config/"]
14 changes: 12 additions & 2 deletions ahoy-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>za.co.lsd.ahoy</groupId>
<artifactId>ahoy</artifactId>
<version>0.8.0</version>
<version>0.9.0</version>
</parent>
<artifactId>ahoy-server</artifactId>

Expand Down Expand Up @@ -79,7 +79,7 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<version>4.9.0</version>
<version>4.13.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down Expand Up @@ -117,6 +117,11 @@
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand All @@ -132,6 +137,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ResponseEntity<EnvironmentRelease> copyEnvConfig(@PathVariable Environmen
}

@PostMapping("/releaseVersions/{releaseVersionId}/copyAppEnvConfig")
public ResponseEntity<EnvironmentRelease> copyApplicationVersionEnvConfig(@PathVariable Long releaseVersionId,
public ResponseEntity<Void> copyApplicationVersionEnvConfig(@PathVariable Long releaseVersionId,
@RequestParam Long sourceApplicationVersionId,
@RequestParam Long destApplicationVersionId) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import za.co.lsd.ahoy.server.security.Role;
import za.co.lsd.ahoy.server.security.Scope;

@Configuration
@EnableWebSecurity
Expand All @@ -50,8 +51,8 @@ protected void configure(HttpSecurity http) throws Exception {
.regexMatchers(HttpMethod.GET,"/data/applicationVersions/.*projection=.*Full").hasAnyAuthority(Role.admin, Role.releasemanager, Role.developer)
.regexMatchers(HttpMethod.GET,"/data/applicationEnvironmentConfigs/.*projection=.*Full").hasAnyAuthority(Role.admin, Role.releasemanager, Role.developer)
.regexMatchers(HttpMethod.GET,"/data/.*projection=.*Full").hasAuthority(Role.admin)
.antMatchers("/data/**").hasAuthority("SCOPE_ahoy")
.antMatchers("/api/**").hasAuthority("SCOPE_ahoy")
.antMatchers("/data/**").hasAuthority(Scope.ahoy)
.antMatchers("/api/**").hasAuthority(Scope.ahoy)
.anyRequest().authenticated()
.and()
.oauth2ResourceServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.messaging.MessageSecurityMetadataSourceRegistry;
import org.springframework.security.config.annotation.web.socket.AbstractSecurityWebSocketMessageBrokerConfigurer;
import za.co.lsd.ahoy.server.security.Scope;

@Configuration
public class WebSocketSecurityConfiguration extends AbstractSecurityWebSocketMessageBrokerConfigurer {

@Override
protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
messages
.simpDestMatchers("/user/events/**").hasAuthority("SCOPE_ahoy")
.simpDestMatchers("/events/**").hasAuthority("SCOPE_ahoy")
.simpDestMatchers("/user/events/**").hasAuthority(Scope.ahoy)
.simpDestMatchers("/events/**").hasAuthority(Scope.ahoy)
.anyMessage().authenticated();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 LSD Information Technology (Pty) Ltd
* Copyright 2022 LSD Information Technology (Pty) Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,7 @@
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

import static com.fasterxml.jackson.annotation.JsonProperty.Access.*;

Expand Down Expand Up @@ -86,4 +87,17 @@ public boolean hasSecrets() {
public ApplicationSpec summarySpec() {
return new ApplicationSpec(spec.getImage(), spec.getDockerRegistryName());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ApplicationVersion that = (ApplicationVersion) o;
return id.equals(that.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 LSD Information Technology (Pty) Ltd
* Copyright 2022 LSD Information Technology (Pty) Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,7 +50,7 @@ public void createNamespace(String name) {

try (DefaultOpenShiftClient openShiftClient = new DefaultOpenShiftClient(config)) {

if (openShiftClient.projects().withName(name).get() != null) {
if (openShiftClient.projects().withName(name).get() == null) {
openShiftClient.projects().createOrReplaceWithNew()
.withNewMetadata()
.withName(name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 LSD Information Technology (Pty) Ltd
* Copyright 2022 LSD Information Technology (Pty) Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,7 +97,9 @@ public void writeTemplates(EnvironmentRelease environmentRelease, ReleaseVersion
applicationVersion.getSpec().getServicePorts().size() > 0) {
addTemplate(application, "service", templatesPath, trackedTemplates);

if (applicationEnvironmentConfig != null && applicationEnvironmentConfig.getSpec().getRouteHostname() != null && applicationEnvironmentConfig.getSpec().getRouteTargetPort() != null) {
if (applicationEnvironmentConfig != null &&
applicationEnvironmentConfig.getSpec().getRouteHostname() != null && !applicationEnvironmentConfig.getSpec().getRouteHostname().trim().isEmpty() &&
applicationEnvironmentConfig.getSpec().getRouteTargetPort() != null) {
addTemplate(application, "ingress", templatesPath, trackedTemplates);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2022 LSD Information Technology (Pty) Ltd
*
* 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 za.co.lsd.ahoy.server.helm.values;

import org.apache.commons.text.StringSubstitutor;
import org.springframework.stereotype.Component;
import za.co.lsd.ahoy.server.applications.Application;
import za.co.lsd.ahoy.server.environmentrelease.EnvironmentRelease;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Component
public class RouteHostnameResolver {

public String resolve(EnvironmentRelease environmentRelease, Application application, String routeHostname) {
if (routeHostname == null)
return null;

Objects.requireNonNull(environmentRelease, "environmentRelease is required");
Objects.requireNonNull(application, "application is required");

Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("cluster_host", environmentRelease.getEnvironment().getCluster().getHost());
valuesMap.put("environment_name", environmentRelease.getEnvironment().getName());
valuesMap.put("release_name", environmentRelease.getRelease().getName());
valuesMap.put("application_name", application.getName());

StringSubstitutor stringSubstitutor = new StringSubstitutor(valuesMap);
stringSubstitutor.setEnableUndefinedVariableException(true);

try {
return stringSubstitutor.replace(routeHostname);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Failed to resolve route hostname for " +
application.getName() +
": " + routeHostname +
", reason: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 LSD Information Technology (Pty) Ltd
* Copyright 2022 LSD Information Technology (Pty) Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,17 +47,20 @@ public class ValuesBuilder {
private final DockerConfigSealedSecretProducer dockerConfigSealedSecretProducer;
private final SecretDataSealedSecretProducer secretDataSealedSecretProducer;
private final ObjectMapper objectMapper;
private RouteHostnameResolver routeHostnameResolver;

public ValuesBuilder(DockerRegistryProvider dockerRegistryProvider,
ApplicationEnvironmentConfigProvider environmentConfigProvider,
DockerConfigSealedSecretProducer dockerConfigSealedSecretProducer,
SecretDataSealedSecretProducer secretDataSealedSecretProducer,
ObjectMapper objectMapper) {
ObjectMapper objectMapper,
RouteHostnameResolver routeHostnameResolver) {
this.dockerRegistryProvider = dockerRegistryProvider;
this.environmentConfigProvider = environmentConfigProvider;
this.dockerConfigSealedSecretProducer = dockerConfigSealedSecretProducer;
this.secretDataSealedSecretProducer = secretDataSealedSecretProducer;
this.objectMapper = objectMapper;
this.routeHostnameResolver = routeHostnameResolver;
}

public Values build(EnvironmentRelease environmentRelease, ReleaseVersion releaseVersion) throws IOException {
Expand All @@ -76,7 +79,7 @@ public Values build(EnvironmentRelease environmentRelease, ReleaseVersion releas
ApplicationEnvironmentConfig applicationEnvironmentConfig =
environmentConfigProvider.environmentConfigFor(environmentRelease, releaseVersion, applicationVersion)
.orElse(null);
apps.put(HelmUtils.valuesName(application), buildApplication(applicationVersion, applicationEnvironmentConfig));
apps.put(HelmUtils.valuesName(application), buildApplication(environmentRelease, applicationVersion, applicationEnvironmentConfig));

log.debug("Added values for application '{}' in environment '{}'", application.getName(), environment.getName());
}
Expand All @@ -85,7 +88,7 @@ public Values build(EnvironmentRelease environmentRelease, ReleaseVersion releas
return valuesBuilder.build();
}

public ApplicationValues buildApplication(ApplicationVersion applicationVersion, ApplicationEnvironmentConfig environmentConfig) throws IOException {
public ApplicationValues buildApplication(EnvironmentRelease environmentRelease, ApplicationVersion applicationVersion, ApplicationEnvironmentConfig environmentConfig) throws IOException {
ApplicationSpec spec = applicationVersion.getSpec();
ApplicationValues.ApplicationValuesBuilder builder = ApplicationValues.builder()
.name(applicationVersion.getApplication().getName())
Expand Down Expand Up @@ -162,7 +165,7 @@ public ApplicationValues buildApplication(ApplicationVersion applicationVersion,

builder
.replicas(environmentSpec.getReplicas() != null ? environmentSpec.getReplicas() : 1)
.routeHostname(environmentSpec.getRouteHostname())
.routeHostname(routeHostnameResolver.resolve(environmentRelease, applicationVersion.getApplication(), environmentSpec.getRouteHostname()))
.routeTargetPort(environmentSpec.getRouteTargetPort())
.tls(environmentSpec.isTls())
.tlsSecretName(environmentSpec.getTlsSecretName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 LSD Information Technology (Pty) Ltd
* Copyright 2022 LSD Information Technology (Pty) Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Entity
Expand All @@ -48,7 +49,7 @@ public class Release implements Serializable {
@OneToMany(mappedBy = "release", cascade = CascadeType.REMOVE)
@JsonIgnore
@OrderBy("id")
private List<ReleaseVersion> releaseVersions;
private List<ReleaseVersion> releaseVersions = new ArrayList<>();

public ReleaseVersion latestReleaseVersion() {
if (releaseVersions != null && releaseVersions.size() > 0) {
Expand All @@ -66,6 +67,11 @@ public Release(Long id, @NotNull String name) {
this.name = name;
}

public void addReleaseVersion(ReleaseVersion releaseVersion) {
releaseVersions.add(releaseVersion);
releaseVersion.setRelease(this);
}

@Override
public String toString() {
return "Release{" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package za.co.lsd.ahoy.server.security;

public final class Scope {
public static final String ahoy = "SCOPE_ahoy";

private Scope() {
}
}
Loading

0 comments on commit 2b6d403

Please sign in to comment.