Skip to content
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

Asabu orgs cluster test #800

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/twilio/Domains.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum Domains {
NUMBERS("numbers"),
OAUTH("oauth"),
PREVIEW("preview"),
PREVIEWIAM("preview-iam"),
PRICING("pricing"),
PROXY("proxy"),
ROUTES("routes"),
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/com/twilio/TwilioBearerTokenAuth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.twilio;

import com.twilio.annotations.Preview;
import com.twilio.exception.AuthenticationException;
import com.twilio.http.bearertoken.BearerTokenTwilioRestClient;
import lombok.Getter;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Preview
public class TwilioBearerTokenAuth {
private static String accessToken;
@Getter
private static List<String> userAgentExtensions;
private static String region = System.getenv("TWILIO_REGION");
private static String edge = System.getenv("TWILIO_EDGE");
private static volatile BearerTokenTwilioRestClient restClient;

private static volatile ExecutorService executorService;

private TwilioBearerTokenAuth() {
}

public static synchronized void init(final String accessToken) {
if (accessToken == null || accessToken.isEmpty()) {
throw new AuthenticationException("Access Token can not be null or Empty");
}
if (!accessToken.equals(TwilioBearerTokenAuth.accessToken)) {
TwilioBearerTokenAuth.invalidate();
}
TwilioBearerTokenAuth.accessToken = accessToken;
}

public static BearerTokenTwilioRestClient getRestClient() {
if (TwilioBearerTokenAuth.restClient == null) {
synchronized (TwilioBearerTokenAuth.class) {
if (TwilioBearerTokenAuth.restClient == null) {
TwilioBearerTokenAuth.restClient = buildOAuthRestClient();
}
}
}
return TwilioBearerTokenAuth.restClient;
}
/**
* Returns the Twilio executor service.
*
* @return the Twilio executor service
*/
public static ExecutorService getExecutorService() {
if (TwilioBearerTokenAuth.executorService == null) {
synchronized (TwilioBearerTokenAuth.class) {
if (TwilioBearerTokenAuth.executorService == null) {
TwilioBearerTokenAuth.executorService = Executors.newCachedThreadPool();
}
}
}
return TwilioBearerTokenAuth.executorService;
}

private static BearerTokenTwilioRestClient buildOAuthRestClient() {

BearerTokenTwilioRestClient.Builder builder = new BearerTokenTwilioRestClient.Builder(accessToken);

if (userAgentExtensions != null) {
builder.userAgentExtensions(TwilioBearerTokenAuth.userAgentExtensions);
}

builder.region(TwilioBearerTokenAuth.region);
builder.edge(TwilioBearerTokenAuth.edge);

return builder.build();
}

/**
* Invalidates the volatile state held in the Twilio singleton.
*/
private static void invalidate() {
TwilioBearerTokenAuth.restClient = null;
}


}
48 changes: 48 additions & 0 deletions src/main/java/com/twilio/TwilioNoAuth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.twilio;

import com.twilio.annotations.Preview;
import com.twilio.http.noauth.NoAuthTwilioRestClient;
import lombok.Getter;

import java.util.List;
import com.twilio.exception.AuthenticationException;

@Preview
public class TwilioNoAuth {
@Getter
private static List<String> userAgentExtensions;
private static String region = System.getenv("TWILIO_REGION");
private static String edge = System.getenv("TWILIO_EDGE");

private static volatile NoAuthTwilioRestClient noAuthTwilioRestClient;

private TwilioNoAuth() {
}

public static NoAuthTwilioRestClient getRestClient() {
if (TwilioNoAuth.noAuthTwilioRestClient == null) {
synchronized (TwilioNoAuth.class) {
if (TwilioNoAuth.noAuthTwilioRestClient == null) {
TwilioNoAuth.noAuthTwilioRestClient = buildOAuthRestClient();
}
}
}
return TwilioNoAuth.noAuthTwilioRestClient;
}

private static NoAuthTwilioRestClient buildOAuthRestClient() {

NoAuthTwilioRestClient.Builder builder = new NoAuthTwilioRestClient.Builder();

if (userAgentExtensions != null) {
builder.userAgentExtensions(TwilioNoAuth.userAgentExtensions);
}

builder.region(TwilioNoAuth.region);
builder.edge(TwilioNoAuth.edge);

return builder.build();
}


}
9 changes: 9 additions & 0 deletions src/main/java/com/twilio/annotations/Beta.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.twilio.annotations;

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Beta {
String value() default "This class/method is under beta and is subjected to change. Use with caution.";
}
12 changes: 12 additions & 0 deletions src/main/java/com/twilio/annotations/Preview.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.twilio.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Preview {
String value() default "This class/method is under preview and is subjected to change. Use with caution.";
}
50 changes: 50 additions & 0 deletions src/main/java/com/twilio/base/bearertoken/Creator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.twilio.base.bearertoken;

import com.twilio.TwilioBearerTokenAuth;
import com.twilio.http.bearertoken.BearerTokenTwilioRestClient;

import java.util.concurrent.CompletableFuture;

/**
* Executor for creation of a resource.
*
* @param <T> type of the resource
*/
public abstract class Creator<T extends Resource> {

/**
* Execute an async request using default client.
*
* @return future that resolves to requested object
*/
public CompletableFuture<T> createAsync() {
return createAsync(TwilioBearerTokenAuth.getRestClient());
}

/**
* Execute an async request using specified client.
*
* @param client client used to make request
* @return future that resolves to requested object
*/
public CompletableFuture<T> createAsync(final BearerTokenTwilioRestClient client) {
return CompletableFuture.supplyAsync(() -> create(client), TwilioBearerTokenAuth.getExecutorService());
}

/**
* Execute a request using default client.
*
* @return Requested object
*/
public T create() {
return create(TwilioBearerTokenAuth.getRestClient());
}

/**
* Execute a request using specified client.
*
* @param client client used to make request
* @return Requested object
*/
public abstract T create(final BearerTokenTwilioRestClient client);
}
51 changes: 51 additions & 0 deletions src/main/java/com/twilio/base/bearertoken/Deleter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.twilio.base.bearertoken;

import com.twilio.Twilio;
import com.twilio.TwilioBearerTokenAuth;
import com.twilio.http.bearertoken.BearerTokenTwilioRestClient;

import java.util.concurrent.CompletableFuture;

/**
* Executor for deletes of a resource.
*
* @param <T> type of the resource
*/
public abstract class Deleter<T extends Resource> {

/**
* Execute an async request using default client.
*
* @return future that resolves to true if the object was deleted
*/
public CompletableFuture<Boolean> deleteAsync() {
return deleteAsync(TwilioBearerTokenAuth.getRestClient());
}

/**
* Execute an async request using specified client.
*
* @param client client used to make request
* @return future that resolves to true if the object was deleted
*/
public CompletableFuture<Boolean> deleteAsync(final BearerTokenTwilioRestClient client) {
return CompletableFuture.supplyAsync(() -> delete(client), Twilio.getExecutorService());
}

/**
* Execute a request using default client.
*
* @return true if the object was deleted
*/
public boolean delete() {
return delete(TwilioBearerTokenAuth.getRestClient());
}

/**
* Execute a request using specified client.
*
* @param client client used to make request
* @return true if the object was deleted
*/
public abstract boolean delete(final BearerTokenTwilioRestClient client);
}
50 changes: 50 additions & 0 deletions src/main/java/com/twilio/base/bearertoken/Fetcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.twilio.base.bearertoken;

import com.twilio.TwilioBearerTokenAuth;
import com.twilio.http.bearertoken.BearerTokenTwilioRestClient;

import java.util.concurrent.CompletableFuture;

/**
* Executor for fetches of a resource.
*
* @param <T> type of the resource
*/
public abstract class Fetcher<T extends Resource> {

/**
* Execute an async request using default client.
*
* @return future that resolves to requested object
*/
public CompletableFuture<T> fetchAsync() {
return fetchAsync(TwilioBearerTokenAuth.getRestClient());
}

/**
* Execute an async request using specified client.
*
* @param client client used to make request
* @return future that resolves to requested object
*/
public CompletableFuture<T> fetchAsync(final BearerTokenTwilioRestClient client) {
return CompletableFuture.supplyAsync(() -> fetch(client), TwilioBearerTokenAuth.getExecutorService());
}

/**
* Execute a request using default client.
*
* @return Requested object
*/
public T fetch() {
return fetch(TwilioBearerTokenAuth.getRestClient());
}

/**
* Execute a request using specified client.
*
* @param client client used to make request
* @return Requested object
*/
public abstract T fetch(final BearerTokenTwilioRestClient client);
}
Loading
Loading