Skip to content

Commit

Permalink
chore: url deprecation warning
Browse files Browse the repository at this point in the history
Signed-off-by: Pat Losoponkul <pat.losoponkul@iohk.io>
  • Loading branch information
patlo-iog committed May 14, 2024
1 parent cc1dfc3 commit b04cccb
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object AppConfig {
val urlRegex = """^(http|https)://[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(:[0-9]{1,5})?(/.*)?$""".r
urlRegex.findFirstMatchIn(url) match
case Some(_) =>
Try(java.net.URL(url)).toEither.left.map(ex /*java.net.MalformedURLException*/ =>
Try(java.net.URI(url).toURL()).toEither.left.map(ex /*java.net.MalformedURLException*/ =>
Config.Error.InvalidData(zio.Chunk.empty, ex.getMessage())
)
case _ => Left(Config.Error.InvalidData(zio.Chunk.empty, s"Invalid URL: $url"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.hyperledger.identus.iam.wallet.http.controller.WalletManagementContro
import org.hyperledger.identus.shared.models.WalletAccessContext
import zio.*

import java.net.URL
import java.net.URI
import scala.language.implicitConversions
import java.util.UUID

Expand Down Expand Up @@ -44,7 +44,9 @@ class EventControllerImpl(service: WalletManagementService) extends EventControl
request: CreateWebhookNotification
)(implicit rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, WebhookNotification] = {
for {
url <- ZIO.attempt(new URL(request.url)).mapError(e => ErrorResponse.badRequest(detail = Some(e.toString())))
url <- ZIO
.attempt(new URI(request.url).toURL())
.mapError(e => ErrorResponse.badRequest(detail = Some(e.toString())))
notificationConfig <- EventNotificationConfig.applyWallet(url, request.customHeaders.getOrElse(Map.empty))
_ <- service
.createWalletNotification(notificationConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import zio.test.*
import zio.test.Assertion.*
import zio.test.ZIOSpecDefault

import java.net.URI
import java.net.URL

object AgentInitializationSpec extends ZIOSpecDefault, PostgresTestContainerSupport, ApolloSpecHelper {
Expand Down Expand Up @@ -113,7 +114,7 @@ object AgentInitializationSpec extends ZIOSpecDefault, PostgresTestContainerSupp
test("create wallet with provided webhook") {
val url = "http://example.com"
for {
_ <- AgentInitialization.run.overrideConfig(webhookUrl = Some(URL(url)))
_ <- AgentInitialization.run.overrideConfig(webhookUrl = Some(URI(url).toURL()))
webhooks <- ZIO
.serviceWithZIO[WalletNonSecretStorage](
_.walletNotification
Expand All @@ -127,7 +128,7 @@ object AgentInitializationSpec extends ZIOSpecDefault, PostgresTestContainerSupp
val url = "http://example.com"
val apiKey = "secret"
for {
_ <- AgentInitialization.run.overrideConfig(webhookUrl = Some(URL(url)), webhookApiKey = Some(apiKey))
_ <- AgentInitialization.run.overrideConfig(webhookUrl = Some(URI(url).toURL()), webhookApiKey = Some(apiKey))
webhooks <- ZIO
.serviceWithZIO[WalletNonSecretStorage](
_.walletNotification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,32 +242,6 @@ class JdbcDIDNonSecretStorage(xa: Transactor[ContextAwareTask], xb: Transactor[T
}
}

override def listHdKeyPath(
did: PrismDID
): RIO[WalletAccessContext, Seq[(String, ArraySeq[Byte], ManagedDIDHdKeyPath)]] = {
val cxnIO =
sql"""
| SELECT
| key_id,
| operation_hash,
| key_usage,
| key_index
| FROM public.prism_did_key
| WHERE did = $did AND key_mode = ${KeyManagementMode.HD}
""".stripMargin
.query[(String, ArraySeq[Byte], VerificationRelationship | InternalKeyPurpose, Int)]
.to[List]

for {
state <- getManagedDIDState(did)
paths <- cxnIO.transactWallet(xa)
} yield state.map(_.didIndex).fold(Nil) { didIndex =>
paths.map { (keyId, operationHash, keyUsage, keyIndex) =>
(keyId, operationHash, ManagedDIDHdKeyPath(didIndex, keyUsage, keyIndex))
}
}
}

override def insertKeyMeta(
did: PrismDID,
keyId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import zio.json.*
import zio.json.ast.Json
import zio.json.ast.Json.*

import java.net.URI
import java.net.URL
import java.time.Instant
import java.util.UUID
Expand Down Expand Up @@ -123,7 +124,7 @@ package object sql {
given arraySeqByteGet: Get[ArraySeq[Byte]] = Get[Array[Byte]].map(ArraySeq.from)
given arraySeqBytePut: Put[ArraySeq[Byte]] = Put[Array[Byte]].contramap(_.toArray)

given urlGet: Get[URL] = Get[String].map(URL(_))
given urlGet: Get[URL] = Get[String].map(URI(_).toURL())
given urlPut: Put[URL] = Put[String].contramap(_.toString())

given octetKeyPairGet: Get[OctetKeyPair] = Get[String].map(OctetKeyPair.parse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import org.hyperledger.identus.mercury.model.DidId
import org.hyperledger.identus.shared.models.WalletAccessContext
import zio.*

import scala.collection.immutable.ArraySeq

trait DIDNonSecretStorage {

def getManagedDIDState(did: PrismDID): RIO[WalletAccessContext, Option[ManagedDIDState]]
Expand Down Expand Up @@ -35,8 +33,6 @@ trait DIDNonSecretStorage {
operationHash: Array[Byte]
): RIO[WalletAccessContext, Unit]

def listHdKeyPath(did: PrismDID): RIO[WalletAccessContext, Seq[(String, ArraySeq[Byte], ManagedDIDHdKeyPath)]]

/** Return a list of Managed DID as well as a count of all filtered items */
def listManagedDID(
offset: Option[Int],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ object ManagedDIDServiceSpec
ctx2 = ZLayer.succeed(WalletAccessContext(walletId2))
svc <- ZIO.service[ManagedDIDService]
storage <- ZIO.service[DIDNonSecretStorage]
urlTmp = java.net.URL("http://example.com")
urlTmp = java.net.URI("http://example.com").toURL()
peerDid1 <- svc.createAndStorePeerDID(urlTmp).provide(ctx1)
peerDid2 <- svc.createAndStorePeerDID(urlTmp).provide(ctx2)
record1 <- storage.getPeerDIDRecord(peerDid1.did)
Expand Down Expand Up @@ -563,7 +563,7 @@ object ManagedDIDServiceSpec
ctx1 = ZLayer.succeed(WalletAccessContext(walletId1))
ctx2 = ZLayer.succeed(WalletAccessContext(walletId2))
svc <- ZIO.service[ManagedDIDService]
urlTmp = java.net.URL("http://example.com")
urlTmp = java.net.URI("http://example.com").toURL()
dids1 <- ZIO.foreach(1 to 3)(_ => svc.createAndStorePeerDID(urlTmp)).provide(ctx1)
dids2 <- ZIO.foreach(1 to 3)(_ => svc.createAndStorePeerDID(urlTmp)).provide(ctx2)
ownWalletDids1 <- ZIO.foreach(dids1)(d => svc.getPeerDID(d.did).exit).provide(ctx1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import zio.*
import zio.test.*
import zio.test.Assertion.*

import java.net.URL
import java.net.URI

object JdbcWalletNonSecretStorageSpec extends ZIOSpecDefault, PostgresTestContainerSupport {

Expand Down Expand Up @@ -156,7 +156,7 @@ object JdbcWalletNonSecretStorageSpec extends ZIOSpecDefault, PostgresTestContai
for {
storage <- ZIO.service[WalletNonSecretStorage]
wallet <- createWallets(1).map(_.head)
config = EventNotificationConfig(wallet.id, URL("https://example.com"))
config = EventNotificationConfig(wallet.id, URI("https://example.com").toURL())
_ <- storage
.createWalletNotification(config)
.provide(ZLayer.succeed(WalletAccessContext(wallet.id)))
Expand All @@ -171,11 +171,11 @@ object JdbcWalletNonSecretStorageSpec extends ZIOSpecDefault, PostgresTestContai
limit = JdbcWalletNonSecretStorage.MAX_WEBHOOK_PER_WALLET
_ <- ZIO.foreach(1 to limit) { _ =>
storage
.createWalletNotification(EventNotificationConfig(wallet.id, URL("https://example.com")))
.createWalletNotification(EventNotificationConfig(wallet.id, URI("https://example.com").toURL()))
.provide(ZLayer.succeed(WalletAccessContext(wallet.id)))
}
exit <- storage
.createWalletNotification(EventNotificationConfig(wallet.id, URL("https://example.com")))
.createWalletNotification(EventNotificationConfig(wallet.id, URI("https://example.com").toURL()))
.provide(ZLayer.succeed(WalletAccessContext(wallet.id)))
.exit
} yield assert(exit)(fails(isSubtype[TooManyWebhook](anything)))
Expand All @@ -186,7 +186,7 @@ object JdbcWalletNonSecretStorageSpec extends ZIOSpecDefault, PostgresTestContai
wallets <- createWallets(2)
wallet1 = wallets.head
wallet2 = wallets.last
config = EventNotificationConfig(wallet1.id, URL("https://example.com"))
config = EventNotificationConfig(wallet1.id, URI("https://example.com").toURL())
_ <- storage
.createWalletNotification(config)
.provide(ZLayer.succeed(WalletAccessContext(wallet1.id)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hyperledger.identus.mercury.protocol.invitation

import java.net.URI
import java.net.URL
import java.{util => ju}
import org.hyperledger.identus.mercury.protocol.invitation.v2._
Expand All @@ -8,7 +9,7 @@ import io.circe.parser._

object OutOfBand {

def parseLink(url: String): Option[String] = parseLink(new URL(url))
def parseLink(url: String): Option[String] = parseLink(new URI(url).toURL())
def parseLink(url: URL): Option[String] = (url.getQuery() match {
case str if str.startsWith("_oob=") => Some(str.drop(5))
case _ => None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.hyperledger.identus.mercury.protocol.invitation
import cats.implicits._
import io.circe.syntax._
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder, HCursor}
import io.circe.{Decoder, Encoder}

sealed trait ServiceType

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hyperledger.identus.mercury.protocol.outofbandlogin

import java.net.URI
import java.net.URL
import org.hyperledger.identus.mercury

Expand All @@ -10,7 +11,7 @@ object Utils {
*/
def getNewMsgId: String = java.util.UUID.randomUUID().toString

def parseLink(url: String): Option[String] = parseLink(new URL(url))
def parseLink(url: String): Option[String] = parseLink(new URI(url).toURL())
def parseLink(url: URL): Option[String] = (url.getQuery() match {
case str if str.startsWith("_oob=") => Some(str.drop(5))
case _ => None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.hyperledger.identus.mercury.model.AttachmentDescriptor
import org.hyperledger.identus.mercury.model.AttachmentDescriptor.attachmentDescriptorEncoderV2
import munit.*
import org.hyperledger.identus.mercury.model.{LinkData, DidId}
import org.hyperledger.identus.mercury.protocol.presentproof.Presentation

class PresentationSpec extends ZSuite {

Expand Down

0 comments on commit b04cccb

Please sign in to comment.