Skip to content

Commit

Permalink
Merge pull request #507 from atsign-foundation/refactor/noports_core
Browse files Browse the repository at this point in the history
refactor: noports core
  • Loading branch information
XavierChanth authored Oct 5, 2023
2 parents ff442ad + 0fb4db9 commit 4cb9e04
Show file tree
Hide file tree
Showing 87 changed files with 2,229 additions and 1,943 deletions.
6 changes: 4 additions & 2 deletions .github/composite/setup_entrypoints/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ inputs:
devicename:
description: Unique sshnp devicename
required: true
legacy_daemon:
description: Legacy daemon
required: false

runs:
using: composite
Expand All @@ -37,8 +40,7 @@ runs:
entrypoint_filename="sshnp_entrypoint.sh"
;;
esac
echo "entrypoint_filename: $entrypoint_filename"
./setup-sshnp-entrypoint.sh ${{ inputs.devicename }} ${{ inputs.sshnp_atsign }} ${{ inputs.sshnpd_atsign }} ${{ inputs.sshrvd_atsign }} "$entrypoint_filename"
./setup-sshnp-entrypoint.sh ${{ inputs.devicename }} ${{ inputs.sshnp_atsign }} ${{ inputs.sshnpd_atsign }} ${{ inputs.sshrvd_atsign }} "$entrypoint_filename" ${{ inputs.legacy_daemon || false }}
- name: Setup NPD entrypoint
shell: bash
Expand Down
30 changes: 30 additions & 0 deletions .github/composite/verify_cli_tags/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: verify_cli_tags
description: |
Ensures that the tag of sshnoports matches the tag of the composite.
runs:
using: composite
steps:
- name: Ensure pubspec.yaml matches version.dart
shell: bash
working-directory: ./packages/sshnoports
run: |
DART_TAG="v$(egrep -o '^const String version = "(.*)";' lib/version.dart | cut -d'"' -f2)"
PUBSPEC_TAG="v$(egrep -o '^version: (.*)$' pubspec.yaml | cut -d':' -f2 | tr -d '[:space:]')"
if [ "$PUBSPEC_TAG" != "$DART_TAG" ]; then
echo "Tag $PUBSPEC_TAG does not match version in version.dart: $DART_TAG"
exit 1
fi
- name: Ensure version.dart matches git ref (if current git ref is a version tag)
shell: bash
if: startsWith(github.ref, 'refs/tags/v')
working-directory: ./packages/sshnoports
run: |
# check version.dart
REF=${{ github.ref }}
TAG=${REF:10}
DART_TAG="v$(egrep -o '^const String version = "(.*)";' lib/version.dart | cut -d'"' -f2)"
if [ "$TAG" != "$DART_TAG" ]; then
echo "Tag $TAG does not match version in version.dart: $DART_TAG"
exit 1
fi
17 changes: 17 additions & 0 deletions .github/composite/verify_core_tags/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: verify_core_tags
description: |
Ensures that the tag of noports_core matches the tag of the composite.
runs:
using: composite
steps:
- name: Ensure pubspec.yaml matches version.dart
shell: bash
working-directory: ./packages/noports_core
run: |
DART_TAG="v$(grep -Po '^const String version = "(.*)";' lib/version.dart | cut -d'"' -f2)"
PUBSPEC_TAG="v$(egrep -o '^version: (.*)$' pubspec.yaml | cut -d':' -f2 | tr -d '[:space:]')"
if [ "$PUBSPEC_TAG" != "$DART_TAG" ]; then
echo "Tag $PUBSPEC_TAG does not match version in version.dart: $DART_TAG"
exit 1
fi
17 changes: 4 additions & 13 deletions .github/workflows/dockerhub_sshnpd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,9 @@ jobs:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0

