Skip to content

Commit

Permalink
Complete operator functionality (#235)
Browse files Browse the repository at this point in the history
* Make the operator work

Signed-off-by: carlosthe19916 <[email protected]>

* Upgrade xbuilder version

Signed-off-by: carlosthe19916 <[email protected]>

* Upgrade xbuilder version

Signed-off-by: carlosthe19916 <[email protected]>

Signed-off-by: carlosthe19916 <[email protected]>
  • Loading branch information
carlosthe19916 authored Dec 22, 2022
1 parent bc6997a commit 6151d9a
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 61 deletions.
2 changes: 1 addition & 1 deletion application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<dependency>
<groupId>io.github.project-openubl</groupId>
<artifactId>quarkus-xbuilder</artifactId>
<version>2.0.0.Beta2</version>
<version>2.0.0-Beta4</version>
</dependency>
<dependency>
<groupId>io.github.project-openubl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,32 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Optional;

@ApplicationScoped
@StorageProvider(StorageProvider.Type.S3)
public class S3ReadinessCheck implements StorageReadinessCheck {

@ConfigProperty(name = "openubl.storage.s3.health.url")
String s3HostHealthCheckUrl;
Optional<String> s3HostHealthCheckUrl;

private final HttpClient client = HttpClient.newHttpClient();

@Override
public boolean isHealthy() {
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(s3HostHealthCheckUrl))
.GET()
.build();
HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding());
return response.statusCode() == 200;
} catch (URISyntaxException | IOException | InterruptedException e) {
return false;
if (s3HostHealthCheckUrl.isPresent()) {
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(s3HostHealthCheckUrl.get()))
.GET()
.build();
HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding());
return response.statusCode() == 200;
} catch (URISyntaxException | IOException | InterruptedException e) {
return false;
}
} else {
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class TsidUtil {

@ConfigProperty(name = "ublhub.tsid.bytes")
@ConfigProperty(name = "openubl.ublhub.tsid.bytes")
int tsidBytes;

@Produces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@ApplicationScoped
public class SchedulerManager {

@ConfigProperty(name = "openubl.scheduler.type")
@ConfigProperty(name = "openubl.ublhub.scheduler.type")
String schedulerType;

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@ApplicationScoped
public class DisabledAuthController extends AuthorizationController {

@ConfigProperty(name = "ublhub.disable.authorization")
@ConfigProperty(name = "openubl.ublhub.disable.authorization")
boolean disableAuthorization;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class GeneratedIDGenerator implements IDGenerator {
public static final String SERIE_PROPERTY = "serie";
public static final String NUMERO_PROPERTY = "numero";

@ConfigProperty(name = "openubl.xbuilder.timezone")
@ConfigProperty(name = "openubl.ublhub.timezone")
String timezone;

@Inject
Expand Down
14 changes: 8 additions & 6 deletions application/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Resources
quarkus.native.resources.includes=schemas/*.json

# For Key generation
quarkus.security.security-providers=BC

# Resteasy
quarkus.resteasy-reactive.path=/api

Expand Down Expand Up @@ -141,20 +144,19 @@ quarkus.smallrye-openapi.info-license-url=https://www.apache.org/licenses/LICENS
quarkus.smallrye-openapi.store-schema-directory=src/jreleaser/templates/article

# XBuilder
openubl.scheduler.type=vertx
openubl.xbuilder.timezone=America/Lima

quarkus.xbuilder.moneda=PEN
quarkus.xbuilder.unidad-medida=NIU
quarkus.xbuilder.igv-tasa=0.18
quarkus.xbuilder.icb-tasa=0.2
quarkus.xbuilder.icb-tasa=0.3

# XSender
quarkus.xsender.enable-logging-feature=false

# Ublhub
ublhub.disable.authorization=true
ublhub.tsid.bytes=256
openubl.ublhub.timezone=America/Lima
openubl.ublhub.scheduler.type=vertx
openubl.ublhub.disable.authorization=true
openubl.ublhub.tsid.bytes=256

# Profiles
%basic.ublhub.disable.authorization=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package io.github.project.openubl.operator;

import io.github.project.openubl.operator.cdrs.v2alpha1.UblhubSpec;

import java.util.Map;

public class Constants {
Expand Down Expand Up @@ -44,6 +46,7 @@ public class Constants {
public static final String INGRESS_SUFFIX = "-" + UBLHUB_NAME + "-ingress";
public static final String SECRET_SUFFIX = "-" + UBLHUB_NAME + "-secret";
public static final String DEPLOYMENT_SUFFIX = "-" + UBLHUB_NAME + "-deployment";
public static final String PVC_SUFFIX = "-" + UBLHUB_NAME + "-pvc";

public static final String BASIC_AUTH_SECRET_SUFFIX = "-basic-auth";

Expand All @@ -56,6 +59,14 @@ public class Constants {


public static final String CERTIFICATES_FOLDER = "/mnt/certificates";
public static final String WORKSPACES_FOLDER = "/mnt/workspace";
public static final String STORAGE_FOLDER = "/mnt/ublhub-storage";

public static final UblhubSpec.XBuilderSpec defaultXBuilderConfig = UblhubSpec.XBuilderSpec.builder()
.moneda("PEN")
.igvTasa("0.18")
.icbTasa("0.4")
.build();
public static final UblhubSpec.XSenderSpec defaultXSenderConfig = UblhubSpec.XSenderSpec.builder()
.enableLoggingFeature(false)
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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 io.github.project.openubl.operator.cdrs.v2alpha1;

import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpecBuilder;
import io.fabric8.kubernetes.api.model.Quantity;
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder;
import io.github.project.openubl.operator.Constants;
import io.github.project.openubl.operator.utils.CRDUtils;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource;

import java.util.Map;

public class UblhubFileStoragePVC extends CRUDKubernetesDependentResource<PersistentVolumeClaim, Ublhub> {

public UblhubFileStoragePVC() {
super(PersistentVolumeClaim.class);
}

@Override
public PersistentVolumeClaim desired(Ublhub cr, Context context) {
return newPersistentVolumeClaim(cr, context);
}

@SuppressWarnings("unchecked")
private PersistentVolumeClaim newPersistentVolumeClaim(Ublhub cr, Context context) {
final var labels = (Map<String, String>) context.managedDependentResourceContext()
.getMandatory(Constants.CONTEXT_LABELS_KEY, Map.class);

PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder()
.withNewMetadata()
.withName(getPersistentVolumeClaimName(cr))
.withNamespace(cr.getMetadata().getNamespace())
.withLabels(labels)
.endMetadata()
.withSpec(getPersistentVolumeClaimSpec(cr))
.build();
return pvc;
}

private PersistentVolumeClaimSpec getPersistentVolumeClaimSpec(Ublhub cr) {
return new PersistentVolumeClaimSpecBuilder()
.withAccessModes("ReadWriteOnce")
.withResources(new ResourceRequirementsBuilder()
.addToRequests("storage", new Quantity(cr.getSpec().getStorageSpec().getFilesystemSpec().getSize()))
.build()
)
.build();
}

public static String getPersistentVolumeClaimName(Ublhub cr) {
return cr.getMetadata().getName() + "-filesystem" + Constants.PVC_SUFFIX;
}

public static boolean isTlsConfigured(Ublhub cr) {
var tlsSecret = CRDUtils.getValueFromSubSpec(cr.getSpec().getHttpSpec(), UblhubSpec.HttpSpec::getTlsSecret);
return tlsSecret.isPresent() && !tlsSecret.get().trim().isEmpty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@ public class UblhubSpec {
@JsonPropertyDescription("In this section you can configure Oidc settings.")
private OidcSpec oidcSpec;

@JsonProperty("sunat")
@JsonPropertyDescription("In this section you can configure SUNAT settings.")
private SunatSpec sunatSpec;
@JsonProperty("storage")
@JsonPropertyDescription("In this section you can configure the Storage.")
private StorageSpec storageSpec;

@JsonProperty("xbuilder")
@JsonPropertyDescription("XBuilder settings.")
private XBuilderSpec xBuilderSpec;

@JsonProperty("xsender")
@JsonPropertyDescription("XSender settings.")
private XSenderSpec xSenderSpec;

@Data
@Builder
Expand Down Expand Up @@ -152,12 +160,78 @@ public static class OidcSpec {
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class SunatSpec {
@JsonPropertyDescription("Padron Reducido Url.")
private String padronReducidoUrl;
public static class StorageSpec {
public enum Type {
filesystem,
s3
}

@JsonPropertyDescription("Typo of chosen storage.")
private Type type;

@JsonProperty("filesystem")
@JsonPropertyDescription("Filesystem settings.")
private StorageFilesystemSpec filesystemSpec;

@JsonProperty("s3")
@JsonPropertyDescription("Filesystem settings.")
private StorageS3Spec s3Spec;
}

@JsonPropertyDescription("Cron for downloading the Padron Reducido.")
private String padronReducidoCron;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class StorageFilesystemSpec {
@JsonPropertyDescription("Size of the PVC to create.")
private String size;
}

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class StorageS3Spec {
@JsonPropertyDescription("Only if you are using Minio, otherwise leave it empty")
private String host;

@JsonPropertyDescription("Only if you are using Minio, otherwise leave it empty")
private String healthUrl;

@JsonPropertyDescription("Region")
private String region;

@JsonPropertyDescription("Bucket")
private String bucket;

@JsonPropertyDescription("Access key id")
private String accessKeyId;

@JsonPropertyDescription("Secret access key")
private String secretAccessKey;
}

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class XBuilderSpec {
@JsonPropertyDescription("Default currency")
private String moneda = "PEN";

@JsonPropertyDescription("Default IGV")
private String igvTasa;

@JsonPropertyDescription("Default ICB")
private String icbTasa;
}

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class XSenderSpec {
@JsonPropertyDescription("Enable logging feature")
private Boolean enableLoggingFeature = false;
}
}
Loading

0 comments on commit 6151d9a

Please sign in to comment.