Skip to content

Commit

Permalink
Released 2.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsutton committed Sep 17, 2022
1 parent 92d68bf commit f0006b5
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 134 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ build/
.failed_tracker
onepub.token.yaml
test/test_settings.yaml
bin/onepub
bin/opub
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# 2.0.0
- BREAKING: re-wrote login to use pure server side rather than requiring the browser to connect via local host. This is to get around local firewalls, the brave browser and the inability to login from an ssh session or a local docker container. All of these scenarios should now work.
- Added version checks into the api to ensure the onepub client is running
against a compatible onepub client.
- doctor now checks for a compatible server version no.
- improvements to the auth pre test hook.
- Added missing future/await to return of withTestSystem callback.
- renamed OnePubTokenStore.fetch to load as fetch implies an http request rather then a local file.
- moved to dcli 1.20.2 as 1.20.1 didn't actually correctly support dart 2.12 whilst 1.20.2 does.
- Added unit test for missing sub command.
- Change the structure of the REST json response from onepub to expect 'body' rather than 'success' for the body of the response.
- Added capture function from dcli 2.x to help with unit testing.
- Added ExitException to list of user facing exceptions.
- Changed logout json response to always have non-null error message.
- Added missing awaits after testing code against dart 2.18 improved formatting of usage statements. Improved formatting/messaging of errors.
- Added the .pub-cache path to the doctor output.
- improved the formatting of the doctor command.

# 1.4.5
- Modified the ssh detection and removed SSH_AGENT_PID as this is
used on the local machine to indicate the PID of the local ssh agent
Expand Down
43 changes: 43 additions & 0 deletions lib/src/pub/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# specific lints for code cloned from pub
analyzer:
errors:
unused_import: error
unused_local_variable: error
dead_code: error
todo: ignore

exclude:
- lib/src/pub/third_party



linter:
rules:
avoid_catching_errors: true
avoid_print: true
avoid_private_typedef_functions: true
avoid_redundant_argument_values: true
avoid_returning_null_for_future: true
avoid_unused_constructor_parameters: true
avoid_void_async: true
cancel_subscriptions: true
directives_ordering: false ## changed by onepub
missing_whitespace_between_adjacent_strings: true
no_adjacent_strings_in_list: true
no_runtimeType_toString: true
only_throw_errors: true
package_api_docs: true
prefer_asserts_in_initializer_lists: true
prefer_const_declarations: true
prefer_relative_imports: true
prefer_single_quotes: true
sort_pub_dependencies: true
test_types_in_equals: true
throw_in_finally: true
unawaited_futures: true
unnecessary_lambdas: true
unnecessary_null_aware_assignments: true
unnecessary_parenthesis: true
unnecessary_statements: true
use_super_parameters: false

21 changes: 12 additions & 9 deletions lib/src/pub/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore: cascade_invocations

import 'dart:async';
import 'dart:io';

Expand Down Expand Up @@ -42,14 +44,13 @@ String topLevelProgram = 'onepub';

