-
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.
[TRELLO-2464] Add endpoints to manage blacklisted ips (#1714)
- Loading branch information
Showing
7 changed files
with
55 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
package repositories.ipblacklist | ||
|
||
import play.api.libs.json.Json | ||
import play.api.libs.json.OFormat | ||
|
||
case class BlackListedIp(ip: String, comment: String, critical: Boolean) | ||
|
||
object BlackListedIp { | ||
implicit val format: OFormat[BlackListedIp] = Json.format[BlackListedIp] | ||
} |
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,17 +1,27 @@ | ||
package repositories.ipblacklist | ||
|
||
import repositories.PostgresProfile.api._ | ||
import repositories.TypedCRUDRepository | ||
import slick.basic.DatabaseConfig | ||
import slick.jdbc.JdbcProfile | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.Future | ||
|
||
class IpBlackListRepository(override val dbConfig: DatabaseConfig[JdbcProfile])(implicit | ||
override val ec: ExecutionContext | ||
) extends TypedCRUDRepository[IpBlackListTable, BlackListedIp, String] | ||
with IpBlackListRepositoryInterface { | ||
class IpBlackListRepository(dbConfig: DatabaseConfig[JdbcProfile])(implicit ec: ExecutionContext) | ||
extends IpBlackListRepositoryInterface { | ||
|
||
override val table = IpBlackListTable.table | ||
val table = IpBlackListTable.table | ||
|
||
import dbConfig._ | ||
|
||
override def create(ip: BlackListedIp): Future[BlackListedIp] = db | ||
.run( | ||
table returning table += ip | ||
) | ||
|
||
override def delete(ip: String): Future[Int] = db.run( | ||
table.filter(_.ip === ip).delete | ||
) | ||
|
||
override def list(): Future[List[BlackListedIp]] = db.run(table.to[List].result) | ||
} |
8 changes: 6 additions & 2 deletions
8
app/repositories/ipblacklist/IpBlackListRepositoryInterface.scala
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,5 +1,9 @@ | ||
package repositories.ipblacklist | ||
|
||
import repositories.TypedCRUDRepositoryInterface | ||
import scala.concurrent.Future | ||
|
||
trait IpBlackListRepositoryInterface extends TypedCRUDRepositoryInterface[BlackListedIp, String] {} | ||
trait IpBlackListRepositoryInterface { | ||
def create(ip: BlackListedIp): Future[BlackListedIp] | ||
def delete(ip: String): Future[Int] | ||
def list(): Future[List[BlackListedIp]] | ||
} |
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