Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ java -cp "target/at_client-1.0-SNAPSHOT.jar:target/lib/*" org.atsign.client.cli.
3) Get
4) Delete
5) Register
6) Onboard
6) Activate

#### Note: Each of these classes requires a different set of arguments, make sure to read the help text and provide necessary arguments
** Text about the remaining functionalities coming soon **
Expand Down
19 changes: 13 additions & 6 deletions at_client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,19 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
75 changes: 41 additions & 34 deletions at_client/src/main/java/org/atsign/client/api/AtClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
import org.atsign.client.api.impl.connections.DefaultAtConnectionFactory;
import org.atsign.client.api.impl.events.SimpleAtEventBus;
import org.atsign.client.api.impl.secondaries.RemoteSecondary;
import org.atsign.client.util.KeysUtil;
import org.atsign.common.AtException;
import org.atsign.common.AtSign;
import org.atsign.common.exceptions.AtClientConfigException;
import org.atsign.common.exceptions.AtSecondaryConnectException;
import org.atsign.common.exceptions.AtSecondaryNotFoundException;
import org.atsign.common.options.GetRequestOptions;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import static org.atsign.common.Keys.*;
Expand All @@ -24,57 +22,70 @@
* The primary interface of the AtSign client library.
*/
@SuppressWarnings("unused")
public interface AtClient extends Secondary, AtEvents.AtEventBus {
public interface AtClient extends Secondary, AtEvents.AtEventBus, Closeable {

/**
* Standard AtClient factory - uses production @ root to look up the cloud secondary address for this atSign
* @param atSign the atsign of this client
* @param atSign the {@link AtSign} of this client - e.g. @alice
* @param keys the {@link AtKeys} for this client
* @return An {@link AtClient}
* @throws AtException if something goes wrong with looking up or connecting to the remote secondary
*/
static AtClient withRemoteSecondary(AtSign atSign) throws AtException {
return withRemoteSecondary("root.atsign.org:64", atSign);
static AtClient withRemoteSecondary(AtSign atSign, AtKeys keys) throws AtException {
return withRemoteSecondary("root.atsign.org:64", atSign, keys);
}
/**
* Standard AtClient factory - uses production @ root to look up the cloud secondary address for this atSign
* @param atSign the atsign of this client
* @param atSign the {@link AtSign} of this client - e.g. @alice
* @param keys the {@link AtKeys} for this client
* @param verbose set to true for chatty logs
* @return An {@link AtClient}
* @throws AtException if something goes wrong with looking up or connecting to the remote secondary
*/
static AtClient withRemoteSecondary(AtSign atSign, boolean verbose) throws AtException {
return withRemoteSecondary("root.atsign.org:64", atSign, verbose);
static AtClient withRemoteSecondary(AtSign atSign, AtKeys keys, boolean verbose) throws AtException {
return withRemoteSecondary("root.atsign.org:64", atSign, keys, verbose);
}

/**
* Factory to use when you wish to use a custom Secondary.AddressFinder
* @param atSign the atSign of this client
* @param atSign the {@link AtSign} of this client - e.g. @alice
* @param keys the {@link AtKeys} for this client
* @param secondaryAddressFinder will be used to find the Secondary.Address of the atSign
* @return An {@link AtClient}
* @throws AtException if any other exception occurs while connecting to the remote (cloud) secondary
*/
static AtClient withRemoteSecondary(AtSign atSign, Secondary.AddressFinder secondaryAddressFinder) throws AtException {
static AtClient withRemoteSecondary(AtSign atSign, AtKeys keys, Secondary.AddressFinder secondaryAddressFinder) throws AtException {
Secondary.Address remoteSecondaryAddress;
try {
remoteSecondaryAddress = secondaryAddressFinder.findSecondary(atSign);
} catch (IOException e) {
throw new AtSecondaryConnectException("Failed to find secondary, with IOException", e);
}
return withRemoteSecondary(atSign, remoteSecondaryAddress, false);
return withRemoteSecondary(atSign, keys, remoteSecondaryAddress, false);
}

/**
* Factory - returns default AtClientImpl with a RemoteSecondary and a DefaultConnectionFactory
* @param rootUrl the address of the root server to use - e.g. root.atsign.org:64 for production at-signs
* @param atSign the atSign of the client - e.g. @alice
* @param atSign the {@link AtSign} of this client - e.g. @alice
* @param keys the {@link AtKeys} for this client
* @return An {@link AtClient}
* @throws AtException if anything goes wrong during construction
*/
static AtClient withRemoteSecondary(String rootUrl, AtSign atSign) throws AtException {
return withRemoteSecondary(rootUrl, atSign, false);
static AtClient withRemoteSecondary(String rootUrl, AtSign atSign, AtKeys keys) throws AtException {
return withRemoteSecondary(rootUrl, atSign, keys, false);
}

static AtClient withRemoteSecondary(String rootUrl, AtSign atSign, boolean verbose) throws AtException {
/**
* Factory - returns default AtClientImpl with a RemoteSecondary and a DefaultConnectionFactory
* @param rootUrl the address of the root server to use - e.g. root.atsign.org:64 for production at-signs
* @param atSign the {@link AtSign} of this client - e.g. @alice
* @param keys the {@link AtKeys} for this client
* @param verbose set to true for chatty logs
* @return An {@link AtClient}
* @throws AtException if anything goes wrong during construction
*/
static AtClient withRemoteSecondary(String rootUrl, AtSign atSign, AtKeys keys, boolean verbose) throws AtException {
DefaultAtConnectionFactory connectionFactory = new DefaultAtConnectionFactory();

Secondary.Address secondaryAddress;
Expand All @@ -88,41 +99,36 @@ static AtClient withRemoteSecondary(String rootUrl, AtSign atSign, boolean verbo
throw new AtSecondaryNotFoundException("Failed to lookup remote secondary", e);
}

return withRemoteSecondary(atSign, secondaryAddress, verbose);
return withRemoteSecondary(atSign, keys, secondaryAddress, verbose);
}

/**
* Factory to use when you wish to use a custom Secondary.AddressFinder
* @param atSign the atSign of this client
* @param atSign the {@link AtSign} of this client - e.g. @alice
* @param keys the {@link AtKeys} for this client
* @param verbose set to true for chatty logs
* @return An {@link AtClient}
* @throws IOException if thrown by the address finder
* @throws AtException if any other exception occurs while connecting to the remote (cloud) secondary
*/
static AtClient withRemoteSecondary(AtSign atSign, Secondary.AddressFinder secondaryAddressFinder, boolean verbose) throws IOException, AtException {
static AtClient withRemoteSecondary(AtSign atSign, AtKeys keys, Secondary.AddressFinder secondaryAddressFinder, boolean verbose) throws IOException, AtException {
Secondary.Address remoteSecondaryAddress = secondaryAddressFinder.findSecondary(atSign);
return withRemoteSecondary(atSign, remoteSecondaryAddress, verbose);
return withRemoteSecondary(atSign, keys, remoteSecondaryAddress, verbose);
}

/**
* Factory to use when you already know the address of the remote (cloud) secondary
* @param atSign the atSign of this client
* @param atSign the {@link AtSign} of this client - e.g. @alice
* @param keys the {@link AtKeys} for this client
* @param remoteSecondaryAddress the address of the remote secondary server
* @param verbose set to true for chatty logs
* @return An {@link AtClient}
* @throws AtException if any other exception occurs while connecting to the remote (cloud) secondary
*/
static AtClient withRemoteSecondary(AtSign atSign, Secondary.Address remoteSecondaryAddress, boolean verbose) throws AtException {
static AtClient withRemoteSecondary(AtSign atSign, AtKeys keys, Secondary.Address remoteSecondaryAddress, boolean verbose) throws AtException {
DefaultAtConnectionFactory connectionFactory = new DefaultAtConnectionFactory();
AtEvents.AtEventBus eventBus = new SimpleAtEventBus();

Map<String, String> keys;
try {
keys = KeysUtil.loadKeys(atSign);
} catch (Exception e) {
throw new AtClientConfigException("Failed to load keys", e);
}

RemoteSecondary secondary;
try {
secondary = new RemoteSecondary(eventBus, atSign, remoteSecondaryAddress, keys, connectionFactory, verbose);
Expand All @@ -135,20 +141,21 @@ static AtClient withRemoteSecondary(AtSign atSign, Secondary.Address remoteSecon

/**
* Factory to use when you already know the address of the remote (cloud) secondary
* @param atSign the atSign of this client
* @param remoteSecondaryAddress the address of the remote secondary server
* @param atSign the {@link AtSign} of this client - e.g. @alice
* @param keys the {@link AtKeys} for this client
* @return An {@link AtClient}
* @throws AtException if any other exception occurs while connecting to the remote (cloud) secondary
*/
static AtClient withRemoteSecondary(Secondary.Address remoteSecondaryAddress, AtSign atSign) throws AtException {
return withRemoteSecondary(atSign, remoteSecondaryAddress, false);
static AtClient withRemoteSecondary(Secondary.Address remoteSecondaryAddress, AtSign atSign, AtKeys keys) throws AtException {
return withRemoteSecondary(atSign, keys, remoteSecondaryAddress, false);
}



AtSign getAtSign();
Secondary getSecondary();
Map<String, String> getEncryptionKeys();
AtKeys getEncryptionKeys();

CompletableFuture<String> get(SharedKey sharedKey);
CompletableFuture<byte[]> getBinary(SharedKey sharedKey);
Expand Down
Loading
Loading