Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up JDK 8 and maven cache
- name: Set up JDK 11 and maven cache
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
java-version: '8'
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Add virtual env entry to hosts file
run: echo "127.0.0.1 vip.ve.atsign.zone" | sudo tee -a /etc/hosts
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/maven-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up JDK 8
- name: Set up JDK 11
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
java-version: '8'
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
server-id: central # Value of the distributionManagement/repository/id field of the pom.xml
server-username: "CENTRAL_USERNAME" # env variable for username in deploy
server-password: "CENTRAL_TOKEN" # env variable for token in deploy
Expand Down
231 changes: 101 additions & 130 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,170 +8,141 @@
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/atsign-foundation/at_java/badge)](https://securityscorecards.dev/viewer/?uri=github.com/atsign-foundation/at_java&sort_by=check-score&sort_direction=desc)
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/8116/badge)](https://www.bestpractices.dev/projects/8116)

## The atPlatform for Java developers

This repo contains libraries, tools, samples and examples for developers who wish
to work with the atPlatform from Java code.

## Maven Dependency

The Java SDK can be added to your project through a compiled JAR or by Maven!

```xml
<repositories>
<repository>
<name>Central Portal Snapshots</name>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.atsign</groupId>
<artifactId>at_client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
```
## The Atsign Platform for Java developers

## Getting Started
This repository contains libraries, tools, samples and examples for developers that
wish to work with the Atsign Platform from Java code.

### Prerequisites
## Modules

* Java (JDK 8)
* Maven
There are 4 modules.

### Steps
1. **at_client** is the Java SDK for interacting with the Atsign Platform
[README](at_client/README.md).
2. **at_shell** is a self-contained "fatjar" that provides an interactive command
line interface for performing various operations and tests
[README](at_shell/README.md).
3. **at_utils** contains useful code which is not part of the SDK
[README](at_utils/README.md).
4. **examples** contains sample code which illustrates how to use the SDK
[README](examples/README.md).

Clone the at_java repo from GitHub using
## Build Process

```shell
git clone https://github.com/atsign-foundation/at_java.git
```
### Prerequisites

Change directory into at_java/at_client
* Java (JDK 11 or above)
* Maven (3.6.3 or above)

```shell
cd at_client
```

Compile the package using maven with the following command
Check out, build and test with the following commands:

```shell
```text
git clone https://github.com/atsign-foundation/at_java.git
mvn install
```

Now that the programs have been compiled, execute the following command to use at_java
**Note:** The integration tests rely on the virtual env. The tests
will attempt to start a docker container with this image but that relies
on dockerd (or desktop docker). If you want to skip these tests then add
**-DskipITs**. See subsequent section for more information.

```shell
java -cp "target/at_client-1.0-SNAPSHOT.jar:target/lib/*" \
org.atsign.client.cli.<class> [required arguments]
## Unit Tests

These have no external dependencies and are run as part of the maven **test**
lifecycle. The surefire plugin will pick up classes that end in the following:

```text
**/*Test.java
**/*Tests.java
**/*TestCase.java
```

## Main Classes
Use **-DskipTests** to avoid running unit tests.

### Integration Tests

1) REPL
2) Share
3) Get
4) Delete
5) Register
6) Activate
These depend on running the atsign virtual environment and are run as part
of the maven **verify** lifecycle. The failsafe plugin will pick up classes that
end in the following:

**Note:** Each of these classes requires a different set of arguments, make
sure to read the help text and provide necessary arguments.
```text
**/*IT.java
```

### Register
Use **-DskipITs** to avoid running integration tests.

A class that accepts command line arguments which are used to fetch a free
atsign and register it to the email provided. Further, this atsign can be
activated using a verification code sent to the registered email.
The integration tests check to see if a virtual env is running. If not they will
attempt to start one. This requires dockerd or desktop docker to be running.

To run use the following command:
For CI, "standing up" and then "tearing down" the docker container is the intended
behavior. However, for a developer this will be slow so it's preferable to "standup"
the virtual env independently, like this:

```shell
java -cp "target/at_client-1.0-SNAPSHOT.jar:target/lib/*" \
org.atsign.client.cli.Register -e email@example.com
cd at_client/src/test/resources/org/atsign/virtualenv
docker compose -f up
```

### Register with SUPER_API Key
The start-up can take a few minutes and involves running scripts that install the
test configuration. The environment is ready to test with when you see the
following log output:

Register can also be used with a SUPER_API Key that has privileges to preset
and atsign with an activation code.
```text
...
virtualenv-1 | SHOUT|...| install_PKAM_Keys |cramAndPkamAuth successful for @chris
virtualenv-1 | SHOUT|...| install_PKAM_Keys |cramAndPkamAuth successful for @policy1
virtualenv-1 | SHOUT|...| install_PKAM_Keys |cramAndPkamAuth successful for @emoji
```