- name: Ensure version matches tag
if: startsWith(github.ref, 'refs/tags/v')
working-directory: ./packages/sshnoports
run: |
# check version.dart
REF=${{ github.ref }}
TAG=${REF:10}
DART_TAG="v$(grep -Po '^const String version = "(.*)";' lib/version.dart | cut -d'"' -f2)"
if [ "$TAG" != "$DART_TAG" ]; then
echo "Tag $TAG does not match version in version.dart: $DART_TAG"
exit 1
fi
# verify tags
- uses: ./.github/workflows/verify_cli_tags
- uses: ./.github/workflows/verify_core_tags

- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
Expand All @@ -51,7 +42,7 @@ jobs:
- name: Build and push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: ./packages/sshnoports
context: .
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/end2end_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ jobs:
sshnpd_atsign: ${{ env.SSHNPD_ATSIGN }}
sshrvd_atsign: ${{ env[env.PROD_RVD_ATSIGN] }}
devicename: ${{ env.DEVICENAME }}
legacy_daemon: ${{ matrix.np == 'local' && matrix.npd == 'installer' }}

- name: Ensure entrypoints exist
working-directory: tests/end2end_tests/contexts
Expand Down Expand Up @@ -368,12 +369,14 @@ jobs:
matrix:
include:
- np: local
npd: latest
- np: latest
npd: v3.4.2
legacy_daemon: true
- np: v3.4.2
npd: local

- np: local
npd: v3.3.0
legacy_daemon: true
- np: v3.3.0
npd: local

Expand Down Expand Up @@ -415,6 +418,7 @@ jobs:
sshnpd_atsign: ${{ env.SSHNPD_ATSIGN }}
sshrvd_atsign: ${{ env[env.PROD_RVD_ATSIGN] }}
devicename: ${{ env.DEVICENAME }}
legacy_daemon: ${{ matrix.legacy_daemon || false }}

- name: Ensure entrypoints exist
working-directory: tests/end2end_tests/contexts
Expand Down Expand Up @@ -610,4 +614,4 @@ jobs:
continue-on-error: true # failing this step does not fail the entire job
working-directory: tests/end2end_tests/tests
run: |
docker compose down
docker compose down
36 changes: 8 additions & 28 deletions .github/workflows/multibuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
verify_tags:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- uses: ./.github/composite/verify_cli_tags
- uses: ./.github/composite/verify_core_tags
x64_build:
needs: verify_tags
runs-on: ${{ matrix.os }}
defaults:
run:
Expand All @@ -23,20 +30,6 @@ jobs:

steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0

- name: Ensure version matches tag
if: startsWith(github.ref, 'refs/tags/v')
working-directory: ./packages/sshnoports
run: |
# check version.dart
REF=${{ github.ref }}
TAG=${REF:10}
DART_TAG="v$(egrep -o '^const String version = "(.*)";' lib/version.dart | cut -d'"' -f2)"
if [ "$TAG" != "$DART_TAG" ]; then
echo "Tag $TAG does not match version in version.dart: $DART_TAG"
exit 1
fi
- uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 # v1.5.1
- run: mkdir sshnp
- run: mkdir tarball
Expand All @@ -56,6 +49,7 @@ jobs:
if-no-files-found: error

other_build:
needs: verify_tags
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -72,20 +66,6 @@ jobs:
output-name: sshnp-linux-riscv64
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0

- name: Ensure version matches tag
if: startsWith(github.ref, 'refs/tags/v')
working-directory: ./packages/sshnoports
run: |
# check version.dart
REF=${{ github.ref }}
TAG=${REF:10}
DART_TAG="v$(grep -Po '^const String version = "(.*)";' lib/version.dart | cut -d'"' -f2)"
if [ "$TAG" != "$DART_TAG" ]; then
echo "Tag $TAG does not match version in version.dart: $DART_TAG"
exit 1
fi
- uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
- uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
- run: |
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: unit_tests

permissions:
contents: read

on:
workflow_dispatch:
push:
branches:
- trunk

