Skip to content

Commit

Permalink
Merge pull request #348 from atsign-foundation/xlin-repl-prepublish
Browse files Browse the repository at this point in the history
chore(at_repl): prepublish changes / pub score
  • Loading branch information
Xlin123 authored Jul 3, 2023
2 parents aad9dfd + 53b6264 commit 5e20c7c
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 46 deletions.
13 changes: 8 additions & 5 deletions packages/at_repl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
## 1.0.0
## 1.0.2

- Initial version.
- feat: added tests
- feat: more verbose exceptions

## 1.0.1

- Fixed very obvious bugs
- fix: improper formatting of shared keys
- fix: modified namespace formatting

## 1.0.2
## 1.0.0

- feat: initial version.

- A more proper release.

20 changes: 12 additions & 8 deletions packages/at_repl/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
## at_repl

<img width=250px src="https://atsign.dev/assets/img/atPlatform_logo_gray.svg?sanitize=true">

[![pub package](https://img.shields.io/pub/v/at_repl)](https://pub.dev/packages/at_repl)
[![pub points](https://img.shields.io/badge/dynamic/json?url=https://pub.dev/api/packages/at_repl/score&label=pub%20score&query=grantedPoints)]([https://pub.dev/packages/at_repl](https://pub.dev/packages/at_repl/score))
[![pub points](https://img.shields.io/badge/dynamic/json?url=https://pub.dev/api/packages/at_repl/score&label=pub%20score&query=grantedPoints)](https://pub.dev/packages/at_repl/score)
[![gitHub license](https://img.shields.io/badge/license-BSD3-blue.svg)](./LICENSE)

A CLI application that talks directly to the atPlatform.

## Getting Started
## Getting Started

Ensure you have your atSign keys. Keys are usually located in `$HOME/.atsign/keys`.

If you don't have an atSign, visit here https://my.atsign.com/login.
If you don't have an atSign, visit here https://my.atsign.com/login.

If the CLI application is available on [pub](https://pub.dev), activate globally via:

Expand All @@ -21,17 +24,16 @@ Or locally via:

```sh
cd packages/at_repl
dart pub global activate . --s path
dart pub global activate . -s path
```

## Usage

-a, user's atsign (REQUIRED)
-r, root URL (defaults to root.atsign.org:64)
-r, root URL (defaults to root.atsign.org:64)
-v, verbose
-n, enforce namespaces (defaults to true)


```sh
#example of full REPL command
$ at_repl -a @xavierlin -r root.atsign.org:64 -v -n
Expand All @@ -40,7 +42,9 @@ $ at_repl -a @xavierlin -r root.atsign.org:64 -v -n
$ at_repl -a @xavierlin

```

Use /help or help for instructions/usage.

```sh
@chess69
```
@chess69 /help
```
53 changes: 37 additions & 16 deletions packages/at_repl/bin/at_repl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ Future<void> main(List<String> arguments) async {
abbr: 'a',
mandatory: true,
)
..addOption("rootUrl", abbr: 'r', mandatory: false, defaultsTo: "root.atsign.org:64")
..addOption("rootUrl",
abbr: 'r', mandatory: false, defaultsTo: "root.atsign.org:64")
..addFlag("verbose", abbr: 'v', defaultsTo: false)
..addFlag("enforceNamespace",
abbr: 'n', defaultsTo: true, help: "specifically for /put, if false namespaces will automatically by placed.");
abbr: 'n',
defaultsTo: true,
help:
"specifically for /put, if false namespaces will automatically by placed.");

final pubUpdater = PubUpdater();
final upToDate = await pubUpdater.isUpToDate(packageName: "at_repl", currentVersion: version.packageVersion);
final upToDate = await pubUpdater.isUpToDate(
packageName: "at_repl", currentVersion: version.packageVersion);
if (!upToDate) {
stdout.writeln(red.wrap("Package out of date, updating..."));
await pubUpdater.update(packageName: 'at_repl');
Expand All @@ -48,7 +53,8 @@ Future<void> main(List<String> arguments) async {
atSign = results["atSign"];
verbose = results["verbose"];
enforceNamespace = results["enforceNamespace"];
stdout.writeln("Looking up secondary server address for $atSign on $rootUrl");
stdout
.writeln("Looking up secondary server address for $atSign on $rootUrl");
} catch (e) {
stdout.writeln(red.wrap('Invalid arguments. Usage:\n${argParser.usage}'));
exit(1);
Expand Down Expand Up @@ -76,15 +82,20 @@ Future<void> main(List<String> arguments) async {
}

atClient = repl.atClient;
stdout.writeln(lightGreen.wrap("use /help or help to see available commands"));
stdout.writeln(
lightGreen.wrap("use /help or help to see available commands"));
} on PathNotFoundException catch (e) {
stdout.writeln(red.wrap('Authentication failed: You do not have the keys to this atSign'));
logger.info("$e :Could not authenticate atsign, either you don't own the keys or you have a typo in the atsign");
stdout.writeln(red.wrap(
'Authentication failed: You do not have the keys to this atSign'));
logger.info(
"$e :Could not authenticate atsign, either you don't own the keys or you have a typo in the atsign");

exit(2);
}

var namespaceMsg = (enforceNamespace ? "" : "Namespaces will default to impressed1 when needed.");
var namespaceMsg = (enforceNamespace
? ""
: "Namespaces will default to impressed1 when needed.");
stdout.writeln(yellow.wrap(namespaceMsg));

// 3. REPL!
Expand All @@ -97,7 +108,10 @@ Future<void> main(List<String> arguments) async {
try {
if (command.isNotEmpty) {
command = command.trim();
if (command == "help" || command.startsWith("_") || command.startsWith("/") || command.startsWith("\\")) {
if (command == "help" ||
command.startsWith("_") ||
command.startsWith("/") ||
command.startsWith("\\")) {
if (command != "help") {
command = command.substring(1);
}
Expand Down Expand Up @@ -171,41 +185,48 @@ void printHelpInstructions() {
stdout.writeln(
" 1) By default, REPL treats input as atProtocol commands. Use / for additional commands listed below");

stdout.write(" 2) In the usage examples below, it is assumed that the atSign being used is ");
stdout.write(
" 2) In the usage examples below, it is assumed that the atSign being used is ");
stdout.writeln(green.wrap("@alice \n"));
stdout.write(magenta.wrap(" help or /help"));
stdout.writeln("- print this help message \n");

stdout.write(magenta.wrap("/scan"));
stdout.write(green.wrap(" [regex] "));
stdout.writeln("- scan for all records, or all records whose keyNames match the regex (e.g. /scan test@alice.*) \n");
stdout.writeln(
"- scan for all records, or all records whose keyNames match the regex (e.g. /scan test@alice.*) \n");

stdout.write(magenta.wrap("/put"));
stdout.write(green.wrap(" <atKeyName> "));
stdout.write(lightBlue.wrap(" <value> "));
stdout.writeln("- create or update a record with the given atKeyName and with the supplied value \n For example: ");
stdout.writeln(
"- create or update a record with the given atKeyName and with the supplied value \n For example: ");

stdout.write(magenta.wrap(" /put"));
stdout.write(green.wrap(" test@alice "));
stdout.write(lightBlue.wrap(" secrets "));
stdout.writeln("-> will create or update a 'self' record (a record private just to @alice)");
stdout.writeln(
"-> will create or update a 'self' record (a record private just to @alice)");

stdout.write(magenta.wrap(" /put"));
stdout.write(green.wrap(" @bob:test@alice "));
stdout.write(lightBlue.wrap(" Hello, Bob! "));
stdout.writeln("-> will create or update a record encrypted for, and then shared with, @bob \n");
stdout.writeln(
"-> will create or update a record encrypted for, and then shared with, @bob \n");

stdout.write(magenta.wrap("/get"));
stdout.write(green.wrap(" <atKeyName> "));
stdout.writeln("- retrieve a value from the record with this atKeyName \n For example: ");
stdout.writeln(
"- retrieve a value from the record with this atKeyName \n For example: ");

stdout.write(magenta.wrap(" /get"));
stdout.write(green.wrap(" test@alice "));
stdout.writeln("- retrieve a value from test@alice. \n");

stdout.write(magenta.wrap("/delete"));
stdout.write(green.wrap(" <atKeyName> "));
stdout.writeln("- delete the record with this atKeyName (e.g. /delete test@alice) \n");
stdout.writeln(
"- delete the record with this atKeyName (e.g. /delete test@alice) \n");

stdout.write(magenta.wrap("/q or /quit"));
stdout.writeln("- will quit the REPL \n");
Expand Down
7 changes: 7 additions & 0 deletions packages/at_repl/example/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Activate Locally

![](https://github.com/atsign-foundation/at_tools/tree/trunk/packages/at_repl/example/local.gif)

## Usage

![](https://github.com/atsign-foundation/at_tools/tree/trunk/packages/at_repl/example/usage.gif)
Binary file added packages/at_repl/example/local.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/at_repl/example/usage.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 12 additions & 6 deletions packages/at_repl/lib/src/at_repl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class REPL {
..syncIntervalMins = 1
..rootDomain = rootUrl.split(':')[0]
..rootPort = int.parse(rootUrl.split(':')[1])
..atKeysFilePath = "${getHomeDirectory()}/.atsign/keys/${atSign}_key.atKeys";
..atKeysFilePath =
"${getHomeDirectory()}/.atsign/keys/${atSign}_key.atKeys";

_atOnboardingService = AtOnboardingServiceImpl(atSign, pref);
return _atOnboardingService.authenticate();
Expand All @@ -47,7 +48,8 @@ class REPL {
final String? response = (await rs.executeCommand(command, auth: true));

if (response == null) {
throw Exception('Result is null for some reason after executing command: $command');
throw Exception(
'Result is null for some reason after executing command: $command');
}

result = response;
Expand All @@ -61,7 +63,8 @@ class REPL {
throw Exception("Please enter a record ID - e.g. /get test@alice");
}
String id = args[1];
RegExp encryptedSharedKeyMatcher = RegExp(r'^shared_key\..+@.+|@.+:shared_key@.+');
RegExp encryptedSharedKeyMatcher =
RegExp(r'^shared_key\..+@.+|@.+:shared_key@.+');
if (id.contains(encryptedSharedKeyMatcher)) {
throw AtKeyException("The given key is a symmetric shared key.");
}
Expand All @@ -73,16 +76,19 @@ class REPL {
///puts the atKey to secondary server
Future<String> put(List<String> args, bool enforceNamespace) async {
if (args.length != 3) {
throw Exception("Please enter a record ID and a value - e.g. /put test@alice value");
throw Exception(
"Please enter a record ID and a value - e.g. /put test@alice value");
}
if (!enforceNamespace) {
if (!args[1].contains('.')) {
args[1] = "${args[1].substring(0, args[1].indexOf('@'))}.$namespace${args[1].substring(args[1].indexOf('@'))}";
args[1] =
"${args[1].substring(0, args[1].indexOf('@'))}.$namespace${args[1].substring(args[1].indexOf('@'))}";
}
}
String id = args[1];
String value = args[2];
RegExp encryptedSharedKeyMatcher = RegExp(r'^shared_key\..+@.+|@.+:shared_key@.+');
RegExp encryptedSharedKeyMatcher =
RegExp(r'^shared_key\..+@.+|@.+:shared_key@.+');
if (id.contains(encryptedSharedKeyMatcher)) {
throw AtKeyException("The given key is a symmetric shared key.");
}
Expand Down
6 changes: 4 additions & 2 deletions packages/at_repl/lib/src/repl_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class REPLListener implements SyncProgressListener {
void onSyncProgressEvent(SyncProgress syncProgress) {
if (syncProgress.localCommitIdBeforeSync! < syncProgress.serverCommitId!) {
_logger.info("Local is behind Remote, syncing to cloud.");
} else if (syncProgress.localCommitIdBeforeSync! > syncProgress.serverCommitId!) {
} else if (syncProgress.localCommitIdBeforeSync! >
syncProgress.serverCommitId!) {
_logger.info("Remote is behind Local, syncing locally.");
}

if (syncProgress.syncStatus == SyncStatus.failure || syncProgress.syncStatus == SyncStatus.success) {
if (syncProgress.syncStatus == SyncStatus.failure ||
syncProgress.syncStatus == SyncStatus.success) {
syncComplete = true;
}
if (syncProgress.syncStatus == SyncStatus.failure) {
Expand Down
4 changes: 2 additions & 2 deletions packages/at_repl/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_repl
description: A command line tool that interacts with the at_platform.
version: 1.0.1
description: A command line tool that interacts with the at_platform. Uses some custom functions as well as protocol verbs.
version: 1.0.2
repository: https://github.com/atsign-foundation/at_tools
environment:
sdk: ^3.0.0
Expand Down
35 changes: 28 additions & 7 deletions packages/at_repl/test/at_repl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ void main() async {
..showHiddenKeys = false
..sharedBy = '@chess69';

var verbResult =
await AtClientManager.getInstance().atClient.getRemoteSecondary()!.executeVerb(scanVerbBuilder, sync: true);
var verbResult = await AtClientManager.getInstance()
.atClient
.getRemoteSecondary()!
.executeVerb(scanVerbBuilder, sync: true);
var commandResult = await repl.executeCommand("scan\n");
expect(commandResult, verbResult);
});
Expand Down Expand Up @@ -63,7 +65,11 @@ void main() async {

//Happy Path :)
test("Put", () async {
List<String> args = ["put", "public:demotest.$namespace$atSign", "initial"];
List<String> args = [
"put",
"public:demotest.$namespace$atSign",
"initial"
];
String result = await repl.put(args, enforceNamespace);
expect(result.isNotEmpty, true);
});
Expand All @@ -73,7 +79,11 @@ void main() async {
expect(result, " => initial");
});
test("Update", () async {
List<String> args = ["put", "public:demotest.$namespace$atSign", "updated"];
List<String> args = [
"put",
"public:demotest.$namespace$atSign",
"updated"
];
String result = await repl.put(args, enforceNamespace);
expect(result.isNotEmpty, true);
});
Expand All @@ -93,7 +103,11 @@ void main() async {
group("Test REPL functions with shared keys", () {
final bool enforceNamespace = true;
test("Test Put", () async {
List<String> args = ["put", "@chess69lovely:demotest.$namespace$atSign", "initial"];
List<String> args = [
"put",
"@chess69lovely:demotest.$namespace$atSign",
"initial"
];
String result = await repl.put(args, enforceNamespace);
expect(result.isNotEmpty, true);
});
Expand All @@ -103,7 +117,11 @@ void main() async {
expect(result, " => initial");
});
test("Test Update from another atsign", () async {
List<String> args = ["put", "@chess69lovely:demotest.$namespace$atSign", "updated"];
List<String> args = [
"put",
"@chess69lovely:demotest.$namespace$atSign",
"updated"
];
String result = await repl.put(args, enforceNamespace);
expect(result.isNotEmpty, true);
});
Expand All @@ -114,7 +132,10 @@ void main() async {
});

test("Test Delete", () async {
List<String> args = ["delete", "$atSign:demotest.$namespace@chess69lovely"];
List<String> args = [
"delete",
"$atSign:demotest.$namespace@chess69lovely"
];
String result = await repl.delete(args);
expect(result, " => true");
});
Expand Down

0 comments on commit 5e20c7c

Please sign in to comment.