-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
10,970 additions
and
6,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'dart:io'; | ||
import 'package:echidna_server/echidna_server.dart'; | ||
import 'package:shelf_modular/shelf_modular.dart'; | ||
import 'dart:mirrors'; | ||
import 'package:analyzer/dart/analysis/utilities.dart'; | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:analyzer/dart/ast/visitor.dart'; | ||
|
||
class PrismaStub implements PrismaClient { | ||
@override | ||
dynamic noSuchMethod(Invocation invocation) { | ||
return super.noSuchMethod(invocation); | ||
} | ||
} | ||
|
||
class ReflectedRouteManager extends RouteManager { | ||
final List<ModularRoute> _routes = []; | ||
|
||
List<ModularRoute> get routes => List.unmodifiable(_routes); | ||
|
||
@override | ||
void add(ModularRoute route) { | ||
_routes.add(route); | ||
} | ||
} | ||
|
||
void main() { | ||
final server = ServerModule(PrismaStub()); | ||
|
||
final manager = ReflectedRouteManager(); | ||
|
||
server.routes(manager); | ||
|
||
for (final route in manager.routes) { | ||
inspectRoute(route); | ||
} | ||
} | ||
|
||
void inspectRoute(ModularRoute route, {String path = ''}) { | ||
final module = route.module; | ||
if (module != null) { | ||
final manager = ReflectedRouteManager(); | ||
|
||
module.routes(manager); | ||
|
||
for (final route in manager.routes) { | ||
inspectRoute(route, path: '$path/${route.name}'); | ||
} | ||
|
||
return; | ||
} | ||
|
||
if (route is Route) { | ||
final handlerMirror = reflect(route.handler); | ||
final handlerType = handlerMirror.type; | ||
final location = handlerType.location; | ||
|
||
print(handlerType.originalDeclaration.metadata.map((e) => e.type)); | ||
|
||
// print('$path/${route.name} -> ${handlerType.simpleName}'); | ||
|
||
if (location != null) { | ||
final filePath = location.sourceUri; | ||
// print('Handler defined in: $filePath'); | ||
// parseAndAnalyzeFile(filePath); | ||
} | ||
} | ||
|
||
// print("$path/${route.name}"); | ||
for (final child in route.children) { | ||
inspectRoute(child, path: '$path/${route.name}'); | ||
} | ||
} | ||
|
||
void parseAndAnalyzeFile(String filePath) { | ||
try { | ||
final fileContent = File(filePath).readAsStringSync(); | ||
final parseResult = parseString(content: fileContent); | ||
|
||
final CompilationUnit unit = parseResult.unit; | ||
final visitor = _ASTPrinter(); | ||
unit.visitChildren(visitor); | ||
} catch (e) { | ||
print('Error reading or parsing file $filePath: $e'); | ||
} | ||
} | ||
|
||
class _ASTPrinter extends GeneralizingAstVisitor<void> { | ||
@override | ||
void visitNode(AstNode node) { | ||
print('${node.runtimeType}: ${node.toString()}'); | ||
Check warning on line 91 in bin/doc.dart GitHub Actions / Lint Check
|
||
super.visitNode(node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
lib/modules/admin/domain/services/license_key_generator_service.dart
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export 'license_key_generator_service.dart'; | ||
|
17 changes: 0 additions & 17 deletions
17
lib/modules/admin/infra/services/hash_license_key_generator_service.dart
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export 'hash_license_key_generator_service.dart'; | ||
|
84 changes: 84 additions & 0 deletions
84
lib/modules/admin/presentation/handlers/create_client_key_handler.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:echidna_server/echidna_server.dart'; | ||
import 'package:shelf/shelf.dart'; | ||
import 'package:shelf_modular/shelf_modular.dart'; | ||
import 'package:uuid/uuid.dart'; | ||
|
||
/// Creates a new client key for a product. | ||
Future<Response> createClientKeyHandler(Request request, Injector i, ModularArguments args) async { | ||
final productId = int.tryParse(args.params['product_id'] as String? ?? ''); | ||
final customerId = int.tryParse(args.params['customer_id'] as String? ?? ''); | ||
|
||
final prisma = i.get<PrismaClient>(); | ||
|
||
if (productId == null) { | ||
request.log('No product ID provided, aborting.'); | ||
|
||
return Response.badRequest(body: 'product_id is required.'); | ||
} | ||
|
||
if (customerId == null) { | ||
request.log('No customer ID provided, aborting.'); | ||
|
||
return Response.badRequest(body: 'customer_id is required.'); | ||
} | ||
|
||
final product = await prisma.product.findUnique(where: ProductWhereUniqueInput(id: productId)); | ||
|
||
if (product == null) { | ||
request.log('Not Found: Product with ID $productId does not exist.'); | ||
return Response.notFound(null); | ||
} | ||
|
||
final customer = await prisma.customer.findUnique(where: CustomerWhereUniqueInput(id: customerId)); | ||
|
||
if (customer == null) { | ||
request.log('Not Found: Customer with ID $customerId does not exist.'); | ||
return Response.notFound(null); | ||
} | ||
|
||
final clientKeys = await prisma.clientKey.findMany( | ||
where: ClientKeyWhereInput( | ||
productId: PrismaUnion.$2(productId), | ||
customerId: PrismaUnion.$2(customerId), | ||
), | ||
); | ||
|
||
if (clientKeys.isNotEmpty) { | ||
final clientKey = clientKeys.firstWhereOrNull((k) => k.revoked == false); | ||
|
||
if (clientKey != null) { | ||
request.log('Found existing client key for product with ID $productId, returning it.'); | ||
return clientKey.toResponse(); | ||
} | ||
|
||
request.log('No active client key found for product with ID $productId, creating a new one.'); | ||
} | ||
|
||
try { | ||
final uuid = i.get<Uuid>(); | ||
|
||
final key = uuid.v4(); | ||
|
||
final clientKey = await prisma.clientKey.create( | ||
data: PrismaUnion.$1( | ||
ClientKeyCreateInput( | ||
key: key, | ||
product: ProductCreateNestedOneWithoutClientKeysInput( | ||
connect: ProductWhereUniqueInput(id: productId), | ||
), | ||
customer: CustomerCreateNestedOneWithoutClientKeysInput( | ||
connect: CustomerWhereUniqueInput(id: customerId), | ||
), | ||
), | ||
), | ||
); | ||
|
||
request.log('Created new client key for product with ID $productId.'); | ||
|
||
return clientKey.toResponse(); | ||
} catch (e, s) { | ||
request.log('Error creating client key for product with ID $productId', e, s); | ||
return Response.internalServerError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
lib/modules/admin/presentation/handlers/get_client_keys_handler.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:echidna_server/echidna_server.dart'; | ||
import 'package:shelf/shelf.dart'; | ||
import 'package:shelf_modular/shelf_modular.dart'; | ||
|
||
/// Returns a list of all client keys. | ||
Future<Response> getClientKeysHandler(Request request, Injector i, ModularArguments args) async { | ||
final prisma = i.get<PrismaClient>(); | ||
|
||
final clientKeys = await prisma.clientKey.findMany(); | ||
|
||
request.log('Found ${clientKeys.length} client keys'); | ||
|
||
return clientKeys.toResponse(); | ||
} |
21 changes: 21 additions & 0 deletions
21
lib/modules/admin/presentation/handlers/get_license_status_handler.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:echidna_server/echidna_server.dart'; | ||
import 'package:shelf/shelf.dart'; | ||
import 'package:shelf_modular/shelf_modular.dart'; | ||
|
||
/// Gets the status of a license by its id. | ||
Future<Response> getLicenseStatusHandler(Request request, Injector i, ModularArguments args) async { | ||
final datasource = i.get<LicenseStatusDatasource>(); | ||
|
||
final id = args.params['id']; | ||
|
||
if (id == null) { | ||
request.log('Bad Request: No id given'); | ||
return Response.badRequest(body: 'ID required'); | ||
} | ||
|
||
final licenseStatus = await datasource.getLicenseStatus(id); | ||
|
||
return Response.ok(jsonEncode(licenseStatus)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.