Skip to content

Commit

Permalink
Merge pull request #2272 from constantine2nd/develop
Browse files Browse the repository at this point in the history
getRoot endpoint
  • Loading branch information
simonredfern authored Sep 15, 2023
2 parents 8f66846 + deffc1b commit 2b99720
Show file tree
Hide file tree
Showing 23 changed files with 372 additions and 83 deletions.
11 changes: 8 additions & 3 deletions obp-api/src/main/scala/code/api/util/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,14 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
val commit = try {
val properties = new java.util.Properties()
logger.debug("Before getResourceAsStream git.properties")
properties.load(getClass().getClassLoader().getResourceAsStream("git.properties"))
logger.debug("Before get Property git.commit.id")
properties.getProperty("git.commit.id", "")
val stream = getClass().getClassLoader().getResourceAsStream("git.properties")
try {
properties.load(stream)
logger.debug("Before get Property git.commit.id")
properties.getProperty("git.commit.id", "")
} finally {
stream.close()
}
} catch {
case e : Throwable => {
logger.warn("gitCommit says: Could not return git commit. Does resources/git.properties exist?")
Expand Down
19 changes: 1 addition & 18 deletions obp-api/src/main/scala/code/api/v1_2_1/APIMethods121.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,6 @@ trait APIMethods121 {
} yield metadata
}

private def getApiInfoJSON(apiVersion : ApiVersion, apiVersionStatus : String) = {
val apiDetails: JValue = {

val organisation = APIUtil.getPropsValue("hosted_by.organisation", "TESOBE")
val email = APIUtil.getPropsValue("hosted_by.email", "[email protected]")
val phone = APIUtil.getPropsValue("hosted_by.phone", "+49 (0)30 8145 3994")
val organisationWebsite = APIUtil.getPropsValue("organisation_website", "https://www.tesobe.com")

val connector = APIUtil.getPropsValue("connector").openOrThrowException("no connector set")

val hostedBy = new HostedBy(organisation, email, phone, organisationWebsite)
val apiInfoJSON = new APIInfoJSON(apiVersion.vDottedApiVersion, apiVersionStatus, gitCommit, connector, hostedBy)
Extraction.decompose(apiInfoJSON)
}
apiDetails
}

// helper methods end here

val Implementations1_2_1 = new Object(){
Expand Down Expand Up @@ -161,7 +144,7 @@ trait APIMethods121 {
for {
_ <- Future() // Just start async call
} yield {
(getApiInfoJSON(apiVersion,apiVersionStatus), HttpCode.`200`(cc.callContext))
(JSONFactory.getApiInfoJSON(apiVersion,apiVersionStatus), HttpCode.`200`(cc.callContext))
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions obp-api/src/main/scala/code/api/v1_2_1/JSONFactory1.2.1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ package code.api.v1_2_1

import java.util.Date

import code.api.util.APIUtil
import net.liftweb.common.{Box, Full}
import code.model._
import code.api.util.APIUtil._
import com.openbankproject.commons.model._
import com.openbankproject.commons.util.ApiVersion
import net.liftweb.json.Extraction
import net.liftweb.json.JsonAST.JValue

case class APIInfoJSON(
version : String,
Expand Down Expand Up @@ -358,6 +362,24 @@ case class MakePaymentJson(
)

object JSONFactory{

def getApiInfoJSON(apiVersion : ApiVersion, apiVersionStatus : String) = {
val apiDetails: JValue = {

val organisation = APIUtil.getPropsValue("hosted_by.organisation", "TESOBE")
val email = APIUtil.getPropsValue("hosted_by.email", "[email protected]")
val phone = APIUtil.getPropsValue("hosted_by.phone", "+49 (0)30 8145 3994")
val organisationWebsite = APIUtil.getPropsValue("organisation_website", "https://www.tesobe.com")

val connector = APIUtil.getPropsValue("connector").openOrThrowException("no connector set")

val hostedBy = new HostedBy(organisation, email, phone, organisationWebsite)
val apiInfoJSON = new APIInfoJSON(apiVersion.vDottedApiVersion, apiVersionStatus, gitCommit, connector, hostedBy)
Extraction.decompose(apiInfoJSON)
}
apiDetails
}

def createBankJSON(bank : Bank) : BankJSON = {
new BankJSON(
stringOrNull(bank.bankId.value),
Expand Down
5 changes: 2 additions & 3 deletions obp-api/src/main/scala/code/api/v1_2_1/OBPAPI1.2.1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object OBPAPI1_2_1 extends OBPRestHelper with APIMethods121 with MdcLoggable wit
val versionStatus = ApiVersionStatus.STABLE.toString

lazy val endpointsOf1_2_1 = List(
Implementations1_2_1.root(version, versionStatus),
Implementations1_2_1.root,
Implementations1_2_1.getBanks,
Implementations1_2_1.bankById,
Implementations1_2_1.getPrivateAccountsAllBanks,
Expand Down Expand Up @@ -117,8 +117,7 @@ object OBPAPI1_2_1 extends OBPRestHelper with APIMethods121 with MdcLoggable wit

// Filter the possible endpoints by the disabled / enabled Props settings and add them together
val routes : List[OBPEndpoint] =
List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory
getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs)
getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs)


registerRoutes(routes, allResourceDocs, apiPrefix)
Expand Down
31 changes: 31 additions & 0 deletions obp-api/src/main/scala/code/api/v1_3_0/APIMethods130.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import code.api.util.ErrorMessages._
import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.util.{ErrorMessages, NewStyle}
import code.api.v1_2_1.JSONFactory
import code.bankconnectors.Connector
import code.model.BankX
import com.openbankproject.commons.model.BankId
Expand All @@ -18,6 +19,7 @@ import net.liftweb.json.Extraction

import scala.collection.immutable.Nil
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.Future

trait APIMethods130 {
//needs to be a RestHelper to get access to JsonGet, JsonPost, etc.
Expand All @@ -30,6 +32,35 @@ trait APIMethods130 {
val apiVersion = ApiVersion.v1_3_0 // was String "1_3_0"


resourceDocs += ResourceDoc(
root,
apiVersion,
"root",
"GET",
"/root",
"Get API Info (root)",
"""Returns information about:
|
|* API version
|* Hosted by information
|* Git Commit""",
emptyObjectJson,
apiInfoJSON,
List(UnknownError, "no connector set"),
apiTagApi :: Nil)

lazy val root : OBPEndpoint = {
case (Nil | "root" :: Nil) JsonGet _ => {
cc =>
implicit val ec = EndpointContext(Some(cc))
for {
_ <- Future() // Just start async call
} yield {
(JSONFactory.getApiInfoJSON(OBPAPI1_3_0.version, OBPAPI1_3_0.versionStatus), HttpCode.`200`(cc.callContext))
}
}
}

resourceDocs += ResourceDoc(
getCards,
apiVersion,
Expand Down
3 changes: 1 addition & 2 deletions obp-api/src/main/scala/code/api/v1_3_0/OBPAPI1_3_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ object OBPAPI1_3_0 extends OBPRestHelper with APIMethods130 with APIMethods121 w
//TODO: check all these calls to see if they should really have the same behaviour as 1.2.1

lazy val endpointsOf1_2_1 = List(
Implementations1_2_1.root(version, versionStatus),
Implementations1_2_1.getBanks,
Implementations1_2_1.bankById,
Implementations1_2_1.getPrivateAccountsAllBanks,
Expand Down Expand Up @@ -93,6 +92,7 @@ object OBPAPI1_3_0 extends OBPRestHelper with APIMethods130 with APIMethods121 w
)

val endpointsOf1_3_0 = List(
Implementations1_3_0.root,
Implementations1_3_0.getCards,
Implementations1_3_0.getCardsForBank
)
Expand All @@ -103,7 +103,6 @@ object OBPAPI1_3_0 extends OBPRestHelper with APIMethods130 with APIMethods121 w

// Filter the possible endpoints by the disabled / enabled Props settings and add them together
val routes : List[OBPEndpoint] =
List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory
getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs)

Expand Down
32 changes: 32 additions & 0 deletions obp-api/src/main/scala/code/api/v1_4_0/APIMethods140.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import code.api.util.ApiTag._
import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.util._
import code.api.v1_2_1.JSONFactory
import code.api.v1_3_0.OBPAPI1_3_0
import code.api.v1_4_0.JSONFactory1_4_0._
import code.api.v2_0_0.CreateCustomerJson
import code.atms.Atms
Expand Down Expand Up @@ -62,6 +64,36 @@ trait APIMethods140 extends MdcLoggable with APIMethods130 with APIMethods121{
val apiVersion = ApiVersion.v1_4_0 // was noV i.e. "1_4_0"
val apiVersionStatus : String = "STABLE"


resourceDocs += ResourceDoc(
root,
apiVersion,
"root",
"GET",
"/root",
"Get API Info (root)",
"""Returns information about:
|
|* API version
|* Hosted by information
|* Git Commit""",
emptyObjectJson,
apiInfoJSON,
List(UnknownError, "no connector set"),
apiTagApi :: Nil)

lazy val root : OBPEndpoint = {
case (Nil | "root" :: Nil) JsonGet _ => {
cc =>
implicit val ec = EndpointContext(Some(cc))
for {
_ <- Future() // Just start async call
} yield {
(JSONFactory.getApiInfoJSON(OBPAPI1_4_0.version, OBPAPI1_4_0.versionStatus), HttpCode.`200`(cc.callContext))
}
}
}

resourceDocs += ResourceDoc(
getCustomer,
apiVersion,
Expand Down
5 changes: 2 additions & 3 deletions obp-api/src/main/scala/code/api/v1_4_0/OBPAPI1_4_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ object OBPAPI1_4_0 extends OBPRestHelper with APIMethods140 with MdcLoggable wit
val versionStatus = ApiVersionStatus.STABLE.toString

lazy val endpointsOf1_2_1 = List(
Implementations1_2_1.root(version, versionStatus),
Implementations1_2_1.getBanks,
Implementations1_2_1.bankById,
Implementations1_2_1.getPrivateAccountsAllBanks,
Expand Down Expand Up @@ -95,6 +94,7 @@ object OBPAPI1_4_0 extends OBPRestHelper with APIMethods140 with MdcLoggable wit

// New in 1.4.0
val endpointsOf1_4_0 = List(
Implementations1_4_0.root,
Implementations1_4_0.getCustomer,
Implementations1_4_0.addCustomer,
Implementations1_4_0.getCustomersMessages,
Expand All @@ -117,8 +117,7 @@ object OBPAPI1_4_0 extends OBPRestHelper with APIMethods140 with MdcLoggable wit

// Filter the possible endpoints by the disabled / enabled Props settings and add them together
val routes : List[OBPEndpoint] =
List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory
getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_4_0, Implementations1_4_0.resourceDocs)

Expand Down
30 changes: 30 additions & 0 deletions obp-api/src/main/scala/code/api/v2_0_0/APIMethods200.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import code.api.util.NewStyle.HttpCode
import code.api.util._
import code.api.v1_2_1.OBPAPI1_2_1._
import code.api.v1_2_1.{JSONFactory => JSONFactory121}
import code.api.v1_3_0.OBPAPI1_3_0
import code.api.v1_4_0.JSONFactory1_4_0
import code.api.v1_4_0.JSONFactory1_4_0.ChallengeAnswerJSON
import code.api.v2_0_0.JSONFactory200.{privateBankAccountsListToJson, _}
Expand Down Expand Up @@ -134,6 +135,35 @@ trait APIMethods200 {



resourceDocs += ResourceDoc(
root,
apiVersion,
"root",
"GET",
"/root",
"Get API Info (root)",
"""Returns information about:
|
|* API version
|* Hosted by information
|* Git Commit""",
emptyObjectJson,
apiInfoJSON,
List(UnknownError, "no connector set"),
apiTagApi :: Nil)

lazy val root : OBPEndpoint = {
case (Nil | "root" :: Nil) JsonGet _ => {
cc =>
implicit val ec = EndpointContext(Some(cc))
for {
_ <- Future() // Just start async call
} yield {
(JSONFactory121.getApiInfoJSON(OBPAPI2_0_0.version, OBPAPI2_0_0.versionStatus), HttpCode.`200`(cc.callContext))
}
}
}



resourceDocs += ResourceDoc(
Expand Down
5 changes: 2 additions & 3 deletions obp-api/src/main/scala/code/api/v2_0_0/OBPAPI2_0_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ object OBPAPI2_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
// Note: Since we pattern match on these routes, if two implementations match a given url the first will match

lazy val endpointsOf1_2_1 = List(
Implementations1_2_1.root(version, versionStatus),
Implementations1_2_1.getBanks,
Implementations1_2_1.bankById,
// Now in 2_0_0
Expand Down Expand Up @@ -139,6 +138,7 @@ object OBPAPI2_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w

// Updated in 2.0.0 (less info about the views)
val endpointsOf2_0_0 = List(
Implementations2_0_0.root,
Implementations2_0_0.getPrivateAccountsAllBanks,
Implementations2_0_0.corePrivateAccountsAllBanks,
Implementations2_0_0.publicAccountsAllBanks,
Expand Down Expand Up @@ -194,8 +194,7 @@ object OBPAPI2_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w

// Filter the possible endpoints by the disabled / enabled Props settings and add them together
val routes : List[OBPEndpoint] =
List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory
getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_4_0, Implementations1_4_0.resourceDocs) :::
getAllowedEndpoints(endpointsOf2_0_0, Implementations2_0_0.resourceDocs)
Expand Down
31 changes: 31 additions & 0 deletions obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import code.api.util.ErrorMessages.TransactionDisabled
import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.util.{APIUtil, ApiRole, ErrorMessages, NewStyle}
import code.api.v1_2_1.JSONFactory
import code.api.v1_3_0.{JSONFactory1_3_0, _}
import code.api.v1_4_0.JSONFactory1_4_0
import code.api.v1_4_0.JSONFactory1_4_0._
Expand Down Expand Up @@ -75,6 +76,36 @@ trait APIMethods210 {
val codeContext = CodeContext(resourceDocs, apiRelations)


resourceDocs += ResourceDoc(
root,
apiVersion,
"root",
"GET",
"/root",
"Get API Info (root)",
"""Returns information about:
|
|* API version
|* Hosted by information
|* Git Commit""",
emptyObjectJson,
apiInfoJSON,
List(UnknownError, "no connector set"),
apiTagApi :: Nil)

lazy val root : OBPEndpoint = {
case (Nil | "root" :: Nil) JsonGet _ => {
cc =>
implicit val ec = EndpointContext(Some(cc))
for {
_ <- Future() // Just start async call
} yield {
(JSONFactory.getApiInfoJSON(OBPAPI2_1_0.version, OBPAPI2_1_0.versionStatus), HttpCode.`200`(cc.callContext))
}
}
}


// TODO Add example body below

resourceDocs += ResourceDoc(
Expand Down
4 changes: 2 additions & 2 deletions obp-api/src/main/scala/code/api/v2_1_0/OBPAPI2_1_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ object OBPAPI2_1_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w

// Possible Endpoints 2.1.0
val endpointsOf2_1_0 = Implementations2_1_0.sandboxDataImport ::
Implementations2_1_0.root ::
Implementations2_1_0.getTransactionRequestTypesSupportedByBank ::
Implementations2_1_0.createTransactionRequest ::
Implementations2_1_0.answerTransactionRequestChallenge ::
Expand Down Expand Up @@ -206,8 +207,7 @@ object OBPAPI2_1_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w

// Filter the possible endpoints by the disabled / enabled Props settings and add them together
val routes : List[OBPEndpoint] =
List(Implementations1_2_1.root(version, versionStatus)) ::: // For now we make this mandatory
getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_2_1, Implementations1_2_1.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_3_0, Implementations1_3_0.resourceDocs) :::
getAllowedEndpoints(endpointsOf1_4_0, Implementations1_4_0.resourceDocs) :::
getAllowedEndpoints(endpointsOf2_0_0, Implementations2_0_0.resourceDocs) :::
Expand Down
Loading

0 comments on commit 2b99720

Please sign in to comment.