Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object Files {
const val storageSftp = "cloudnet-sftp.jar"
const val storageS3 = "cloudnet-s3.jar"
const val influx = "cloudnet-influx.jar"
const val replacer = "cloudnet-replacer.jar"
const val node = "cloudnet.jar"
const val nodeCnl = "cloudnet.cnl"
}
20 changes: 20 additions & 0 deletions modules/replacer/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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.
*/

plugins {
id("cloudnet-publish")
id("cloudnet-modules-api")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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 eu.cloudnetservice.modules.replacer.model;

import eu.cloudnetservice.modules.replacer.model.condition.ConditionRule;
import eu.cloudnetservice.modules.replacer.type.ReplaceType;
import eu.cloudnetservice.modules.replacer.type.SearchType;
import java.util.List;
import org.jetbrains.annotations.Nullable;

public record PlaceholderReplacement(
String token,
@Nullable SearchType searchType,
@Nullable ReplaceType replaceType,
@Nullable List<String> values,
@Nullable List<ConditionRule> conditions
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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 eu.cloudnetservice.modules.replacer.model;

import java.util.List;
import org.jetbrains.annotations.Nullable;

public record Replacement(
@Nullable String id,
@Nullable Boolean enabled,
@Nullable List<TargetDefinition> targets,
@Nullable List<String> files,
@Nullable List<PlaceholderReplacement> placeholders
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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 eu.cloudnetservice.modules.replacer.model;

import org.jetbrains.annotations.Nullable;

public record TargetDefinition(
@Nullable String task,
@Nullable String service,
@Nullable String environment,
@Nullable String group,
@Nullable String template
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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 eu.cloudnetservice.modules.replacer.model.condition;

public record ConditionRule(
ConditionWhen when,
String value
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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 eu.cloudnetservice.modules.replacer.model.condition;

import org.jetbrains.annotations.Nullable;

public record ConditionWhen(
@Nullable String field,
@Nullable String equals,
@Nullable String regex
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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 eu.cloudnetservice.modules.replacer.model.config;

import eu.cloudnetservice.modules.replacer.model.Replacement;
import java.util.List;
import org.jetbrains.annotations.Nullable;

/**
* Container model for a replacement rule file.
*
* @param rules the rules parsed from the file.
*/
public record Replacements(@Nullable List<Replacement> rules) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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 eu.cloudnetservice.modules.replacer.model.config;

import eu.cloudnetservice.modules.replacer.type.ReplaceType;
import eu.cloudnetservice.modules.replacer.type.SearchType;
import java.util.List;

public record Replacer(
boolean builtInPlaceholdersEnabled,
DefaultSection defaults,
PathSection paths,
LimitSection limits
) {

public record DefaultSection(SearchType searchType, ReplaceType replaceType) {
}

public record PathSection(List<String> filePatterns) {
}

public record LimitSection(long maxFileSizeBytes) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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 eu.cloudnetservice.modules.replacer.type;

/**
* Determines how a replacement value is chosen for a placeholder occurrence.
*/
public enum ReplaceType {
/**
* Always use the first value in the list.
*/
FIRST,

/**
* Pick a random value for each occurrence.
*/
RANDOM,

/**
* Cycle through the values in order (wrap-around).
*/
SEQUENTIAL,

/**
* Choose a value based on matching condition rules.
*/
CONDITIONAL
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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 eu.cloudnetservice.modules.replacer.type;

/**
* Controls how many placeholder occurrences are replaced in a document.
*/
public enum SearchType {
/**
* Replace every occurrence of the token.
*/
ALL,

/**
* Replace only the first occurrence of the token.
*/
FIRST
}
47 changes: 47 additions & 0 deletions modules/replacer/impl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2019-present CloudNetService team & contributors
*
* 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.
*/

import eu.cloudnetservice.cloudnet.gradle.util.Files

plugins {
id("cloudnet-modules")
id("cloudnet-publish")
alias(libs.plugins.shadow)
}

dependencies {
compileOnlyApi(projects.node.nodeImpl)
compileOnlyApi(projects.driver.driverImpl)
compileOnlyApi(projects.utils.utilsBase)

api(projects.modules.replacer.replacerApi)

testImplementation(libs.mockito)
testImplementation(libs.bundles.junit)
testRuntimeOnly(libs.junitLauncher)
testImplementation(projects.driver.driverApi)
}

tasks.shadowJar {
archiveFileName = Files.replacer
}

moduleJson {
author = "CloudNetService"
name = "CloudNet-Replacer"
main = "eu.cloudnetservice.modules.replacer.ReplacerModule"
description = "Replaces configured placeholders in service files after templates/inclusions are applied"
}
Loading