-
Notifications
You must be signed in to change notification settings - Fork 35
Synchronize Secret Format and Usage #1620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
94f34a1
716b7ea
e41db50
b24b310
d8bdabc
a13616e
4423c5c
45b8f41
84e19ee
ba1a924
8ab4795
1caa17f
8d9c72b
c8eeac1
9bf5e4c
a03f3e4
ea8a6a4
cef38e4
1609b5f
41c48db
d808230
ee1d73a
a0ca08d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
import java.util.function.Supplier; | ||
import java.util.regex.Pattern; | ||
|
||
import org.opensearch.migrations.arguments.ArgLogUtils; | ||
import org.opensearch.migrations.arguments.ArgNameConstants; | ||
import org.opensearch.migrations.bulkload.common.DefaultSourceRepoAccessor; | ||
import org.opensearch.migrations.bulkload.common.DocumentReindexer; | ||
import org.opensearch.migrations.bulkload.common.FileSystemRepo; | ||
|
@@ -48,7 +50,6 @@ | |
import org.opensearch.migrations.transform.TransformationLoader; | ||
import org.opensearch.migrations.transform.TransformerConfigUtils; | ||
import org.opensearch.migrations.transform.TransformerParams; | ||
import org.opensearch.migrations.utils.ArgLogUtils; | ||
import org.opensearch.migrations.utils.ProcessHelpers; | ||
|
||
import com.beust.jcommander.IStringConverter; | ||
|
@@ -69,8 +70,6 @@ public class RfsMigrateDocuments { | |
public static final int NO_WORK_LEFT_EXIT_CODE = 3; | ||
public static final int TOLERABLE_CLIENT_SERVER_CLOCK_DIFFERENCE_SECONDS = 5; | ||
public static final String LOGGING_MDC_WORKER_ID = "workerId"; | ||
public static final String TARGET_USERNAME_ENV_VAR = "TARGET_USERNAME"; | ||
public static final String TARGET_PASSWORD_ENV_VAR = "TARGET_PASSWORD"; | ||
|
||
// Decrease successor nextAcquisitionLeaseExponent if shard setup takes less than 2.5% of total lease time | ||
// Increase successor nextAcquisitionLeaseExponent if shard setup takes more than 10% of lease total time | ||
|
@@ -265,13 +264,13 @@ private EnvParameters() { | |
|
||
public static void injectFromEnv(Args args) { | ||
List<String> addedEnvParams = new ArrayList<>(); | ||
if (args.targetArgs.username == null && System.getenv(TARGET_USERNAME_ENV_VAR) != null) { | ||
args.targetArgs.username = System.getenv(TARGET_USERNAME_ENV_VAR); | ||
addedEnvParams.add(TARGET_USERNAME_ENV_VAR); | ||
if (args.targetArgs.username == null && System.getenv(ArgNameConstants.TARGET_USERNAME_ENV_ARG) != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you added the env variables BEFORE the JCommander ones, would you need to check for null? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My stance (and what seems like should be expected) has been that command line arguments have priority over environment variables. I think we will get to the point where we are using command line arguments less, and they will be more an override than the norm |
||
args.targetArgs.username = System.getenv(ArgNameConstants.TARGET_USERNAME_ENV_ARG); | ||
addedEnvParams.add(ArgNameConstants.TARGET_USERNAME_ENV_ARG); | ||
} | ||
if (args.targetArgs.password == null && System.getenv(TARGET_PASSWORD_ENV_VAR) != null) { | ||
args.targetArgs.password = System.getenv(TARGET_PASSWORD_ENV_VAR); | ||
addedEnvParams.add(TARGET_PASSWORD_ENV_VAR); | ||
if (args.targetArgs.password == null && System.getenv(ArgNameConstants.TARGET_PASSWORD_ENV_ARG) != null) { | ||
args.targetArgs.password = System.getenv(ArgNameConstants.TARGET_PASSWORD_ENV_ARG); | ||
addedEnvParams.add(ArgNameConstants.TARGET_PASSWORD_ENV_ARG); | ||
} | ||
if (!addedEnvParams.isEmpty()) { | ||
log.info("Adding parameters from the following expected environment variables: {}", addedEnvParams); | ||
|
@@ -312,7 +311,7 @@ public static void validateArgs(Args args) { | |
|
||
public static void main(String[] args) throws Exception { | ||
var workerId = ProcessHelpers.getNodeInstanceName(); | ||
System.err.println("Starting program with: " + String.join(" ", ArgLogUtils.getRedactedArgs(args))); | ||
System.err.println("Starting program with: " + String.join(" ", ArgLogUtils.getRedactedArgs(args, ArgNameConstants.CENSORED_TARGET_ARGS))); | ||
// Ensure that log4j2 doesn't execute shutdown hooks until ours have completed. This means that we need to take | ||
// responsibility for calling `LogManager.shutdown()` in our own shutdown hook.. | ||
System.setProperty("log4j2.shutdownHookEnabled", "false"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.opensearch.migrations.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.opensearch.migrations.MigrateOrEvaluateArgs; | ||
import org.opensearch.migrations.arguments.ArgNameConstants; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class EnvArgs { | ||
|
||
private EnvArgs() { | ||
throw new IllegalStateException("EnvArgs utility class should not instantiated"); | ||
} | ||
|
||
public static void injectFromEnv(MigrateOrEvaluateArgs args) { | ||
List<String> addedEnvParams = new ArrayList<>(); | ||
if (args.sourceArgs.username == null && System.getenv(ArgNameConstants.SOURCE_USERNAME_ENV_ARG) != null) { | ||
args.sourceArgs.username = System.getenv(ArgNameConstants.SOURCE_USERNAME_ENV_ARG); | ||
addedEnvParams.add(ArgNameConstants.SOURCE_USERNAME_ENV_ARG); | ||
} | ||
if (args.sourceArgs.password == null && System.getenv(ArgNameConstants.SOURCE_PASSWORD_ENV_ARG) != null) { | ||
args.sourceArgs.password = System.getenv(ArgNameConstants.SOURCE_PASSWORD_ENV_ARG); | ||
addedEnvParams.add(ArgNameConstants.SOURCE_PASSWORD_ENV_ARG); | ||
} | ||
if (args.targetArgs.username == null && System.getenv(ArgNameConstants.TARGET_USERNAME_ENV_ARG) != null) { | ||
args.targetArgs.username = System.getenv(ArgNameConstants.TARGET_USERNAME_ENV_ARG); | ||
addedEnvParams.add(ArgNameConstants.TARGET_USERNAME_ENV_ARG); | ||
} | ||
if (args.targetArgs.password == null && System.getenv(ArgNameConstants.TARGET_PASSWORD_ENV_ARG) != null) { | ||
args.targetArgs.password = System.getenv(ArgNameConstants.TARGET_PASSWORD_ENV_ARG); | ||
addedEnvParams.add(ArgNameConstants.TARGET_PASSWORD_ENV_ARG); | ||
} | ||
if (!addedEnvParams.isEmpty()) { | ||
log.info("Adding parameters from the following expected environment variables: {}", addedEnvParams); | ||
} | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can wait, but this could be generalized into the solution for https://opensearch.atlassian.net/browse/MIGRATIONS-2634.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that is my intention for the future of this, and had to stop myself a couple times from implementing it, as I'd like this work to focus on using secrets. I'd like to see us create a more generic class that we can use reuse for this work. Ideally it has type checking for converting str to whatever data type and allows us to specify some list of parameters to check in the environment for