Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

parrot_shelf package #6

Closed
wants to merge 2 commits into from
Closed
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
20 changes: 20 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Security Policy

🦜 Parrot security needs the help of the community, and CI scanning alone can only prevent existing problems.

## Supported Versions

| Package | Version | Supprted |
| ------------ | ------- | -------- |
| parrot | < 1.0.0 | :x: |
| parrot_shelf | < 1.0.0 | :x: |

## Reporting a Vulnerability

Please report (suspected) security vulnerabilities to [security@odroe.com](mailto:security@odroe.com) You will receive a response from us within 48 hours. If the issue is confirmed, we will release a patch as soon as possible depending on complexity but historically within a few days.

> **Note:** Please do not report security vulnerabilities through public GitHub issues.
>
> If you have a fix, please submit a pull request.
>
> **Publicizing a security issue with uncertainty about its impact would cause a lot of trouble and immeasurable damage to the rest of the community.**
10 changes: 10 additions & 0 deletions examples/parrot_02_shelf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build outputs.
build/

# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
13 changes: 13 additions & 0 deletions examples/parrot_02_shelf/lib/app.controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:parrot_shelf/parrot_shelf.dart';

import 'app.service.dart';

@Controller()
class AppController {
const AppController(this.service);

final AppService service;

@Get()
hello() => 'Hello, ${service.name}!';
}
10 changes: 10 additions & 0 deletions examples/parrot_02_shelf/lib/app.module.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:parrot_shelf/parrot_shelf.dart';

import 'app.controller.dart';
import 'app.service.dart';

@ShelfModule(
controllers: [AppController],
providers: [AppService],
)
class AppModule {}
6 changes: 6 additions & 0 deletions examples/parrot_02_shelf/lib/app.service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:parrot/parrot.dart';

@Injectable()
class AppService {
String get name => '🦜 Parrot';
}
1 change: 1 addition & 0 deletions examples/parrot_02_shelf/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 11 additions & 0 deletions examples/parrot_02_shelf/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: parrot_02_shelf
environment:
sdk: '>=2.10.0 <3.0.0'
dependencies:
parrot: ^0.0.1
parrot_shelf: ^0.0.0
dependency_overrides:
parrot:
path: ../../packages/parrot
parrot_shelf:
path: ../../packages/parrot_shelf
7 changes: 6 additions & 1 deletion packages/parrot_shelf/lib/parrot_shelf.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/// Shelf support module for Parrot framework.
library parrot.shelf;

export 'src/parrot_shelf_application.dart';
export 'src/annotations/controller.dart';
export 'src/annotations/route.dart';
export 'src/annotations/shelf_module.dart';

export 'src/parrot_middleware.dart';
export 'src/shelf_application.dart';
6 changes: 5 additions & 1 deletion packages/parrot_shelf/lib/src/annotations/controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class Controller {
const Controller([this.path]);
const Controller({
this.path,
this.middleware = const [],
});

final String? path;
final List<Type> middleware;
}
69 changes: 69 additions & 0 deletions packages/parrot_shelf/lib/src/annotations/route.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class Route {
const Route(
this.method, {
this.path,
this.middleware = const [],
});

final String method;

final String? path;

final List<Type> middleware;
}

class Get extends Route {
const Get({
String? path,
List<Type> middleware = const [],
}) : super('GET', path: path, middleware: middleware);
}

class Head extends Route {
const Head({
String? path,
List<Type> middleware = const [],
}) : super('HEAD', path: path, middleware: middleware);
}

class Post extends Route {
const Post({
String? path,
List<Type> middleware = const [],
}) : super('POST', path: path, middleware: middleware);
}

class Put extends Route {
const Put({
String? path,
List<Type> middleware = const [],
}) : super('PUT', path: path, middleware: middleware);
}

class Delete extends Route {
const Delete({
String? path,
List<Type> middleware = const [],
}) : super('DELETE', path: path, middleware: middleware);
}

class Connect extends Route {
const Connect({
String? path,
List<Type> middleware = const [],
}) : super('CONNECT', path: path, middleware: middleware);
}

class Options extends Route {
const Options({
String? path,
List<Type> middleware = const [],
}) : super('OPTIONS', path: path, middleware: middleware);
}

class Trace extends Route {
const Trace({
String? path,
List<Type> middleware = const [],
}) : super('TRACE', path: path, middleware: middleware);
}
13 changes: 13 additions & 0 deletions packages/parrot_shelf/lib/src/annotations/shelf_module.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:parrot/parrot.dart';

class ShelfModule extends Module {
const ShelfModule({
this.controllers = const [],
super.dependencies,
super.exports,
super.global,
super.providers,
});

final Iterable<Type> controllers;
}
15 changes: 0 additions & 15 deletions packages/parrot_shelf/lib/src/http/http_method.dart

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions packages/parrot_shelf/lib/src/middleware/middleware_configure.dart

This file was deleted.

17 changes: 0 additions & 17 deletions packages/parrot_shelf/lib/src/middleware/typed.dart

This file was deleted.

55 changes: 0 additions & 55 deletions packages/parrot_shelf/lib/src/parrot_shelf_application.dart

This file was deleted.

18 changes: 18 additions & 0 deletions packages/parrot_shelf/lib/src/router/router_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:parrot/parrot.dart';
import 'package:shelf_router/shelf_router.dart';

class RouterBuilder {
RouterBuilder._(this.app);

static Future<Router>? _router;

static Future<Router> single(ParrotApplication app) =>
_router ??= RouterBuilder._(app).build();

final ParrotApplication app;

/// Build a [Router] from the [ParrotApplication].
Future<Router> build() {
throw UnimplementedError();
}
}
31 changes: 31 additions & 0 deletions packages/parrot_shelf/lib/src/shelf_application.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'dart:io';

import 'package:parrot/parrot.dart';
import 'package:shelf/shelf_io.dart';

import 'router/router_builder.dart';
import 'utils/get_free_port.dart';

extension ShelfApplication on ParrotApplication {
/// Listens for HTTP requests on the specified [address] and [port].
///
/// If [address] is `null`, this will listen on all available IPv4 addresses
/// (not IPv6 addresses).
///
/// If [port] is `null`, this will listen on a random port.
Future<HttpServer> listen({
int? port,
Object? address,
SecurityContext? securityContext,
int? backlog,
bool shared = false,
}) async =>
serve(
await RouterBuilder.single(this),
address ?? InternetAddress.anyIPv4,
port ?? await getFreePort(),
securityContext: securityContext,
backlog: backlog,
shared: shared,
);
}
11 changes: 11 additions & 0 deletions packages/parrot_shelf/lib/src/utils/get_free_port.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'dart:io';

/// returns free port.
Future<int> getFreePort() async {
final ServerSocket socket =
await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
final int port = socket.port;
await socket.close();

return port;
}
1 change: 1 addition & 0 deletions packages/parrot_shelf/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ environment:
dependencies:
shelf: ^1.3.2
parrot: ^0.0.1
shelf_router: ^1.1.3

dev_dependencies:
lints: ^2.0.0
Expand Down