|
32 | 32 | import java.io.File;
|
33 | 33 | import java.nio.charset.StandardCharsets;
|
34 | 34 | import java.nio.file.Files;
|
35 |
| -import java.util.ArrayList; |
36 |
| -import java.util.Arrays; |
37 | 35 | import java.util.List;
|
38 | 36 | import java.util.function.Consumer;
|
39 | 37 |
|
40 | 38 | import static com.mongodb.assertions.Assertions.isTrueArgument;
|
| 39 | +import static com.mongodb.internal.connection.FaasEnvironment.getFaasEnvironment; |
41 | 40 | import static java.lang.String.format;
|
42 | 41 | import static java.lang.System.getProperty;
|
43 | 42 | import static java.nio.file.Paths.get;
|
@@ -180,61 +179,6 @@ static boolean clientMetadataDocumentTooLarge(final BsonDocument document) {
|
180 | 179 | new BsonDocumentCodec().encode(new BsonBinaryWriter(buffer), document, EncoderContext.builder().build());
|
181 | 180 | return buffer.getPosition() > MAXIMUM_CLIENT_METADATA_ENCODED_SIZE;
|
182 | 181 | }
|
183 |
| - private enum FaasEnvironment { |
184 |
| - AWS_LAMBDA("aws.lambda"), |
185 |
| - AZURE_FUNC("azure.func"), |
186 |
| - GCP_FUNC("gcp.func"), |
187 |
| - VERCEL("vercel"), |
188 |
| - UNKNOWN(null); |
189 |
| - |
190 |
| - @Nullable |
191 |
| - private final String name; |
192 |
| - |
193 |
| - FaasEnvironment(@Nullable final String name) { |
194 |
| - this.name = name; |
195 |
| - } |
196 |
| - |
197 |
| - @Nullable |
198 |
| - public String getName() { |
199 |
| - return name; |
200 |
| - } |
201 |
| - |
202 |
| - @Nullable |
203 |
| - public Integer getTimeoutSec() { |
204 |
| - switch (this) { |
205 |
| - case GCP_FUNC: |
206 |
| - return getEnvInteger("FUNCTION_TIMEOUT_SEC"); |
207 |
| - default: |
208 |
| - return null; |
209 |
| - } |
210 |
| - } |
211 |
| - |
212 |
| - @Nullable |
213 |
| - public Integer getMemoryMb() { |
214 |
| - switch (this) { |
215 |
| - case AWS_LAMBDA: |
216 |
| - return getEnvInteger("AWS_LAMBDA_FUNCTION_MEMORY_SIZE"); |
217 |
| - case GCP_FUNC: |
218 |
| - return getEnvInteger("FUNCTION_MEMORY_MB"); |
219 |
| - default: |
220 |
| - return null; |
221 |
| - } |
222 |
| - } |
223 |
| - |
224 |
| - @Nullable |
225 |
| - public String getRegion() { |
226 |
| - switch (this) { |
227 |
| - case AWS_LAMBDA: |
228 |
| - return System.getenv("AWS_REGION"); |
229 |
| - case GCP_FUNC: |
230 |
| - return System.getenv("FUNCTION_REGION"); |
231 |
| - case VERCEL: |
232 |
| - return System.getenv("VERCEL_REGION"); |
233 |
| - default: |
234 |
| - return null; |
235 |
| - } |
236 |
| - } |
237 |
| - } |
238 | 182 |
|
239 | 183 | public enum ContainerRuntime {
|
240 | 184 | DOCKER("docker") {
|
@@ -311,43 +255,6 @@ static Orchestrator determineExecutionOrchestrator() {
|
311 | 255 | }
|
312 | 256 | }
|
313 | 257 |
|
314 |
| - @Nullable |
315 |
| - private static Integer getEnvInteger(final String name) { |
316 |
| - try { |
317 |
| - String value = System.getenv(name); |
318 |
| - return Integer.parseInt(value); |
319 |
| - } catch (NumberFormatException e) { |
320 |
| - return null; |
321 |
| - } |
322 |
| - } |
323 |
| - |
324 |
| - static FaasEnvironment getFaasEnvironment() { |
325 |
| - List<FaasEnvironment> result = new ArrayList<>(); |
326 |
| - String awsExecutionEnv = System.getenv("AWS_EXECUTION_ENV"); |
327 |
| - |
328 |
| - if (System.getenv("VERCEL") != null) { |
329 |
| - result.add(FaasEnvironment.VERCEL); |
330 |
| - } |
331 |
| - if ((awsExecutionEnv != null && awsExecutionEnv.startsWith("AWS_Lambda_")) |
332 |
| - || System.getenv("AWS_LAMBDA_RUNTIME_API") != null) { |
333 |
| - result.add(FaasEnvironment.AWS_LAMBDA); |
334 |
| - } |
335 |
| - if (System.getenv("FUNCTIONS_WORKER_RUNTIME") != null) { |
336 |
| - result.add(FaasEnvironment.AZURE_FUNC); |
337 |
| - } |
338 |
| - if (System.getenv("K_SERVICE") != null || System.getenv("FUNCTION_NAME") != null) { |
339 |
| - result.add(FaasEnvironment.GCP_FUNC); |
340 |
| - } |
341 |
| - // vercel takes precedence over aws.lambda |
342 |
| - if (result.equals(Arrays.asList(FaasEnvironment.VERCEL, FaasEnvironment.AWS_LAMBDA))) { |
343 |
| - return FaasEnvironment.VERCEL; |
344 |
| - } |
345 |
| - if (result.size() != 1) { |
346 |
| - return FaasEnvironment.UNKNOWN; |
347 |
| - } |
348 |
| - return result.get(0); |
349 |
| - } |
350 |
| - |
351 | 258 | static MongoDriverInformation getDriverInformation(@Nullable final MongoDriverInformation mongoDriverInformation) {
|
352 | 259 | MongoDriverInformation.Builder builder = mongoDriverInformation != null ? MongoDriverInformation.builder(mongoDriverInformation)
|
353 | 260 | : MongoDriverInformation.builder();
|
|
0 commit comments