diff --git a/generators/java/sdk/CHANGELOG.md b/generators/java/sdk/CHANGELOG.md index 20836ac2995..eb9a220cb5c 100644 --- a/generators/java/sdk/CHANGELOG.md +++ b/generators/java/sdk/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.7.0-rc0] - 2024-02-04 +## [0.7.0-rc1] - 2024-02-04 - Chore: Bump intermediate representation to v31 - Feature: The SDK generator now supports idempotency headers. Users will be able to specify the idempotency headers in RequestOptions. @@ -18,6 +18,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 .idempotencyKey("...") .build()); ``` +- Feature: The SDK generator now supports scanning API credentials + via environment varaibles. + ```java + Imdb imdb = Imdb.builder() + .apiKey("...") // defaults to System.getenv("IMDB_API_KEY") + .build(); + ``` ## [0.6.1] - 2024-02-03 diff --git a/generators/java/sdk/VERSION b/generators/java/sdk/VERSION index 4ba1bffe174..81e56e16206 100644 --- a/generators/java/sdk/VERSION +++ b/generators/java/sdk/VERSION @@ -1 +1 @@ -0.7.0-rc0 \ No newline at end of file +0.7.0-rc1 \ No newline at end of file diff --git a/generators/java/sdk/src/main/java/com/fern/java/client/generators/RootClientGenerator.java b/generators/java/sdk/src/main/java/com/fern/java/client/generators/RootClientGenerator.java index 05e6458de5a..142149b7d76 100644 --- a/generators/java/sdk/src/main/java/com/fern/java/client/generators/RootClientGenerator.java +++ b/generators/java/sdk/src/main/java/com/fern/java/client/generators/RootClientGenerator.java @@ -19,6 +19,7 @@ import com.fern.ir.model.auth.AuthScheme; import com.fern.ir.model.auth.BasicAuthScheme; import com.fern.ir.model.auth.BearerAuthScheme; +import com.fern.ir.model.auth.EnvironmentVariable; import com.fern.ir.model.auth.HeaderAuthScheme; import com.fern.ir.model.commons.TypeId; import com.fern.java.AbstractGeneratorContext; @@ -37,9 +38,11 @@ import com.squareup.javapoet.FieldSpec; import com.squareup.javapoet.JavaFile; import com.squareup.javapoet.MethodSpec; +import com.squareup.javapoet.ParameterSpec; import com.squareup.javapoet.TypeSpec; import java.util.Base64; import java.util.Map; +import java.util.Optional; import javax.lang.model.element.Modifier; public final class RootClientGenerator extends AbstractFileGenerator { @@ -120,20 +123,21 @@ public GeneratedRootClient generateFile() { } private TypeSpec getClientBuilder() { - TypeSpec.Builder typeSpecBuilder = + TypeSpec.Builder clientBuilder = TypeSpec.classBuilder(builderName).addModifiers(Modifier.PUBLIC, Modifier.FINAL); + MethodSpec.Builder buildMethod = + MethodSpec.methodBuilder("build").addModifiers(Modifier.PUBLIC).returns(className); - typeSpecBuilder.addField( - FieldSpec.builder(generatedClientOptions.builderClassName(), CLIENT_OPTIONS_BUILDER_NAME) - .addModifiers(Modifier.PRIVATE) - .initializer("$T.builder()", generatedClientOptions.getClassName()) - .build()); + clientBuilder.addField(FieldSpec.builder(generatedClientOptions.builderClassName(), CLIENT_OPTIONS_BUILDER_NAME) + .addModifiers(Modifier.PRIVATE) + .initializer("$T.builder()", generatedClientOptions.getClassName()) + .build()); FieldSpec.Builder environmentFieldBuilder = FieldSpec.builder( generatedEnvironmentsClass.getClassName(), ENVIRONMENT_FIELD_NAME) .addModifiers(Modifier.PRIVATE); - AuthSchemeHandler authSchemeHandler = new AuthSchemeHandler(typeSpecBuilder); + AuthSchemeHandler authSchemeHandler = new AuthSchemeHandler(clientBuilder, buildMethod); generatorContext.getIr().getAuth().getSchemes().forEach(authScheme -> authScheme.visit(authSchemeHandler)); generatorContext.getIr().getHeaders().forEach(httpHeader -> { authSchemeHandler.visitHeader(HeaderAuthScheme.builder() @@ -155,14 +159,14 @@ private TypeSpec getClientBuilder() { .addParameter(generatedEnvironmentsClass.getClassName(), "environment") .returns(builderName) .build(); - typeSpecBuilder.addMethod(environmentMethod.toBuilder() + clientBuilder.addMethod(environmentMethod.toBuilder() .addStatement("this.$L = $L", ENVIRONMENT_FIELD_NAME, "environment") .addStatement("return this") .build()); } FieldSpec environmentField = environmentFieldBuilder.build(); - typeSpecBuilder.addField(environmentField); + clientBuilder.addField(environmentField); if (generatedEnvironmentsClass.info() instanceof SingleUrlEnvironmentClass) { SingleUrlEnvironmentClass singleUrlEnvironmentClass = @@ -172,7 +176,7 @@ private TypeSpec getClientBuilder() { .addParameter(String.class, "url") .returns(builderName) .build(); - typeSpecBuilder.addMethod(urlMethod.toBuilder() + clientBuilder.addMethod(urlMethod.toBuilder() .addStatement( "this.$L = $T.$N($L)", ENVIRONMENT_FIELD_NAME, @@ -203,13 +207,9 @@ private TypeSpec getClientBuilder() { .addStatement("return this") .build(); }) - .forEach(typeSpecBuilder::addMethod); + .forEach(clientBuilder::addMethod); - MethodSpec buildMethod = MethodSpec.methodBuilder("build") - .addModifiers(Modifier.PUBLIC) - .returns(className) - .build(); - typeSpecBuilder.addMethod(buildMethod.toBuilder() + clientBuilder.addMethod(buildMethod .addStatement( "$L.$N(this.$N)", CLIENT_OPTIONS_BUILDER_NAME, @@ -218,7 +218,7 @@ private TypeSpec getClientBuilder() { .addStatement("return new $T($L.build())", className, CLIENT_OPTIONS_BUILDER_NAME) .build()); - return typeSpecBuilder.build(); + return clientBuilder.build(); } private static String getRootClientName(AbstractGeneratorContext generatorContext) { @@ -234,43 +234,107 @@ private static String getRootClientPrefix(AbstractGeneratorContext generat private final class AuthSchemeHandler implements AuthScheme.Visitor { - private final TypeSpec.Builder builder; + private final TypeSpec.Builder clientBuilder; + private final MethodSpec.Builder buildMethod; + private final boolean isMandatory; - private AuthSchemeHandler(TypeSpec.Builder builder) { - this.builder = builder; + private AuthSchemeHandler(TypeSpec.Builder clientBuilder, MethodSpec.Builder buildMethod) { + this.clientBuilder = clientBuilder; + this.buildMethod = buildMethod; + this.isMandatory = clientGeneratorContext.getIr().getSdkConfig().getIsAuthMandatory(); } @Override public Void visitBearer(BearerAuthScheme bearer) { - MethodSpec tokenMethod = MethodSpec.methodBuilder( - bearer.getToken().getCamelCase().getSafeName()) - .addModifiers(Modifier.PUBLIC) - .addParameter(String.class, bearer.getToken().getCamelCase().getSafeName()) - .returns(builderName) - .build(); - builder.addMethod(tokenMethod.toBuilder() - .addStatement( - "this.$L.addHeader($S, $S + $L)", - CLIENT_OPTIONS_BUILDER_NAME, - "Authorization", - "Bearer ", - bearer.getToken().getCamelCase().getSafeName()) - .addStatement("return this") - .build()); + String fieldName = bearer.getToken().getCamelCase().getSafeName(); + createSetter(fieldName, bearer.getTokenEnvVar()); + if (isMandatory) { + this.buildMethod + .beginControlFlow("if ($L == null)", fieldName) + .addStatement( + "throw new RuntimeException($S)", + bearer.getTokenEnvVar().isEmpty() + ? getErrorMessage(fieldName) + : getErrorMessage( + fieldName, + bearer.getTokenEnvVar().get())) + .endControlFlow(); + } + this.buildMethod.addStatement( + "this.$L.addHeader($S, $S + this.$L)", + CLIENT_OPTIONS_BUILDER_NAME, + "Authorization", + "Bearer ", + fieldName); return null; } @Override public Void visitBasic(BasicAuthScheme basic) { - MethodSpec tokenMethod = MethodSpec.methodBuilder("credentials") + // username + String usernameFieldName = basic.getUsername().getCamelCase().getSafeName(); + FieldSpec.Builder usernameField = + FieldSpec.builder(String.class, usernameFieldName).addModifiers(Modifier.PRIVATE); + if (basic.getUsernameEnvVar().isPresent()) { + usernameField.initializer( + "System.getenv($S)", basic.getUsernameEnvVar().get().get()); + } else { + usernameField.initializer("null"); + } + this.clientBuilder.addField(usernameField.build()); + + // password + String passwordFieldName = basic.getPassword().getCamelCase().getSafeName(); + FieldSpec.Builder passwordField = + FieldSpec.builder(String.class, passwordFieldName).addModifiers(Modifier.PRIVATE); + if (basic.getPasswordEnvVar().isPresent()) { + passwordField.initializer( + "System.getenv($S)", basic.getPasswordEnvVar().get().get()); + } else { + passwordField.initializer("null"); + } + this.clientBuilder.addField(passwordField.build()); + + + // add setter method + ParameterSpec usernameParam = ParameterSpec.builder(String.class, usernameFieldName) + .build(); + ParameterSpec passwordParam = ParameterSpec.builder(String.class, passwordFieldName) + .build(); + this.clientBuilder.addMethod(MethodSpec.methodBuilder("credentials") .addModifiers(Modifier.PUBLIC) - .addParameter( - String.class, basic.getUsername().getCamelCase().getSafeName()) - .addParameter( - String.class, basic.getPassword().getCamelCase().getSafeName()) + .addParameter(usernameParam) + .addParameter(passwordParam) + .addStatement("this.$L = $L", usernameFieldName, usernameFieldName) + .addStatement("this.$L = $L", passwordFieldName, passwordFieldName) + .addStatement("return this") .returns(builderName) - .build(); - builder.addMethod(tokenMethod.toBuilder() + .build()); + + if (isMandatory) { + this.buildMethod + .beginControlFlow("if (this.$L == null)", usernameFieldName) + .addStatement( + "throw new RuntimeException($S)", + basic.getUsernameEnvVar().isEmpty() + ? getErrorMessage(usernameFieldName) + : getErrorMessage( + usernameFieldName, + basic.getUsernameEnvVar().get())) + .endControlFlow(); + this.buildMethod + .beginControlFlow("if (this.$L == null)", passwordFieldName) + .addStatement( + "throw new RuntimeException($S)", + basic.getPasswordEnvVar().isEmpty() + ? getErrorMessage(passwordFieldName) + : getErrorMessage( + passwordFieldName, + basic.getPasswordEnvVar().get())) + .endControlFlow(); + } + + this.buildMethod .addStatement( "String unencodedToken = $L + \":\" + $L", basic.getUsername().getCamelCase().getSafeName(), @@ -282,44 +346,77 @@ public Void visitBasic(BasicAuthScheme basic) { "this.$L.addHeader($S, $S + $L)", CLIENT_OPTIONS_BUILDER_NAME, "Authorization", - "Basic ", - "encodedToken") - .addStatement("return this") - .build()); + "Bearer ", + "encodedToken"); return null; } @Override public Void visitHeader(HeaderAuthScheme header) { - String headerCamelCase = header.getName().getName().getCamelCase().getSafeName(); - MethodSpec tokenMethod = MethodSpec.methodBuilder(headerCamelCase) - .addModifiers(Modifier.PUBLIC) - .addParameter(String.class, headerCamelCase) - .returns(builderName) - .build(); - if (header.getPrefix().isPresent()) { - builder.addMethod(tokenMethod.toBuilder() + String fieldName = header.getName().getName().getCamelCase().getSafeName(); + createSetter(fieldName, header.getHeaderEnvVar()); + if (isMandatory) { + this.buildMethod + .beginControlFlow("if ($L == null)", fieldName) .addStatement( - "this.$L.addHeader($S, $S + $L)", - CLIENT_OPTIONS_BUILDER_NAME, - header.getName().getWireValue(), - header.getPrefix().get(), - headerCamelCase) - .addStatement("return this") - .build()); + "throw new RuntimeException($S)", + header.getHeaderEnvVar().isEmpty() + ? getErrorMessage(fieldName) + : getErrorMessage( + fieldName, + header.getHeaderEnvVar().get())) + .endControlFlow(); + } + if (header.getPrefix().isPresent()) { + this.buildMethod.addStatement( + "this.$L.addHeader($S, $S + this.$L)", + CLIENT_OPTIONS_BUILDER_NAME, + header.getName().getWireValue(), + header.getPrefix().get(), + fieldName); } else { - builder.addMethod(tokenMethod.toBuilder() - .addStatement( - "this.$L.addHeader($S, $L)", - CLIENT_OPTIONS_BUILDER_NAME, - header.getName().getWireValue(), - headerCamelCase) - .addStatement("return this") - .build()); + this.buildMethod.addStatement( + "this.$L.addHeader($S, this.$L)", + CLIENT_OPTIONS_BUILDER_NAME, + header.getName().getWireValue(), + fieldName); } return null; } + private void createSetter(String fieldName, Optional environmentVariable) { + FieldSpec.Builder field = FieldSpec.builder(String.class, fieldName).addModifiers(Modifier.PRIVATE); + if (environmentVariable.isPresent()) { + field.initializer( + "System.getenv($S)", environmentVariable.get().get()); + } else { + field.initializer("null"); + } + clientBuilder.addField(field.build()); + MethodSpec.Builder setter = MethodSpec.methodBuilder(fieldName) + .addModifiers(Modifier.PUBLIC) + .addParameter(String.class, fieldName) + .returns(builderName) + .addJavadoc("Sets $L", fieldName) + .addStatement("this.$L = $L", fieldName, fieldName) + .addStatement("return this"); + if (environmentVariable.isPresent()) { + setter.addJavadoc( + ".\nDefaults to the $L environment variable.", + environmentVariable.get().get()); + } + clientBuilder.addMethod(setter.build()); + } + + private String getErrorMessage(String fieldName) { + return "Please provide " + fieldName; + } + + private String getErrorMessage(String fieldName, EnvironmentVariable environmentVariable) { + return "Please provide " + fieldName + " or set the " + environmentVariable.get() + " " + + "environment variable."; + } + @Override public Void _visitUnknown(Object unknownType) { throw new RuntimeException("Encountered unknown auth scheme"); diff --git a/packages/seed/src/cli.ts b/packages/seed/src/cli.ts index 7edcac08556..597a3dbda53 100644 --- a/packages/seed/src/cli.ts +++ b/packages/seed/src/cli.ts @@ -45,6 +45,11 @@ function addTestCommand(cli: Argv) { demandOption: false, description: "Runs on all fixtures if not provided" }) + .option("keepDocker", { + type: "boolean", + demandOption: false, + description: "Keeps the docker container after the tests are finished" + }) .option("update", { type: "boolean", alias: "u", @@ -94,7 +99,8 @@ function addTestCommand(cli: Argv) { language: workspace.workspaceConfig.language, docker: parsedDockerImage, logLevel: argv["log-level"], - numDockers: argv.parallel + numDockers: argv.parallel, + keepDocker: argv.keepDocker }); } else { await testWorkspaceFixtures({ @@ -106,7 +112,8 @@ function addTestCommand(cli: Argv) { scripts: workspace.workspaceConfig.scripts, logLevel: argv["log-level"], numDockers: argv.parallel, - taskContextFactory + taskContextFactory, + keepDocker: argv.keepDocker }); } } diff --git a/packages/seed/src/commands/test/runDockerForWorkspace.ts b/packages/seed/src/commands/test/runDockerForWorkspace.ts index 42d9419f4c2..27a6559712f 100644 --- a/packages/seed/src/commands/test/runDockerForWorkspace.ts +++ b/packages/seed/src/commands/test/runDockerForWorkspace.ts @@ -23,7 +23,8 @@ export async function runDockerForWorkspace({ irVersion, outputVersion, outputMode, - fixtureName + fixtureName, + keepDocker }: { absolutePathToOutput: AbsoluteFilePath; docker: ParsedDockerName; @@ -35,6 +36,7 @@ export async function runDockerForWorkspace({ outputVersion?: string; outputMode: OutputMode; fixtureName: string; + keepDocker: boolean | undefined; }): Promise { const generatorGroup: GeneratorGroup = { groupName: "test", @@ -56,7 +58,7 @@ export async function runDockerForWorkspace({ organization: DUMMY_ORGANIZATION, workspace, generatorGroup, - keepDocker: true, + keepDocker: keepDocker ?? false, context: taskContext, irVersionOverride: irVersion, outputVersionOverride: outputVersion diff --git a/packages/seed/src/commands/test/testCustomFixture.ts b/packages/seed/src/commands/test/testCustomFixture.ts index bf120c54c1b..ec07777a34b 100644 --- a/packages/seed/src/commands/test/testCustomFixture.ts +++ b/packages/seed/src/commands/test/testCustomFixture.ts @@ -15,7 +15,8 @@ export async function testCustomFixture({ language, docker, logLevel, - numDockers + numDockers, + keepDocker }: { pathToFixture: AbsoluteFilePath; workspace: SeedWorkspace; @@ -24,6 +25,7 @@ export async function testCustomFixture({ docker: ParsedDockerName; logLevel: LogLevel; numDockers: number; + keepDocker: boolean | undefined; }): Promise { const lock = new Semaphore(numDockers); const outputDir = await tmp.dir(); @@ -46,7 +48,8 @@ export async function testCustomFixture({ outputDir: absolutePathToOutput, outputMode: "github", outputFolder: "custom", - id: "custom" + id: "custom", + keepDocker }); if (result.type === "failure") { diff --git a/packages/seed/src/commands/test/testWorkspaceFixtures.ts b/packages/seed/src/commands/test/testWorkspaceFixtures.ts index 4db9cd11c3c..216760c192e 100644 --- a/packages/seed/src/commands/test/testWorkspaceFixtures.ts +++ b/packages/seed/src/commands/test/testWorkspaceFixtures.ts @@ -44,7 +44,8 @@ export async function testWorkspaceFixtures({ docker, scripts, taskContextFactory, - numDockers + numDockers, + keepDocker }: { workspace: SeedWorkspace; irVersion: string | undefined; @@ -55,6 +56,7 @@ export async function testWorkspaceFixtures({ logLevel: LogLevel; taskContextFactory: TaskContextFactory; numDockers: number; + keepDocker: boolean | undefined; }): Promise { const lock = new Semaphore(numDockers); @@ -94,7 +96,8 @@ export async function testWorkspaceFixtures({ RelativeFilePath.of(fixtureConfigInstance.outputFolder) ), outputMode: fixtureConfigInstance.outputMode ?? workspace.workspaceConfig.defaultOutputMode, - outputFolder: fixtureConfigInstance.outputFolder + outputFolder: fixtureConfigInstance.outputFolder, + keepDocker }) ); } @@ -114,7 +117,8 @@ export async function testWorkspaceFixtures({ taskContext: taskContextFactory.create(`${workspace.workspaceName}:${fixture}`), outputDir: join(workspace.absolutePathToWorkspace, RelativeFilePath.of(fixture)), outputMode: workspace.workspaceConfig.defaultOutputMode, - outputFolder: fixture + outputFolder: fixture, + keepDocker }) ); } @@ -175,7 +179,8 @@ export async function acquireLocksAndRunTest({ outputDir, absolutePathToWorkspace, outputMode, - outputFolder + outputFolder, + keepDocker }: { id: string; lock: Semaphore; @@ -191,6 +196,7 @@ export async function acquireLocksAndRunTest({ absolutePathToWorkspace: AbsoluteFilePath; outputMode: OutputMode; outputFolder: string; + keepDocker: boolean | undefined; }): Promise { taskContext.logger.debug("Acquiring lock..."); await lock.acquire(); @@ -208,7 +214,8 @@ export async function acquireLocksAndRunTest({ outputDir, absolutePathToWorkspace, outputMode, - outputFolder + outputFolder, + keepDocker }); taskContext.logger.debug("Releasing lock..."); lock.release(); @@ -228,7 +235,8 @@ async function testWithWriteToDisk({ outputDir, absolutePathToWorkspace, outputMode, - outputFolder + outputFolder, + keepDocker }: { id: string; fixture: string; @@ -243,6 +251,7 @@ async function testWithWriteToDisk({ absolutePathToWorkspace: AbsoluteFilePath; outputMode: OutputMode; outputFolder: string; + keepDocker: boolean | undefined; }): Promise { try { const workspace = await loadAPIWorkspace({ @@ -275,7 +284,8 @@ async function testWithWriteToDisk({ irVersion, outputVersion, outputMode, - fixtureName: fixture + fixtureName: fixture, + keepDocker }); for (const script of scripts ?? []) { taskContext.logger.info(`Running script on ${fixture}`); diff --git a/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/SeedAuthEnvironmentVariablesClientBuilder.java b/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/SeedAuthEnvironmentVariablesClientBuilder.java index 6ad6e8842af..d248db006c7 100644 --- a/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/SeedAuthEnvironmentVariablesClientBuilder.java +++ b/seed/java-sdk/auth-environment-variables/src/main/java/com/seed/authEnvironmentVariables/SeedAuthEnvironmentVariablesClientBuilder.java @@ -9,10 +9,16 @@ public final class SeedAuthEnvironmentVariablesClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String apiKey = System.getenv("FERN_API_KEY"); + private Environment environment; + /** + * Sets apiKey. + * Defaults to the FERN_API_KEY environment variable. + */ public SeedAuthEnvironmentVariablesClientBuilder apiKey(String apiKey) { - this.clientOptionsBuilder.addHeader("X-FERN-API-KEY", apiKey); + this.apiKey = apiKey; return this; } @@ -22,6 +28,10 @@ public SeedAuthEnvironmentVariablesClientBuilder url(String url) { } public SeedAuthEnvironmentVariablesClient build() { + if (apiKey == null) { + throw new RuntimeException("Please provide apiKey or set the FERN_API_KEY environment variable."); + } + this.clientOptionsBuilder.addHeader("X-FERN-API-KEY", this.apiKey); clientOptionsBuilder.environment(this.environment); return new SeedAuthEnvironmentVariablesClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/SeedBasicAuthClientBuilder.java b/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/SeedBasicAuthClientBuilder.java index f43ed7708fb..fcf26b2cbf1 100644 --- a/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/SeedBasicAuthClientBuilder.java +++ b/seed/java-sdk/basic-auth/src/main/java/com/seed/basicAuth/SeedBasicAuthClientBuilder.java @@ -10,12 +10,15 @@ public final class SeedBasicAuthClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String username = null; + + private String password = null; + private Environment environment; public SeedBasicAuthClientBuilder credentials(String username, String password) { - String unencodedToken = username + ":" + password; - String encodedToken = Base64.getEncoder().encodeToString(unencodedToken.getBytes()); - this.clientOptionsBuilder.addHeader("Authorization", "Basic " + encodedToken); + this.username = username; + this.password = password; return this; } @@ -25,6 +28,15 @@ public SeedBasicAuthClientBuilder url(String url) { } public SeedBasicAuthClient build() { + if (this.username == null) { + throw new RuntimeException("Please provide username"); + } + if (this.password == null) { + throw new RuntimeException("Please provide password"); + } + String unencodedToken = username + ":" + password; + String encodedToken = Base64.getEncoder().encodeToString(unencodedToken.getBytes()); + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + encodedToken); clientOptionsBuilder.environment(this.environment); return new SeedBasicAuthClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/SeedBearerTokenEnvironmentVariableClientBuilder.java b/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/SeedBearerTokenEnvironmentVariableClientBuilder.java index cb7cfbe5b46..222fe218891 100644 --- a/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/SeedBearerTokenEnvironmentVariableClientBuilder.java +++ b/seed/java-sdk/bearer-token-environment-variable/src/main/java/com/seed/bearerTokenEnvironmentVariable/SeedBearerTokenEnvironmentVariableClientBuilder.java @@ -9,10 +9,16 @@ public final class SeedBearerTokenEnvironmentVariableClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String apiKey = System.getenv("COURIER_API_KEY"); + private Environment environment; + /** + * Sets apiKey. + * Defaults to the COURIER_API_KEY environment variable. + */ public SeedBearerTokenEnvironmentVariableClientBuilder apiKey(String apiKey) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + apiKey); + this.apiKey = apiKey; return this; } @@ -22,6 +28,10 @@ public SeedBearerTokenEnvironmentVariableClientBuilder url(String url) { } public SeedBearerTokenEnvironmentVariableClient build() { + if (apiKey == null) { + throw new RuntimeException("Please provide apiKey or set the COURIER_API_KEY environment variable."); + } + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.apiKey); clientOptionsBuilder.environment(this.environment); return new SeedBearerTokenEnvironmentVariableClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/SeedCustomAuthClientBuilder.java b/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/SeedCustomAuthClientBuilder.java index d084b7015c1..0e2b2e1863c 100644 --- a/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/SeedCustomAuthClientBuilder.java +++ b/seed/java-sdk/custom-auth/src/main/java/com/seed/customAuth/SeedCustomAuthClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedCustomAuthClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String customAuthScheme = null; + private Environment environment; + /** + * Sets customAuthScheme + */ public SeedCustomAuthClientBuilder customAuthScheme(String customAuthScheme) { - this.clientOptionsBuilder.addHeader("X-API-KEY", customAuthScheme); + this.customAuthScheme = customAuthScheme; return this; } @@ -22,6 +27,10 @@ public SeedCustomAuthClientBuilder url(String url) { } public SeedCustomAuthClient build() { + if (customAuthScheme == null) { + throw new RuntimeException("Please provide customAuthScheme"); + } + this.clientOptionsBuilder.addHeader("X-API-KEY", this.customAuthScheme); clientOptionsBuilder.environment(this.environment); return new SeedCustomAuthClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/examples/src/main/java/com/seed/examples/SeedExamplesClientBuilder.java b/seed/java-sdk/examples/src/main/java/com/seed/examples/SeedExamplesClientBuilder.java index a25698a5165..32cb3a0a8f2 100644 --- a/seed/java-sdk/examples/src/main/java/com/seed/examples/SeedExamplesClientBuilder.java +++ b/seed/java-sdk/examples/src/main/java/com/seed/examples/SeedExamplesClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedExamplesClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment; + /** + * Sets token + */ public SeedExamplesClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -27,6 +32,7 @@ public SeedExamplesClientBuilder url(String url) { } public SeedExamplesClient build() { + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedExamplesClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java index a826250b9a2..bd59da0e215 100644 --- a/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java +++ b/seed/java-sdk/exhaustive/custom-dependency/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedExhaustiveClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment; + /** + * Sets token + */ public SeedExhaustiveClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -22,6 +27,7 @@ public SeedExhaustiveClientBuilder url(String url) { } public SeedExhaustiveClient build() { + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedExhaustiveClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java index a826250b9a2..bd59da0e215 100644 --- a/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java +++ b/seed/java-sdk/exhaustive/forward-compatible-enums/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedExhaustiveClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment; + /** + * Sets token + */ public SeedExhaustiveClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -22,6 +27,7 @@ public SeedExhaustiveClientBuilder url(String url) { } public SeedExhaustiveClient build() { + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedExhaustiveClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/exhaustive/local-files/SeedExhaustiveClientBuilder.java b/seed/java-sdk/exhaustive/local-files/SeedExhaustiveClientBuilder.java index 5d4f6b9d404..843d99ab83d 100644 --- a/seed/java-sdk/exhaustive/local-files/SeedExhaustiveClientBuilder.java +++ b/seed/java-sdk/exhaustive/local-files/SeedExhaustiveClientBuilder.java @@ -11,10 +11,15 @@ public final class SeedExhaustiveClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment; + /** + * Sets token + */ public SeedExhaustiveClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -24,6 +29,7 @@ public SeedExhaustiveClientBuilder url(String url) { } public SeedExhaustiveClient build() { + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedExhaustiveClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java index a826250b9a2..bd59da0e215 100644 --- a/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java +++ b/seed/java-sdk/exhaustive/no-custom-config/src/main/java/com/seed/exhaustive/SeedExhaustiveClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedExhaustiveClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment; + /** + * Sets token + */ public SeedExhaustiveClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -22,6 +27,7 @@ public SeedExhaustiveClientBuilder url(String url) { } public SeedExhaustiveClient build() { + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedExhaustiveClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/idempotency-headers/src/main/java/com/seed/idempotencyHeaders/SeedIdempotencyHeadersClientBuilder.java b/seed/java-sdk/idempotency-headers/src/main/java/com/seed/idempotencyHeaders/SeedIdempotencyHeadersClientBuilder.java index 8ba583b06ac..ed634318256 100644 --- a/seed/java-sdk/idempotency-headers/src/main/java/com/seed/idempotencyHeaders/SeedIdempotencyHeadersClientBuilder.java +++ b/seed/java-sdk/idempotency-headers/src/main/java/com/seed/idempotencyHeaders/SeedIdempotencyHeadersClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedIdempotencyHeadersClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment; + /** + * Sets token + */ public SeedIdempotencyHeadersClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -22,6 +27,10 @@ public SeedIdempotencyHeadersClientBuilder url(String url) { } public SeedIdempotencyHeadersClient build() { + if (token == null) { + throw new RuntimeException("Please provide token"); + } + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedIdempotencyHeadersClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/imdb/src/main/java/com/seed/api/SeedApiClientBuilder.java b/seed/java-sdk/imdb/src/main/java/com/seed/api/SeedApiClientBuilder.java index cbbae4c8451..047698e5064 100644 --- a/seed/java-sdk/imdb/src/main/java/com/seed/api/SeedApiClientBuilder.java +++ b/seed/java-sdk/imdb/src/main/java/com/seed/api/SeedApiClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedApiClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment; + /** + * Sets token + */ public SeedApiClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -22,6 +27,7 @@ public SeedApiClientBuilder url(String url) { } public SeedApiClient build() { + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedApiClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/SeedLiteralHeadersClientBuilder.java b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/SeedLiteralHeadersClientBuilder.java index 4c4cef13813..9288439a333 100644 --- a/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/SeedLiteralHeadersClientBuilder.java +++ b/seed/java-sdk/literal-headers/src/main/java/com/seed/literalHeaders/SeedLiteralHeadersClientBuilder.java @@ -9,15 +9,25 @@ public final class SeedLiteralHeadersClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String apiHeader = null; + + private String apiTest = null; + private Environment environment; + /** + * Sets apiHeader + */ public SeedLiteralHeadersClientBuilder apiHeader(String apiHeader) { - this.clientOptionsBuilder.addHeader("X-API-Header", apiHeader); + this.apiHeader = apiHeader; return this; } + /** + * Sets apiTest + */ public SeedLiteralHeadersClientBuilder apiTest(String apiTest) { - this.clientOptionsBuilder.addHeader("X-API-Test", apiTest); + this.apiTest = apiTest; return this; } @@ -27,6 +37,8 @@ public SeedLiteralHeadersClientBuilder url(String url) { } public SeedLiteralHeadersClient build() { + this.clientOptionsBuilder.addHeader("X-API-Header", this.apiHeader); + this.clientOptionsBuilder.addHeader("X-API-Test", this.apiTest); clientOptionsBuilder.environment(this.environment); return new SeedLiteralHeadersClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/SeedMultiUrlEnvironmentClientBuilder.java b/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/SeedMultiUrlEnvironmentClientBuilder.java index 9f746a2cde4..0f2ac2fadde 100644 --- a/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/SeedMultiUrlEnvironmentClientBuilder.java +++ b/seed/java-sdk/multi-url-environment/src/main/java/com/seed/multiUrlEnvironment/SeedMultiUrlEnvironmentClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedMultiUrlEnvironmentClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment = Environment.PRODUCTION; + /** + * Sets token + */ public SeedMultiUrlEnvironmentClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -22,6 +27,10 @@ public SeedMultiUrlEnvironmentClientBuilder environment(Environment environment) } public SeedMultiUrlEnvironmentClient build() { + if (token == null) { + throw new RuntimeException("Please provide token"); + } + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedMultiUrlEnvironmentClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/SeedNoEnvironmentClientBuilder.java b/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/SeedNoEnvironmentClientBuilder.java index d33fcd4241b..a13106f967a 100644 --- a/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/SeedNoEnvironmentClientBuilder.java +++ b/seed/java-sdk/no-environment/src/main/java/com/seed/noEnvironment/SeedNoEnvironmentClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedNoEnvironmentClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment; + /** + * Sets token + */ public SeedNoEnvironmentClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -22,6 +27,10 @@ public SeedNoEnvironmentClientBuilder url(String url) { } public SeedNoEnvironmentClient build() { + if (token == null) { + throw new RuntimeException("Please provide token"); + } + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedNoEnvironmentClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/SeedSingleUrlEnvironmentDefaultClientBuilder.java b/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/SeedSingleUrlEnvironmentDefaultClientBuilder.java index ef649174bed..b4efb145038 100644 --- a/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/SeedSingleUrlEnvironmentDefaultClientBuilder.java +++ b/seed/java-sdk/single-url-environment-default/src/main/java/com/seed/singleUrlEnvironmentDefault/SeedSingleUrlEnvironmentDefaultClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedSingleUrlEnvironmentDefaultClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment = Environment.PRODUCTION; + /** + * Sets token + */ public SeedSingleUrlEnvironmentDefaultClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -27,6 +32,10 @@ public SeedSingleUrlEnvironmentDefaultClientBuilder url(String url) { } public SeedSingleUrlEnvironmentDefaultClient build() { + if (token == null) { + throw new RuntimeException("Please provide token"); + } + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedSingleUrlEnvironmentDefaultClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/SeedSingleUrlEnvironmentNoDefaultClientBuilder.java b/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/SeedSingleUrlEnvironmentNoDefaultClientBuilder.java index ab894cf2688..6156ffa1b4f 100644 --- a/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/SeedSingleUrlEnvironmentNoDefaultClientBuilder.java +++ b/seed/java-sdk/single-url-environment-no-default/src/main/java/com/seed/singleUrlEnvironmentNoDefault/SeedSingleUrlEnvironmentNoDefaultClientBuilder.java @@ -9,10 +9,15 @@ public final class SeedSingleUrlEnvironmentNoDefaultClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + private Environment environment; + /** + * Sets token + */ public SeedSingleUrlEnvironmentNoDefaultClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } @@ -27,6 +32,10 @@ public SeedSingleUrlEnvironmentNoDefaultClientBuilder url(String url) { } public SeedSingleUrlEnvironmentNoDefaultClient build() { + if (token == null) { + throw new RuntimeException("Please provide token"); + } + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); clientOptionsBuilder.environment(this.environment); return new SeedSingleUrlEnvironmentNoDefaultClient(clientOptionsBuilder.build()); } diff --git a/seed/java-sdk/trace/src/main/java/com/seed/trace/SeedTraceClientBuilder.java b/seed/java-sdk/trace/src/main/java/com/seed/trace/SeedTraceClientBuilder.java index 95110d543f8..4fa890dfe23 100644 --- a/seed/java-sdk/trace/src/main/java/com/seed/trace/SeedTraceClientBuilder.java +++ b/seed/java-sdk/trace/src/main/java/com/seed/trace/SeedTraceClientBuilder.java @@ -9,15 +9,25 @@ public final class SeedTraceClientBuilder { private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private String token = null; + + private String xRandomHeader = null; + private Environment environment = Environment.PROD; + /** + * Sets token + */ public SeedTraceClientBuilder token(String token) { - this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + this.token = token; return this; } + /** + * Sets xRandomHeader + */ public SeedTraceClientBuilder xRandomHeader(String xRandomHeader) { - this.clientOptionsBuilder.addHeader("X-Random-Header", xRandomHeader); + this.xRandomHeader = xRandomHeader; return this; } @@ -32,6 +42,8 @@ public SeedTraceClientBuilder url(String url) { } public SeedTraceClient build() { + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token); + this.clientOptionsBuilder.addHeader("X-Random-Header", this.xRandomHeader); clientOptionsBuilder.environment(this.environment); return new SeedTraceClient(clientOptionsBuilder.build()); }