Skip to content

Commit

Permalink
Simplify Config (#626)
Browse files Browse the repository at this point in the history
- Merge two internal config implementations into one
  • Loading branch information
pawelprazak committed Jun 26, 2023
1 parent c2bdb0b commit 2d9f436
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 339 deletions.
13 changes: 10 additions & 3 deletions sdk/java/pulumi/src/main/java/com/pulumi/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.pulumi.core.Output;
import com.pulumi.core.TypeShape;
import com.pulumi.core.internal.annotations.InternalUse;
import com.pulumi.internal.ConfigInternal;
import com.pulumi.deployment.Deployment;

import java.io.Reader;
import java.util.Optional;
Expand All @@ -14,7 +14,6 @@
* of configuration variables, indexed by simple keys, and each has a name that uniquely
* identifies it; two bags with different names do not share values for variables that
* otherwise share the same key.
* <p/>
* For example, a bag whose name is {@code pulumi:foo}, with keys
* {@code a}, {@code b}, and {@code c}, is entirely separate from a bag whose name is
* {@code pulumi:bar} with the same simple key names. Each key has a fully qualified names,
Expand All @@ -23,6 +22,14 @@
*/
public interface Config {

/**
* Get a copy of {@code this} {@link Config} with a different name (namespace prefix)
*
* @param name the config namespace name
* @return a new Config with the given name
*/
Config withName(String name);

/**
* For internal use by providers.
*
Expand All @@ -34,7 +41,7 @@ public interface Config {
@InternalUse
@Deprecated
static Config of(String name) {
return ConfigInternal.of(name);
return Deployment.getInstance().getConfig().withName(name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,26 @@
import com.pulumi.core.internal.annotations.InternalUse;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Function;

import static java.util.Objects.requireNonNull;

@InternalUse
@ParametersAreNonnullByDefault
public class ConfigContextInternal implements ConfigContext {

private final String projectName;
private final Function<String, Config> configFactory;
private final Config config;

public ConfigContextInternal(String projectName, Function<String, Config> configFactory) {
this.projectName = requireNonNull(projectName);
this.configFactory = requireNonNull(configFactory);
public ConfigContextInternal(Config config) {
this.config = requireNonNull(config);
}

@Override
public Config config() {
return this.configFactory.apply(this.projectName);
return this.config;
}

@Override
public Config config(String name) {
return this.configFactory.apply(name);
return this.config.withName(name);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.pulumi.deployment;


import com.pulumi.core.internal.annotations.InternalUse;
import com.pulumi.deployment.internal.Config;
import com.pulumi.internal.ConfigInternal;

public interface DeploymentInstance extends Deployment {
@InternalUse
Config getConfig();
ConfigInternal getConfig();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.pulumi.exceptions.LogException;
import com.pulumi.exceptions.ResourceException;
import com.pulumi.exceptions.RunException;
import com.pulumi.internal.ConfigInternal;
import com.pulumi.resources.CallArgs;
import com.pulumi.resources.ComponentResource;
import com.pulumi.resources.ComponentResourceOptions;
Expand Down Expand Up @@ -96,6 +97,7 @@
@InternalUse
public class DeploymentImpl extends DeploymentInstanceHolder implements Deployment, DeploymentInternal {

private final ConfigInternal config;
private final DeploymentState state;
private final Log log;
private final FeatureSupport featureSupport;
Expand All @@ -114,8 +116,10 @@ public class DeploymentImpl extends DeploymentInstanceHolder implements Deployme
@InternalUse
@VisibleForTesting
public DeploymentImpl(
ConfigInternal config,
DeploymentState state
) {
this.config = Objects.requireNonNull(config);
this.state = Objects.requireNonNull(state);
this.log = new Log(state.logger, DeploymentState.ExcessiveDebugOutput);
this.featureSupport = new FeatureSupport(state.monitor);
Expand Down Expand Up @@ -150,7 +154,8 @@ public DeploymentImpl(
@VisibleForTesting
public static DeploymentImpl fromEnvironment() {
var state = DeploymentState.fromEnvironment();
var impl = new DeploymentImpl(state);
var config = ConfigInternal.fromEnvironment(state.projectName);
var impl = new DeploymentImpl(config, state);
DeploymentInstanceHolder.setInstance(new DeploymentInstanceInternal(impl));
return impl;
}
Expand Down Expand Up @@ -184,18 +189,18 @@ public Log getLog() {

@Override
@InternalUse
public Config getConfig() {
return this.state.config;
public ConfigInternal getConfig() {
return this.config;
}

@Override
public Optional<String> getConfig(String fullKey) {
return this.state.config.getConfig(fullKey);
return this.config.get(fullKey);
}

@Override
public boolean isConfigSecret(String fullKey) {
return this.state.config.isConfigSecret(fullKey);
return this.config.isConfigSecret(fullKey);
}

@Nullable
Expand Down Expand Up @@ -1463,7 +1468,6 @@ public static class DeploymentState {
public static final boolean DisableResourceReferences = getBooleanEnvironmentVariable("PULUMI_DISABLE_RESOURCE_REFERENCES").or(false);
public static final boolean ExcessiveDebugOutput = getBooleanEnvironmentVariable("PULUMI_EXCESSIVE_DEBUG_OUTPUT").or(false);

public final Config config;
public final String projectName;
public final String stackName;
public final boolean isDryRun;
Expand All @@ -1477,14 +1481,12 @@ public static class DeploymentState {
@InternalUse
@VisibleForTesting
public DeploymentState(
Config config,
Logger standardLogger,
String projectName,
String stackName,
boolean isDryRun,
Engine engine,
Monitor monitor) {
this.config = Objects.requireNonNull(config);
this.standardLogger = Objects.requireNonNull(standardLogger);
this.projectName = Objects.requireNonNull(projectName);
this.stackName = Objects.requireNonNull(stackName);
Expand Down Expand Up @@ -1515,7 +1517,6 @@ public static DeploymentState fromEnvironment() {
var stack = getEnvironmentVariable("PULUMI_STACK").orThrow(startErrorSupplier);
var dryRun = getBooleanEnvironmentVariable("PULUMI_DRY_RUN").orThrow(startErrorSupplier);

var config = Config.parse();
standardLogger.setLevel(GlobalLogging.GlobalLevel);

standardLogger.log(Level.FINEST, "Creating deployment engine");
Expand All @@ -1526,7 +1527,7 @@ public static DeploymentState fromEnvironment() {
var monitor = new GrpcMonitor(monitorTarget);
standardLogger.log(Level.FINEST, "Created deployment monitor");

return new DeploymentState(config, standardLogger, project, stack, dryRun, engine, monitor);
return new DeploymentState(standardLogger, project, stack, dryRun, engine, monitor);
} catch (NullPointerException ex) {
throw new IllegalStateException(
"Program run without the Pulumi engine available; re-run using the `pulumi` CLI", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.pulumi.deployment.CallOptions;
import com.pulumi.deployment.DeploymentInstance;
import com.pulumi.deployment.InvokeOptions;
import com.pulumi.internal.ConfigInternal;
import com.pulumi.resources.CallArgs;
import com.pulumi.resources.InvokeArgs;
import com.pulumi.resources.Resource;
Expand Down Expand Up @@ -55,7 +56,7 @@ public boolean isDryRun() {
}

@Override
public Config getConfig() {
public ConfigInternal getConfig() {
return deployment.getConfig();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.pulumi.core.Output;
import com.pulumi.core.internal.annotations.InternalUse;
import com.pulumi.deployment.Deployment;
import com.pulumi.internal.ConfigInternal;
import com.pulumi.resources.Resource;
import com.pulumi.resources.ResourceArgs;
import com.pulumi.resources.ResourceOptions;
Expand All @@ -15,7 +16,7 @@
@InternalUse
public interface DeploymentInternal extends Deployment {

Config getConfig();
ConfigInternal getConfig();

Optional<String> getConfig(String fullKey);

Expand Down
Loading

0 comments on commit 2d9f436

Please sign in to comment.