Skip to content

Commit

Permalink
Merge pull request #67 from bmpotter/add-image-token-support
Browse files Browse the repository at this point in the history
Add image token support
  • Loading branch information
bmpotter authored Apr 9, 2018
2 parents 7dc00ca + a0202a8 commit 7fe47ff
Show file tree
Hide file tree
Showing 13 changed files with 445 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ services in the exchange.
- Allow random PW creation for user creation
- Consider changing all creates to POST, and update (via put/patch) return codes to 200

## Changes in 1.52.0

- Add services sub-resource called dockerauths for docker image auth tokens

## Changes in 1.51.0

- Fixed error upgrading db schema from earlier than db schema 3
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.51.0
1.52.0
12 changes: 10 additions & 2 deletions src/main/scala/com/horizon/exchangeapi/ExchangeApiTables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object ExchangeApiTables {
++ NodesTQ.rows.schema ++ RegMicroservicesTQ.rows.schema ++ PropsTQ.rows.schema ++ NodeAgreementsTQ.rows.schema ++ NodeStatusTQ.rows.schema
++ AgbotsTQ.rows.schema ++ AgbotAgreementsTQ.rows.schema ++ AgbotPatternsTQ.rows.schema
++ NodeMsgsTQ.rows.schema ++ AgbotMsgsTQ.rows.schema
++ BctypesTQ.rows.schema ++ BlockchainsTQ.rows.schema ++ ServicesTQ.rows.schema ++ ServiceKeysTQ.rows.schema ++ MicroservicesTQ.rows.schema ++ MicroserviceKeysTQ.rows.schema ++ WorkloadsTQ.rows.schema ++ WorkloadKeysTQ.rows.schema ++ PatternsTQ.rows.schema ++ PatternKeysTQ.rows.schema
++ BctypesTQ.rows.schema ++ BlockchainsTQ.rows.schema ++ ServicesTQ.rows.schema ++ ServiceKeysTQ.rows.schema ++ ServiceDockAuthsTQ.rows.schema ++ MicroservicesTQ.rows.schema ++ MicroserviceKeysTQ.rows.schema ++ WorkloadsTQ.rows.schema ++ WorkloadKeysTQ.rows.schema ++ PatternsTQ.rows.schema ++ PatternKeysTQ.rows.schema
).create

