Skip to content

Commit

Permalink
Merge pull request #2441 from hongwei1/develop
Browse files Browse the repository at this point in the history
feature/OBPv510 added new endpoint getApiTags, createConsumer and getConsumer
  • Loading branch information
simonredfern authored Nov 11, 2024
2 parents bc4ad2c + d15f4c0 commit 0d9f303
Show file tree
Hide file tree
Showing 22 changed files with 635 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2698,21 +2698,37 @@ object SwaggerDefinitionsJSON {
roles = None,
roles_info = Some("PEM Encoded Certificate does not contain PSD2 roles.")
)
lazy val consumerJsonV510: ConsumerJsonV510 = ConsumerJsonV510(
consumer_id = "d0d7b08c-f0ec-4e57-ac99-7d9eafe99225",
consumer_key = "d0d7b08c-f0ec-4e57-ac99-7d9eafe99225",
consumer_secret = "d0d7b08c-f0ec-4e57-ac99-7d9eafe99225",
app_name = "SOFI",
app_type = "Web",
description = "Account Management",
developer_email = ExampleValue.emailExample.value,
company = ExampleValue.companyExample.value,
redirect_url = "www.openbankproject.com",

val consumerJsonV510: ConsumerJsonV510 = ConsumerJsonV510(
consumer_id = consumerIdExample.value,
consumer_key = consumerKeyExample.value,
consumer_secret = consumerSecretExample.value,
app_name = appNameExample.value,
app_type = appTypeExample.value,
description = descriptionExample.value,
developer_email = emailExample.value,
company = companyExample.value,
redirect_url = redirectUrlExample.value,
certificate_pem = pem,
certificate_info = Some(certificateInfoJsonV510),
created_by_user = resourceUserJSON,
enabled = true,
created = DateWithDayExampleObject
created = DateWithDayExampleObject,
logo_url = Some(logoURLExample.value)
)

val createConsumerRequestJsonV510 = CreateConsumerRequestJsonV510(
appNameExample.value,
appTypeExample.value,
descriptionExample.value,
emailExample.value,
companyExample.value,
redirectUrlExample.value,
userIdExample.value,
true,
DateWithMsExampleObject,
"-----BEGIN CERTIFICATE-----MIICsjCCAZqgAwIBAgIGAYwQ62R0MA0GCSqGSIb3DQEBCwUAMBoxGDAWBgNVBAMMD2FwcC5leGFtcGxlLmNvbTAeFw0yMzExMjcxMzE1MTFaFw0yNTExMjYxMzE1MTFaMBoxGDAWBgNVBAMMD2FwcC5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAK9WIodZHWzKyCcf9YfWEhPURbfO6zKuMqzHN27GdqHsVVEGxP4F/J4mso+0ENcRr6ur4u81iREaVdCc40rHDHVJNEtniD8Icbz7tcsqAewIVhc/q6WXGqImJpCq7hA0m247dDsaZT0lb/MVBiMoJxDEmAE/GYYnWTEn84R35WhJsMvuQ7QmLvNg6RkChY6POCT/YKe9NKwa1NqI1U+oA5RFzAaFtytvZCE3jtp+aR0brL7qaGfgxm6B7dEpGyhg0NcVCV7xMQNq2JxZTVdAr6lcsRGaAFulakmW3aNnmK+L35Wu8uW+OxNxwUuC6f3b4FVBa276FMuUTRfu7gc+k6kCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAAU5CjEyAoyTn7PgFpQD48ZNPuUsEQ19gzYgJvHMzFIoZ7jKBodjO5mCzWBcR7A4mpeAsdyiNBl2sTiZscSnNqxk61jVzP5Ba1D7XtOjjr7+3iqowrThj6BY40QqhYh/6BSY9fDzVZQiHnvlo6ZUM5kUK6OavZOovKlp5DIl5sGqoP0qAJnpQ4nhB2WVVsKfPlOXc+2KSsbJ23g9l8zaTMr+X0umlvfEKqyEl1Fa2L1dO0y/KFQ+ILmxcZLpRdq1hRAjd0quq9qGC8ucXhRWDgM4hslVpau0da68g0aItWNez3mc5lB82b3dcZpFMzO41bgw7gvw10AvvTfQDqEYIuQ==-----END CERTIFICATE-----",
Some(logoURLExample.value)
)

val consumersJson = ConsumersJson(
Expand Down Expand Up @@ -5522,8 +5538,14 @@ object SwaggerDefinitionsJSON {
valid_from = Some(new Date()),
time_to_live = Some(3600)
)

val consumerLogoUrlJson = ConsumerLogoUrlJson(
"http://localhost:8888"
)


val consumersJsonV510 = ConsumersJsonV510(
List(consumerJsonV510)
)
//The common error or success format.
//Just some helper format to use in Json
case class NotSupportedYet()
Expand Down
3 changes: 3 additions & 0 deletions obp-api/src/main/scala/code/api/util/ApiRole.scala
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ object ApiRole extends MdcLoggable{
case class CanUpdateConsumerRedirectUrl(requiresBankId: Boolean = false) extends ApiRole
lazy val canUpdateConsumerRedirectUrl = CanUpdateConsumerRedirectUrl()

case class CanUpdateConsumerLogoUrl(requiresBankId: Boolean = false) extends ApiRole
lazy val canUpdateConsumerLogoUrl = CanUpdateConsumerLogoUrl()

case class CanCreateConsumer (requiresBankId: Boolean = false) extends ApiRole
lazy val canCreateConsumer = CanCreateConsumer()

Expand Down
5 changes: 5 additions & 0 deletions obp-api/src/main/scala/code/api/util/ApiTag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,10 @@ object ApiTag {
.values.map(_.displayTag).toSet
}

object myApp extends App{
println(ApiTag.allDisplayTagNames)
println(ApiTag.allDisplayTagNames)
}



12 changes: 8 additions & 4 deletions obp-api/src/main/scala/code/api/util/ExampleValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ object ExampleValue {
lazy val challengeExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("challenge", challengeExample)

lazy val appNameExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
lazy val appNameExample = ConnectorField("appNameBank",NoDescriptionProvided)
glossaryItems += makeGlossaryItem("app_name", appNameExample)

lazy val executionDateExample = ConnectorField("2020-01-27",NoDescriptionProvided)
Expand Down Expand Up @@ -1308,7 +1308,7 @@ object ExampleValue {
lazy val inviteesExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("invitees", inviteesExample)

lazy val appTypeExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
lazy val appTypeExample = ConnectorField("Web",NoDescriptionProvided)
glossaryItems += makeGlossaryItem("app_type", appTypeExample)

lazy val productAttributeIdExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
Expand Down Expand Up @@ -1825,8 +1825,12 @@ object ExampleValue {
lazy val purposeExample = ConnectorField(UserInvitationPurpose.DEVELOPER.toString, NoDescriptionProvided)
glossaryItems += makeGlossaryItem("purpose", purposeExample)

lazy val redirectUrlExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
lazy val redirectUrlExample = ConnectorField("https://apisandbox.openbankproject.com",NoDescriptionProvided)
glossaryItems += makeGlossaryItem("redirect_url", redirectUrlExample)


lazy val logoURLExample = ConnectorField("https://apisandbox.openbankproject.com/logo",NoDescriptionProvided)
glossaryItems += makeGlossaryItem("logo_url", logoURLExample)

lazy val roleExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("role", roleExample)
Expand Down Expand Up @@ -2272,7 +2276,7 @@ object ExampleValue {
lazy val indexExample = ConnectorField(NoExampleProvided,NoDescriptionProvided)
glossaryItems += makeGlossaryItem("index", indexExample)

lazy val descriptionExample = ConnectorField(s"This an optional field. Maximum length is ${ApiCollection.Description.maxLen}. It can be any characters here.","The human readable description here.")
lazy val descriptionExample = ConnectorField(s"Description of the object. Maximum length is ${ApiCollection.Description.maxLen}. It can be any characters here.","The human readable description here.")
glossaryItems += makeGlossaryItem("description", descriptionExample)

lazy val paymentServiceExample = ConnectorField("payments", s"The berlin group payment services, eg: payments, periodic-payments and bulk-payments. ")
Expand Down
5 changes: 3 additions & 2 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,11 @@ object NewStyle extends MdcLoggable{
appType: Option[AppType],
description: Option[String],
developerEmail: Option[String],
redirectURL: Option[String],
redirectURL: Option[String],
createdByUserId: Option[String],
logoURL: Option[String],
callContext: Option[CallContext]): Future[Consumer] = {
Future(Consumers.consumers.vend.updateConsumer(id, key, secret, isActive, name, appType, description, developerEmail, redirectURL, createdByUserId)) map {
Future(Consumers.consumers.vend.updateConsumer(id, key, secret, isActive, name, appType, description, developerEmail, redirectURL, createdByUserId, logoURL)) map {
unboxFullOrFail(_, callContext, UpdateConsumerError, 404)
}
}
Expand Down
4 changes: 3 additions & 1 deletion obp-api/src/main/scala/code/api/util/newstyle/Consumer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object Consumer {
redirectURL: Option[String],
createdByUserId: Option[String],
clientCertificate: Option[String],
logoURL: Option[String],
callContext: Option[CallContext]): OBPReturnType[Consumer] = {
Future {
Consumers.consumers.vend.createConsumer(
Expand All @@ -36,7 +37,8 @@ object Consumer {
redirectURL,
createdByUserId,
clientCertificate,
company
company,
logoURL
)
} map {
(_, callContext)
Expand Down
4 changes: 2 additions & 2 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 @@ -956,7 +956,7 @@ trait APIMethods210 {
case false => NewStyle.function.ownEntitlement("", u.userId, ApiRole.canDisableConsumers, cc.callContext)
}
consumer <- Consumers.consumers.vend.getConsumerByPrimaryId(consumerId.toLong)
updatedConsumer <- Consumers.consumers.vend.updateConsumer(consumer.id.get, None, None, Some(putData.enabled), None, None, None, None, None, None) ?~! "Cannot update Consumer"
updatedConsumer <- Consumers.consumers.vend.updateConsumer(consumer.id.get, None, None, Some(putData.enabled), None, None, None, None, None, None, None) ?~! "Cannot update Consumer"
} yield {
// Format the data as json
val json = PutEnabledJSON(updatedConsumer.isActive.get)
Expand Down Expand Up @@ -1640,7 +1640,7 @@ trait APIMethods210 {
consumer.createdByUserId.equals(u.userId)
}
//update the redirectURL and isactive (set to false when change redirectUrl) field in consumer table
updatedConsumer <- NewStyle.function.updateConsumer(consumer.id.get, None, None, Some(APIUtil.getPropsAsBoolValue("consumers_enabled_by_default", false)), None, None, None, None, Some(postJson.redirect_url), None, callContext)
updatedConsumer <- NewStyle.function.updateConsumer(consumer.id.get, None, None, Some(APIUtil.getPropsAsBoolValue("consumers_enabled_by_default", false)), None, None, None, None, Some(postJson.redirect_url), None, None, callContext)
} yield {
val json = JSONFactory210.createConsumerJSON(updatedConsumer)
(json, HttpCode.`200`(callContext))
Expand Down
4 changes: 3 additions & 1 deletion obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,9 @@ trait APIMethods220 {
Some(postedJson.developer_email),
Some(postedJson.redirect_url),
Some(u.userId),
Some(postedJson.clientCertificate)
Some(postedJson.clientCertificate),
None,
None,
)
} yield {
// Format the data as json
Expand Down
4 changes: 2 additions & 2 deletions obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ trait APIMethods310 {
CustomerNumberAlreadyExists,
UserNotFoundById,
CustomerAlreadyExistsForUser,
CreateConsumerError,
CreateCustomerError,
UnknownError
),
List(apiTagCustomer, apiTagPerson),
Expand Down Expand Up @@ -5987,7 +5987,7 @@ trait APIMethods310 {
}
consumer <- NewStyle.function.getConsumerByConsumerId(consumerId, callContext)
updatedConsumer <- Future {
Consumers.consumers.vend.updateConsumer(consumer.id.get, None, None, Some(putData.enabled), None, None, None, None, None, None) ?~! "Cannot update Consumer"
Consumers.consumers.vend.updateConsumer(consumer.id.get, None, None, Some(putData.enabled), None, None, None, None, None,None, None) ?~! "Cannot update Consumer"
}
} yield {
// Format the data as json
Expand Down
11 changes: 7 additions & 4 deletions obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5257,7 +5257,7 @@ trait APIMethods400 extends MdcLoggable {
|""",
ConsumerPostJSON(
"Test",
"Test",
"Web",
"Description",
"[email protected]",
"redirecturl",
Expand All @@ -5284,22 +5284,25 @@ trait APIMethods400 extends MdcLoggable {
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- SS.user
postedJson <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) {
json.extract[ConsumerPostJSON]
(postedJson,appType) <- NewStyle.function.tryons(InvalidJsonFormat, 400, callContext) {
val consumerPostJSON = json.extract[ConsumerPostJSON]
val appType = if(consumerPostJSON.app_type.equals("Confidential")) AppType.valueOf("Confidential") else AppType.valueOf("Public")
(consumerPostJSON, appType)
}
_ <- NewStyle.function.hasEntitlement("", u.userId, ApiRole.canCreateConsumer, callContext)
(consumer, callContext) <- createConsumerNewStyle(
key = Some(Helpers.randomString(40).toLowerCase),
secret = Some(Helpers.randomString(40).toLowerCase),
isActive = Some(postedJson.enabled),
name= Some(postedJson.app_name),
appType = None,
appType = Some(appType),
description = Some(postedJson.description),
developerEmail = Some(postedJson.developer_email),
company = None,
redirectURL = Some(postedJson.redirect_url),
createdByUserId = Some(u.userId),
clientCertificate = Some(postedJson.clientCertificate),
logoURL = None,
callContext
)
user <- Users.users.vend.getUserByUserIdFuture(u.userId)
Expand Down
Loading

0 comments on commit 0d9f303

Please sign in to comment.