pull_request:
branches:
- trunk

jobs:
cli_tags:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- uses: ./.github/composite/verify_cli_tags
core_tags:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- uses: ./.github/composite/verify_core_tags
4 changes: 2 additions & 2 deletions .github/workflows/update_python_requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

permissions:
pull-requests: write

jobs:
bump_requirements:
runs-on: ubuntu-latest
Expand All @@ -32,7 +32,7 @@ jobs:
uses: abatilo/actions-poetry@192395c0d10c082a7c62294ab5d9a9de40e48974 # v2.3.0
with:
poetry-version: '1.6.1'

- name: Bump Python dependencies
if: ${{ github.actor == 'dependabot[bot]' }}
run: |
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ compose-dev.yaml
*.hash
*.atKeys

# Ignore pubspec.lock
pubspec.lock
# Ignore root pubspec.lock only
/pubspec.lock

# Conventional directory for build output.
build/
Expand Down
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pubspec.lock
1 change: 1 addition & 0 deletions packages/noports_core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pubspec.lock
4 changes: 2 additions & 2 deletions packages/noports_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# 4.0.0-dev.1
# 4.0.0

- Initial release based of the 4.0.0 pre-release code of sshnoports
- Initial release based off of the 4.0.0 pre-release code of sshnoports
14 changes: 11 additions & 3 deletions packages/noports_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@

# No Ports Core

Abstractions of the original sshnoports core code used for building No Ports
enabled applications. Currently in development, more documentation to come with
the official release.
No Ports Core is the underlying library used to enable sshnoports and the rest of the No Ports suite.

## Examples

### CLI Example

See the [sshnoports](https://github.com/atsign-foundation/sshnoports/tree/trunk/packages/sshnoports) project.

### Flutter Example

See the [sshnp_gui](https://github.com/atsign-foundation/sshnoports/tree/trunk/packages/sshnp_gui) project.

## Maintainers

Expand Down
11 changes: 0 additions & 11 deletions packages/noports_core/lib/common/defaults.dart

This file was deleted.

7 changes: 0 additions & 7 deletions packages/noports_core/lib/common/supported_ssh_clients.dart

This file was deleted.

22 changes: 0 additions & 22 deletions packages/noports_core/lib/common/sync_listener.dart

This file was deleted.

30 changes: 30 additions & 0 deletions packages/noports_core/lib/src/common/default_args.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:noports_core/src/common/supported_ssh_clients.dart';
import 'package:noports_core/sshrv.dart';

class DefaultArgs {
const DefaultArgs();

static const namespace = 'sshnp';

static const verbose = false;
static const rsa = false;
static const rootDomain = 'root.atsign.org';
static const sshrvGenerator = SSHRV.exec;
static const localSshdPort = 22;
static const remoteSshdPort = 22;

/// value in seconds after which idle ssh tunnels will be closed
static const idleTimeout = 15;
static const help = false;
}

class DefaultSSHNPArgs {
static const device = 'default';
static const port = 22;
static const localPort = 0;
static const sendSshPublicKey = '';
static const localSshOptions = <String>[];
static const legacyDaemon = false;
static const listDevices = false;
static const sshClient = SupportedSshClient.exec;
}
18 changes: 18 additions & 0 deletions packages/noports_core/lib/src/common/supported_ssh_clients.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
enum SupportedSshClient {
exec(cliArg: '/usr/bin/ssh'),
dart(cliArg: 'pure-dart');

final String cliArg;
const SupportedSshClient({required this.cliArg});

factory SupportedSshClient.fromCliArg(String cliArg) {
switch (cliArg) {
case '/usr/bin/ssh':
return SupportedSshClient.exec;
case 'pure-dart':
return SupportedSshClient.dart;
default:
throw ArgumentError('Unsupported SSH client: $cliArg');
}
}
}
Loading

0 comments on commit 4cb9e04

Please sign in to comment.