Skip to content

Commit 174d278

Browse files
authored
Merge pull request #79 from takapi327/0.7.x
Release/v0.7.0
2 parents 7c35952 + 897ce96 commit 174d278

File tree

93 files changed

+2594
-356
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2594
-356
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
run: sbt ++${{ matrix.scala }} test
5858

5959
- name: Compress target directories
60-
run: tar cf targets.tar core/lepus-router/target core/lepus-logger/target modules/lepus-logback/target modules/lepus-swagger/target modules/lepus-database/target target core/lepus-server/target modules/lepus-hikari/target core/sbt-plugin/target modules/lepus-doobie/target core/lepus/target development/sbt-scripted-tools/target core/lepus-guice/target project/target
60+
run: tar cf targets.tar modules/lepus-router/target modules/lepus-logger/target modules/lepus-logback/target modules/lepus-swagger/target modules/lepus-database/target target core/lepus-app/target core/lepus-server/target modules/lepus-hikari/target core/sbt-plugin/target modules/lepus-doobie/target core/lepus/target development/sbt-scripted-tools/target core/lepus-guice/target project/target
6161

6262
- name: Upload target directories
6363
uses: actions/upload-artifact@v2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
![lepusframework](https://socialify.git.ci/takapi327/lepusframework/image?description=1&font=Inter&language=1&logo=https%3A%2F%2Fuser-images.githubusercontent.com%2F57429437%2F170270360-93f29bbf-aef3-47d7-8910-f5baba490ba6.png&owner=1&pattern=Plus&theme=Light)
22

33
<div align="center">
4-
<img src="https://img.shields.io/badge/lepus-v0.6.1-blue">
4+
<img src="https://img.shields.io/badge/lepus-v0.7.0-blue">
55
<a href="https://en.wikipedia.org/wiki/MIT_License">
66
<img src="https://img.shields.io/badge/license-MIT-green">
77
</a>

build.sbt

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,10 @@ lazy val LepusGuiceProject = LepusSbtProject("Lepus-Guice", "core/lepus-guice")
6060
.settings(libraryDependencies ++= Seq(catsEffect, guice) ++ specs2Deps)
6161
.dependsOn(LepusProject)
6262

63-
lazy val LepusLoggerProject = LepusSbtProject("Lepus-Logger", "core/lepus-logger")
63+
lazy val LepusAppProject = LepusSbtProject("Lepus-App", "core/lepus-app")
6464
.settings(scalaVersion := (LepusProject / scalaVersion).value)
65-
.settings(libraryDependencies ++= Seq(
66-
catsEffect,
67-
"io.circe" %% "circe-core" % circeVersion
68-
) ++ specs2Deps)
69-
70-
lazy val LepusRouterProject = LepusSbtProject("Lepus-Router", "core/lepus-router")
71-
.settings(scalaVersion := (LepusProject / scalaVersion).value)
72-
.settings(libraryDependencies ++= routerDependencies ++ specs2Deps)
73-
.dependsOn(LepusProject)
74-
.enablePlugins(spray.boilerplate.BoilerplatePlugin)
65+
.settings(libraryDependencies ++= Seq(http4sDsl, mapRef) ++ jwt ++ specs2Deps)
66+
.dependsOn(LepusProject, LepusGuiceProject)
7567

7668
lazy val LepusServerProject = LepusSbtProject("Lepus-Server", "core/lepus-server")
7769
.settings(scalaVersion := (LepusProject / scalaVersion).value)
@@ -84,7 +76,8 @@ lazy val LepusServerProject = LepusSbtProject("Lepus-Server", "core/lepus-server
8476
(Compile / sourceDirectory).value / s"scala-$suffix"
8577
}
8678
)
87-
.dependsOn(LepusRouterProject, LepusGuiceProject, LepusLoggerProject)
79+
.settings(libraryDependencies ++= http4sEmber ++ specs2Deps)
80+
.dependsOn(LepusAppProject)
8881