The tests require test keys (CRAM keys and atKeys) which the virtual env was
built with. The pom contains a plugin which downloads the
[at_demo_data](https://pub.dev/packages/at_demo_data) package and unpacks it
under target. When the tests run this is where they expect to find keys. The
release version is specified as property in the POM and needs to be periodically
updated to the latest release.

To run use the following command:
**Note:** The integration tests are designed to reset the virtual env as best as
possible. This relies on teardown steps. If you are debugging tests and terminate
the execution then this can leave the virtual env in an unreset state. Running
the test again might fail because of this BUT that teardown should successfully
reset the env and allow the next run to succeed. In extreme circumstances it may
be necessary to reset the docker container, like this:

```shell
java -cp "target/at_client-1.0-SNAPSHOT.jar:target/lib/*" \
org.atsign.client.cli.Register -k <SUPER_API Key>
cd at_client/src/test/resources/org/atsign/virtualenv
docker compose -f down
docker compose -f up
```

When using the SUPER_API Key to register an atsign, the following sequence of
calls take place:
1) User provides at_java/Register with the SUPER_API Key passed as an argument
2) at_java calls the AtSign Registrar API* Endpoint(get-atsign) with the
SUPER_API Key provided
3) The AtSign registrar API responds with an AtSign-ActivationKey pair
4) at_java now call the AtSign Registrar API* Endpoint(activate-atsign) with
the AtSign-ActivationKey pair
5) The API responds with a json containing the CRAM_KEY* for the concerned
atsign
6) This CRAM_KEY* can be used to activate the atsign further making it usable
7) at_java does the activation automatically for you and stores your atKeys*
file at path '~/.atsign/keys'
8) Now the atsign is activated and the atKeys file can be used to
authenticate and perform protected operation with/on the atSign.

### Things to know about at_platform

1) Register: This is a class in at_java that has the functionality to call
the necessary API, handle responses in order to fetch and register atsigns.
2) AtSign Registrar API: An AtSign service that is responsible for handling
atsign's server creation, registration, authentication, reset and deletion.
3) SUPER_API Key
* All calls to the AtSign Registrar API require an API_KEY. But the
SUPER_API Key has some additional privileges.
* SUPER_API Keys have the privilege to preset an AtSign with an activation
key so that this AtSign can be activated without manually entering a
verification code that is sent to the registered email.
* All SUPER_API Keys have a name containing two elements [say pre and
post], all the atsigns generated using this API_Key will be of the
following format: (pre)atsign(post). Now the atsign will be @preatsignpost.
This is done to separate atsigns generated using SUPER_API Keys to the
atsigns that are generated through other methods.
4) CRAM_KEY: This is an authentication key that will be used for a one-time
authentication to activate an atsign which allows for assigning random,
secure non-symmetric keypairs which will be further stored in the users
atKeys file.
* Note: CRAM_KEY will be deleted from the atsign server after an atKeys
file has been generated, so only you have the keys to authenticate into
your atsign.
5) atKeys file: This will be a file generated during activation of an atsign
that stores all the keys necessary for authenticating into atSign
* That would mean users have to keep this file in a secured location
* Users should keep this file safe, as there's only one copy of this file
and losing it would mean the user would be unable to log in to the atsign.
* If lost, users can reset the atsign and get a new atKeys file. This
would result in loss of all data stored in the atsign's server.

### Code Style And Formatting

The maven pom contains the following plugins to enforce a consistent coding
## Virtual Environment

This is a docker image that bundles the following:

* redis
* root server
* multiple at_servers in different states of configuration

The docker image is published as part of the
[at_server](https://github.com/atsign-foundation/at_server) repository.

The keys (CRAM secrets, pre-cut AtKeys) are part the
[at_demos](https://github.com/atsign-foundation/at_demos) repository.

The pom.xml for modules which run have integration tests include a plugin
which downloads the at_demos package to target.

## Code Style And Formatting

The maven poms contain the following plugins to enforce a consistent coding
style and format.

* [checkstyle](https://checkstyle.org)
* [spotless](https://github.com/diffplug/spotless)

The rules which configure the respective plugins are here

* [config/checkstyle.xml](config/checkstyle.xml)
* [config/java-format.xml](config/java-format.xml)
* [checkstyle.xml](config/checkstyle.xml)
* [java-format.xml](config/java-format.xml)

Run the following maven command run the checks:

Expand All @@ -185,17 +156,17 @@ Run the following maven command to fix the spotless violations:
mvn spotless:apply
```

#### Intellij
### Intellij

To configure Intellij to use the same settings
1. Add the **Adaptor for Eclopse Code Formatter** plugin and configure in
1. Add the **Adaptor for Eclipse Code Formatter** plugin and configure in
**Settings -> Adaptor for Eclipse Code Formatter** by setting
**Eclipse workspace/project folder or config file** as
config/java-format.xml
2. Add **CheckStyle-IDEA** plugin and configure in
**Settings -> Tools -> Checkstyle** by adding config/checkstyle.xml

### Contributions welcome
## Contributions welcome

All of our software is open with intent. We welcome contributions - we want
pull requests, and we want to hear about issues. See also
Expand Down
Loading
Loading