class PubCommandRunner extends CommandRunner<int> implements PubTopLevel {
@override
String? get directory => argResults['directory'];
String? get directory => argResults['directory'] as String;

@override
bool get captureStackChains {
return argResults['trace'] ||
argResults['verbose'] ||
argResults['verbosity'] == 'all';
}
bool get captureStackChains =>
argResults['trace'] as bool ||
argResults['verbose'] as bool ||
argResults['verbosity'] as String == 'all';

@override
Verbosity get verbosity {
Expand All @@ -68,14 +69,14 @@ class PubCommandRunner extends CommandRunner<int> implements PubTopLevel {
return log.Verbosity.all;
default:
// No specific verbosity given, so check for the shortcut.
if (argResults['verbose']) return log.Verbosity.all;
if (argResults['verbose'] as bool) return log.Verbosity.all;
if (runningFromTest) return log.Verbosity.testing;
return log.Verbosity.normal;
}
}

@override
bool get trace => argResults['trace'];
bool get trace => argResults['trace'] as bool;

ArgResults? _argResults;

Expand All @@ -94,10 +95,12 @@ class PubCommandRunner extends CommandRunner<int> implements PubTopLevel {
String get usageFooter =>
'See https://dart.dev/tools/pub/cmd for detailed documentation.';

// ignore: sort_constructors_first
PubCommandRunner()
: super('pub', 'Pub is a package manager for Dart.',
usageLineLength: lineLength) {
argParser.addFlag('version', negatable: false, help: 'Print pub version.');

argParser.addFlag('trace',
negatable: false,
help: 'Print debugging information when an error occurs.');
Expand Down Expand Up @@ -165,7 +168,7 @@ class PubCommandRunner extends CommandRunner<int> implements PubTopLevel {
Future<int?> runCommand(ArgResults topLevelResults) async {
_checkDepsSynced();

if (topLevelResults['version']) {
if (topLevelResults['version'] != null) {
log.message('Pub ${sdk.version}');
return 0;
}
Expand Down
20 changes: 10 additions & 10 deletions lib/src/pub/source/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ class GitSource extends CachedSource {
throw FormatException('The description must be a Git URL or a map '
"with a 'url' key.");
} else {
final descriptionUrl = description['url'];
final descriptionUrl = description['url'] as String?;
if (descriptionUrl is! String) {
throw FormatException(
"The 'url' field of a description must be a string.");
}
url = descriptionUrl;

final descriptionRef = description['ref'];
final descriptionRef = description['ref'] as String?;
if (descriptionRef is! String?) {
throw FormatException("The 'ref' field of the description must be a "
'string.');
}
ref = descriptionRef;

final descriptionPath = description['path'];
final descriptionPath = description['path'] as String?;
if (descriptionPath is! String?) {
throw FormatException("The 'path' field of the description must be a "
'string.');
Expand All @@ -82,26 +82,26 @@ class GitSource extends CachedSource {
}

@override
PackageId parseId(String name, Version version, description,
PackageId parseId(String name, Version version, dynamic description,
{String? containingDir}) {
if (description is! Map) {
throw FormatException("The description must be a map with a 'url' "
'key.');
}

var ref = description['ref'];
var ref = description['ref'] as String?;
if (ref != null && ref is! String) {
throw FormatException("The 'ref' field of the description must be a "
'string.');
}

final resolvedRef = description['resolved-ref'];
final resolvedRef = description['resolved-ref'] as String?;
if (resolvedRef is! String) {
throw FormatException("The 'resolved-ref' field of the description "
'must be a string.');
}

final url = description['url'];
final url = description['url'] as String;
return PackageId(
name,
version,
Expand Down Expand Up @@ -487,7 +487,7 @@ class GitSource extends CachedSource {
/// [ref].
///
/// This assumes that the canonical clone already exists.
Future _updateRepoCache(
Future<void> _updateRepoCache(
PackageRef ref,
SystemCache cache,
) async {
Expand Down Expand Up @@ -574,7 +574,7 @@ class GitSource extends CachedSource {
///
/// If [shallow] is true, creates a shallow clone that contains no history
/// for the repository.
Future _clone(
Future<void> _clone(
String from,
String to, {
bool mirror = false,
Expand All @@ -597,7 +597,7 @@ class GitSource extends CachedSource {
}

/// Checks out the reference [ref] in [repoPath].
Future _checkOut(String repoPath, String ref) {
Future<void> _checkOut(String repoPath, String ref) {
return git
.run(['checkout', ref], workingDir: repoPath).then((result) => null);
}
Expand Down
82 changes: 6 additions & 76 deletions lib/src/util/bread_butter_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import 'dart:io';
import 'package:dcli/dcli.dart';
import 'package:usage/uuid/uuid.dart';

import '../exceptions.dart';
import '../api/api.dart';
import '../api/auth_response.dart';
import '../onepub_settings.dart';
import 'send_command.dart';

Expand Down Expand Up @@ -50,88 +51,17 @@ Waiting for your authorisation...''');

late AuthResponse auth;

final api = API();

while (retry) {
final response = await sendCommand(
command: 'member/awaitLogin/$authToken',
commandType: CommandType.cli,
authorised: false);
auth = await api.awaitLogin(authToken);

auth = decantResponse(response);
retry = auth.status == Status.retry;
retry = auth.status == AwaitLoginStatus.retry;
if (retry) {
sleep(auth.pollInterval);
}
}

return auth;
}

AuthResponse decantResponse(EndpointResponse? response) {
if (response == null) {
throw ExitException(
exitCode: 1, message: 'Invalid response. onePubToken not returned');
}

return AuthResponse.parse(response);
}
}

class AuthResponse {
AuthResponse._internal();

factory AuthResponse.parse(EndpointResponse response) {
final auth = AuthResponse._internal();
if (response.success == true) {
auth.status = parseStatus(
response.data['status'] as String? ?? Status.authFailed.toString());

switch (auth.status) {
case Status.authSucceeded:
auth
..onepubToken = response.data['onePubToken']! as String
..firstLogin = response.data['firstLogin']! as bool
..operatorEmail = response.data['operatorEmail']! as String
..organisationName = response.data['organisationName']! as String
..obfuscatedOrganisationId =
response.data['obfuscatedOrganisationId']! as String;
break;
case Status.retry:
auth.pollInterval = response.data['pollInterval'] as int? ?? 3;
break;
case Status.authFailed:
throw ExitException(exitCode: 1, message: 'Authentication failed');
case Status.timeout:
throw ExitException(exitCode: 1, message: 'Login Timed out');
}
return auth;
} else {
throw ExitException(
exitCode: 1, message: 'Login failed: ${response.data['error']}');
}
}

late final Status status;
late final int pollInterval;

late final String onepubToken;
late final bool firstLogin;
late final String operatorEmail;
late final String organisationName;
late final String obfuscatedOrganisationId;
}

enum Status {
authSucceeded,
authFailed,

/// the auth hasn't yet been completed.
/// wait for pollInterval seconds and retry.
retry,

/// The auth has been cancelled as the user
/// didn't respond in a timely manner (usually five minutes)
timeout
}

Status parseStatus(String name) =>
Status.values.firstWhere((e) => e.toString() == 'Status.$name');
2 changes: 1 addition & 1 deletion lib/src/version/version.g.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// GENERATED BY pub_release do not modify.
/// onepub version
String packageVersion = '2.0.0-beta.1';
String packageVersion = '2.0.0';
14 changes: 14 additions & 0 deletions onepub.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"folders": [
{
"path": "."
},
{
"path": "../dcli-2.12"
},
{
"path": "../onepub-deploy"
}
],
"settings": {}
}
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ packages:
path: "../dcli-2.12/dcli"
relative: true
source: path
version: "1.20.2"
version: "1.20.3"
dcli_core:
dependency: "direct main"
description:
path: "../dcli-2.12/dcli_core"
relative: true
source: path
version: "1.20.2"
version: "1.20.3"
equatable:
dependency: "direct main"
description:
Expand Down Expand Up @@ -583,4 +583,4 @@ packages:
source: hosted
version: "2.0.2"
sdks:
dart: ">=2.12.1 <3.0.0"
dart: ">=2.12.0 <3.0.0"
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: onepub
version: 2.0.0-beta.1
version: 2.0.0
homepage: https://onepub.dev
documentation: https://docs.onepub.dev
publish_to: https://squarephone.biz/api/ndavuhnofl/
description: Command line tools for the OnePub private Dart/Flutter repository.
repository: https://github.com/onepub-dev/onepub
environment:
sdk: '>=2.12.1 <3.0.0'
sdk: '>=2.12.0 <3.0.0'
dependencies:
analyzer: 2.3.0
args: 2.3.1
Expand All @@ -15,8 +15,8 @@ dependencies:
cli_util: 0.3.5
collection: 1.15.0
crypto: 3.0.1
dcli: 1.20.2
dcli_core: 1.20.2
dcli: 1.20.3
dcli_core: 1.20.3
equatable: 2.0.3
frontend_server_client: 2.1.2
glob: 2.0.1
Expand Down
Loading

0 comments on commit f0006b5

Please sign in to comment.