8982
lazy val SbtPluginProject = LepusSbtPluginProject("Sbt-Plugin", "core/sbt-plugin")
9083
.settings(
@@ -110,6 +103,13 @@ lazy val LepusLogbackProject = LepusSbtProject("Lepus-Logback", "modules/lepus-l
110103
.settings(scalaVersion := (LepusProject / scalaVersion).value)
111104
.settings(libraryDependencies += logback)
112105

106+
lazy val LepusLoggerProject = LepusSbtProject("Lepus-Logger", "modules/lepus-logger")
107+
.settings(scalaVersion := (LepusProject / scalaVersion).value)
108+
.settings(libraryDependencies ++= Seq(
109+
catsEffect,
110+
"io.circe" %% "circe-core" % circeVersion
111+
) ++ specs2Deps)
112+
113113
lazy val LepusDatabaseProject = LepusSbtProject("Lepus-Database", "modules/lepus-database")
114114
.settings(scalaVersion := (LepusProject / scalaVersion).value)
115115
.settings(libraryDependencies ++= specs2Deps)
@@ -128,10 +128,16 @@ lazy val LepusDoobieProject = LepusSbtProject("Lepus-doobie", "modules/lepus-doo
128128
) ++ specs2Deps)
129129
.dependsOn(LepusHikariProject, LepusGuiceProject)
130130

131+
lazy val LepusRouterProject = LepusSbtProject("Lepus-Router", "modules/lepus-router")
132+
.settings(scalaVersion := (LepusProject / scalaVersion).value)
133+
.settings(libraryDependencies ++= routerDependencies ++ specs2Deps)
134+
.dependsOn(LepusAppProject)
135+
.enablePlugins(spray.boilerplate.BoilerplatePlugin)
136+
131137
lazy val LepusSwaggerProject = LepusSbtProject("Lepus-Swagger", "modules/lepus-swagger")
132138
.settings(scalaVersion := (LepusProject / scalaVersion).value)
133139
.settings(libraryDependencies ++= swaggerDependencies ++ specs2Deps)
134-
.dependsOn(LepusServerProject)
140+
.dependsOn(LepusRouterProject)
135141

136142
// Development projects
137143
lazy val SbtScriptedToolsProject = LepusSbtPluginProject("Sbt-Scripted-Tools", "development/sbt-scripted-tools")
@@ -140,17 +146,18 @@ lazy val SbtScriptedToolsProject = LepusSbtPluginProject("Sbt-Scripted-Tools", "
140146
lazy val coreProjects: Seq[ProjectReference] = Seq(
141147
LepusProject,
142148
LepusGuiceProject,
143-
LepusLoggerProject,
144-
LepusRouterProject,
149+
LepusAppProject,
145150
LepusServerProject,
146151
SbtPluginProject
147152
)
148153

149154
lazy val moduleProjects: Seq[ProjectReference] = Seq(
150155
LepusLogbackProject,
156+
LepusLoggerProject,
151157
LepusDatabaseProject,
152158
LepusHikariProject,
153159
LepusDoobieProject,
160+
LepusRouterProject,
154161
LepusSwaggerProject
155162
)
156163

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/** This file is part of the Lepus Framework. For the full copyright and license information, please view the LICENSE
2+
* file that was distributed with this source code.
3+
*/
4+
5+
package lepus.app
6+
7+
import javax.inject.{ Singleton, Provider }
8+
9+
import com.google.inject.AbstractModule
10+
11+
import lepus.core.util.Configuration
12+
13+
import lepus.app.jwt.*
14+
15+
/** Modules that are included by default in the application
16+
*/
17+
@Singleton
18+
private[lepus] class BuiltinModule extends AbstractModule:
19+
override def configure(): Unit =
20+
bind(classOf[Configuration]).toProvider(classOf[Providers.ConfigurationProvider])
21+
22+
/** Setup for Jwt. */
23+
bind(classOf[JwtConfigReader]).to(classOf[DefaultJwtConfigReader])
24+
bind(classOf[JwtFormatter]).to(classOf[DefaultJwtFormatter])
25+
bind(classOf[JwtSettings]).to(classOf[DefaultJwtSettings])

core/lepus-server/src/main/scala/lepus/server/LepusApp.scala renamed to core/lepus-app/src/main/scala/lepus/app/LepusApp.scala

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,31 @@
22
* file that was distributed with this source code.
33
*/
44

5-
package lepus.server
5+
package lepus.app
66

77
import com.google.inject.Injector
88

9-
import cats.Applicative
10-
import cats.data.NonEmptyList
11-
12-
import org.http4s.{ HttpApp, Status, Response }
13-
import org.http4s.server.middleware.CORSPolicy
14-
15-
import lepus.router.Routing
9+
import org.http4s.{ HttpRoutes, Response }
1610

1711
/** A model for providing server configuration information. Only one must be generated by the application.
1812
*
1913
* For example:
2014
* {{{
2115
* object HttpApp extends LepusApp[IO]:
22-
* override def routes = NonEmptyList.of(
23-
* "world" / country ->> RouterConstructor.of {
24-
* case GET => WorldController.get
16+
* val routes = Router(
17+
* "/" -> HttpRoutes.of[IO] {
18+
* case GET -> Root / "hello" / name => Ok(s"Hello $name")
2519
* }
26-
* )
20+
* ).orNotFound
2721
* }}}
2822
*
2923
* @tparam F
3024
* the effect type.
3125
*/
32-
trait LepusApp[F[_]: Applicative]:
33-
34-
// ----- [ Router Setups ] -----
35-
/** CORS settings applied to all endpoints */
36-
val cors: Option[CORSPolicy] = None
26+
trait LepusApp[F[_]]:
3727

3828
/** List of all endpoints to be launched by the application */
39-
val routes: Injector ?=> NonEmptyList[Routing[F]] | HttpApp[F]
29+
val router: Injector ?=> HttpRoutes[F]
4030

4131
/** Methods to define handling of errors that occur during application execution */
42-
val errorHandler: PartialFunction[Throwable, F[Response[F]]] =
43-
case _ => Applicative[F].pure(Response(Status.InternalServerError))
32+
val errorHandler: PartialFunction[Throwable, F[Response[F]]] = PartialFunction.empty
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** This file is part of the Lepus Framework. For the full copyright and license information, please view the LICENSE
2+
* file that was distributed with this source code.
3+
*/
4+
5+
package lepus.app
6+
7+
import javax.inject.{ Singleton, Provider }
8+
9+
import lepus.core.util.Configuration
10+
11+
/** List of Providers to include by default in your application
12+
*/
13+
object Providers:
14+
15+
@Singleton
16+
class ConfigurationProvider extends Provider[Configuration]:
17+
override def get(): Configuration = Configuration.load()
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/** This file is part of the Lepus Framework. For the full copyright and license information, please view the LICENSE
2+
* file that was distributed with this source code.
3+
*/
4+
5+
package lepus.app.jwt
6+
7+
import javax.inject.Inject
8+
9+
import scala.concurrent.duration.*
10+
11+
import io.jsonwebtoken.SignatureAlgorithm
12+
13+
import org.http4s.{ SameSite, HttpDate }
14+
15+
import lepus.core.util.Configuration
16+
17+
/** Object to read the information needed to configure the JWT from the conf file.
18+
*/
19+
trait JwtConfigReader:
20+
21+
private val config: Configuration = Configuration.load()
22+
23+
/** Key to retrieve the value of jwt. If you want to change the key, you need to overwrite it at the inherited
24+
* location.
25+
*/
26+
val JWT: String = "lepus.jwt"
27+
28+
private final lazy val JWT_SIGNATURE_ALGORITHM: String = JWT + ".signature_algorithm"
29+
private final lazy val JWT_EXPIRES_AFTER: String = JWT + ".expires_after"
30+
private final lazy val JWT_CLOCK_SKEW: String = JWT + ".clock_skew"
31+
private final lazy val JWT_CLAIM_KEY: String = JWT + ".claim_key"
32+
private final lazy val JWT_COOKIE_KEY: String = JWT + ".cookie.key"
33+
private final lazy val JWT_COOKIE_MAX_AGE: String = JWT + ".cookie.max_age"
34+
private final lazy val JWT_COOKIE_HTTP_ONLY: String = JWT + ".cookie.http_only"
35+
private final lazy val JWT_COOKIE_SECURE: String = JWT + ".cookie.secure"
36+
private final lazy val JWT_COOKIE_DOMAIN: String = JWT + ".cookie.domain"
37+
private final lazy val JWT_COOKIE_PATH: String = JWT + ".cookie.path"
38+
private final lazy val JWT_COOKIE_SAME_SITE: String = JWT + ".cookie.same_site"
39+
private final lazy val JWT_COOKIE_EXPIRES: String = JWT + ".cookie.expires"
40+
private final lazy val JWT_COOKIE_EXTENSION: String = JWT + ".cookie.extension"
41+
42+
lazy val signatureAlgorithm: SignatureAlgorithm =
43+
config
44+
.get[Option[String]](JWT_SIGNATURE_ALGORITHM)
45+
.fold(SignatureAlgorithm.HS256)(SignatureAlgorithm.forName)
46+
47+
lazy val expiresAfter: Option[FiniteDuration] =
48+
config.get[Option[FiniteDuration]](JWT_EXPIRES_AFTER)
49+
50+
lazy val clockSkew: FiniteDuration =
51+
config.get[Option[FiniteDuration]](JWT_CLOCK_SKEW).getOrElse(30.seconds)
52+
53+
lazy val claimKey: String =
54+
config.get[Option[String]](JWT_CLAIM_KEY).getOrElse("data")
55+
56+
/** Cookie key managed by cookies. Default is LEPUS_JWT_COOKIE */
57+
lazy val cookieKey: String =
58+
config.get[Option[String]](JWT_COOKIE_KEY).getOrElse("LEPUS_JWT_COOKIE")
59+
60+
/** Expires managed by cookies. */
61+
lazy val expires: Option[HttpDate] =
62+
config
63+
.get[Option[Long]](JWT_COOKIE_EXPIRES)
64+
.map(long =>
65+
HttpDate.fromEpochSecond(long) match
66+
case Right(value) => value
67+
case Left(value) => throw new IllegalArgumentException(value.getMessage)
68+
)
69+
70+
/** Cookie key managed by cookies. Default is LEPUS_JWT_COOKIE */
71+
lazy val maxAge: Option[Long] =
72+
config.get[Option[Long]](JWT_COOKIE_MAX_AGE)
73+
74+
/** HttpOnly managed by cookies. Default is true */
75+
lazy val httpOnly: Boolean = config.get[Option[Boolean]](JWT_COOKIE_HTTP_ONLY).getOrElse(true)
76+
77+
/** Secure managed by cookies. Default is true */
78+
lazy val secure: Boolean = config.get[Option[Boolean]](JWT_COOKIE_SECURE).getOrElse(true)
79+
80+
/** Domain managed by cookies. */
81+
lazy val domain: Option[String] = config.get[Option[String]](JWT_COOKIE_DOMAIN)
82+
83+
/** Path managed by cookies. */
84+
lazy val path: Option[String] = config.get[Option[String]](JWT_COOKIE_PATH)
85+
86+
/** SameSite managed by cookies. Default is Lax */
87+
lazy val sameSite: SameSite = config
88+
.get[Option[String]](JWT_COOKIE_SAME_SITE)
89+
.fold(SameSite.Lax)(str =>
90+
str match
91+
case "Lax" => SameSite.Lax
92+
case "Strict" => SameSite.Strict
93+
case "None" => SameSite.None
94+
case unknown =>
95+
throw new IllegalArgumentException(
96+
s"$unknown did not match any of the SameSites. The value of SameSite must be Lax, Strict, or None."
97+
)
98+
)
99+
100+
/** Extension managed by cookies. */
101+
lazy val extension: Option[String] =
102+
config.get[Option[String]](JWT_COOKIE_EXTENSION)
103+
104+
case class DefaultJwtConfigReader() extends JwtConfigReader

0 commit comments

Comments
 (0)