// Alter the schema of existing tables - used to be used in /admin/upgradedb
Expand All @@ -34,7 +34,7 @@ object ExchangeApiTables {
// Note: doing this with raw sql stmts because a foreign key constraint not existing was causing slick's drops to fail. As long as we are not removing contraints (only adding), we should be ok with the drops below?
//val delete = DBIO.seq(sqlu"drop table orgs", sqlu"drop table workloads", sqlu"drop table mmicroservices", sqlu"drop table blockchains", sqlu"drop table bctypes", sqlu"drop table devmsgs", sqlu"drop table agbotmsgs", sqlu"drop table agbotagreements", sqlu"drop table agbots", sqlu"drop table devagreements", sqlu"drop table properties", sqlu"drop table microservices", sqlu"drop table nodes", sqlu"drop table users")
val delete = DBIO.seq(
sqlu"drop table if exists patternkeys", sqlu"drop table if exists patterns", sqlu"drop table if exists servicekeys", sqlu"drop table if exists services", sqlu"drop table if exists workloadkeys", sqlu"drop table if exists workloads", sqlu"drop table if exists blockchains", sqlu"drop table if exists bctypes", // no table depends on these
sqlu"drop table if exists patternkeys", sqlu"drop table if exists patterns", sqlu"drop table if exists servicedockauths", sqlu"drop table if exists servicekeys", sqlu"drop table if exists services", sqlu"drop table if exists workloadkeys", sqlu"drop table if exists workloads", sqlu"drop table if exists blockchains", sqlu"drop table if exists bctypes", // no table depends on these
sqlu"drop table if exists mmicroservices", // from older schema
sqlu"drop table if exists devmsgs", // from older schema
sqlu"drop table if exists nodemsgs", sqlu"drop table if exists agbotmsgs", // these depend on both nodes and agbots
Expand Down Expand Up @@ -124,6 +124,11 @@ object ExchangeApiTables {
val filename = dumpDir+"/servicekeys"+dumpSuffix
logger.info("dumping "+xs.size+" rows to "+filename)
new TableIo[ServiceKeyRow](filename).dump(xs)
ServiceDockAuthsTQ.rows.result
}).flatMap({ xs =>
val filename = dumpDir+"/servicedockauths"+dumpSuffix
logger.info("dumping "+xs.size+" rows to "+filename)
new TableIo[ServiceDockAuthRow](filename).dump(xs)
MicroservicesTQ.rows.result
}).flatMap({ xs =>
val filename = dumpDir+"/microservices"+dumpSuffix
Expand Down Expand Up @@ -237,6 +242,9 @@ object ExchangeApiTables {
val servicekeys = new TableIo[ServiceKeyRow](dumpDir+"/servicekeys"+dumpSuffix).load
if (servicekeys.nonEmpty) actions += (ServiceKeysTQ.rows ++= servicekeys)

val servicedockauths = new TableIo[ServiceDockAuthRow](dumpDir+"/servicedockauths"+dumpSuffix).load
if (servicedockauths.nonEmpty) actions += (ServiceDockAuthsTQ.rows ++= servicedockauths)

val microservices = new TableIo[MicroserviceRow](dumpDir+"/microservices"+dumpSuffix).load
if (microservices.nonEmpty) actions += (MicroservicesTQ.rows ++= microservices)

Expand Down
14 changes: 7 additions & 7 deletions src/main/scala/com/horizon/exchangeapi/PatternsRoutes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ case class GetPatternAttributeResponse(attribute: String, value: String)
case class PostPutPatternRequest(label: String, description: String, public: Boolean, workloads: Option[List[PWorkloads]], services: Option[List[PServices]], agreementProtocols: List[Map[String,String]]) {
protected implicit val jsonFormats: Formats = DefaultFormats
def validate(): Unit = {
if (services.isDefined) {
if (workloads.isDefined) halt(HttpCode.BAD_INPUT, ApiResponse(ApiResponseType.BAD_INPUT, "can not specify both the 'services' and 'workloads' fields."))
if (services.isDefined && services.get.nonEmpty) {
if (workloads.isDefined && workloads.get.nonEmpty) halt(HttpCode.BAD_INPUT, ApiResponse(ApiResponseType.BAD_INPUT, "can not specify both the 'services' and 'workloads' fields."))
// Check that it is signed and check the version syntax
for (s <- services.get) {
for (sv <- s.serviceVersions) {
Expand All @@ -37,8 +37,8 @@ case class PostPutPatternRequest(label: String, description: String, public: Boo
}
}
}
} else if (workloads.isDefined) {
if (services.isDefined) halt(HttpCode.BAD_INPUT, ApiResponse(ApiResponseType.BAD_INPUT, "can not specify both the 'services' and 'workloads' fields."))
} else if (workloads.isDefined && workloads.get.nonEmpty) {
if (services.isDefined && services.get.nonEmpty) halt(HttpCode.BAD_INPUT, ApiResponse(ApiResponseType.BAD_INPUT, "can not specify both the 'services' and 'workloads' fields."))
// Check that it is signed and check the version syntax
for (w <- workloads.get) {
for (wv <- w.workloadVersions) {
Expand All @@ -55,9 +55,9 @@ case class PostPutPatternRequest(label: String, description: String, public: Boo

// Build a list of db actions to verify that the referenced workloads exist
def validateServiceIds: DBIO[Vector[Int]] = {
if (services.isDefined) PatternsTQ.validateServiceIds(services.get)
else if (workloads.isDefined) PatternsTQ.validateWorkloadIds(workloads.get)
else halt(HttpCode.BAD_INPUT, ApiResponse(ApiResponseType.BAD_INPUT, "either the 'services' or 'workloads' field must be specified."))
if (services.isDefined && services.get.nonEmpty) PatternsTQ.validateServiceIds(services.get)
else if (workloads.isDefined && workloads.get.nonEmpty) PatternsTQ.validateWorkloadIds(workloads.get)
else halt(HttpCode.BAD_INPUT, ApiResponse(ApiResponseType.BAD_INPUT, "either the 'services' or 'workloads' field must be specified and not empty."))
}

// Note: write() handles correctly the case where the optional fields are None.
Expand Down
Loading

0 comments on commit 7fe47ff

Please sign in to comment.