Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor component constructor to accept logger #194

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.hyperledger.identus.walletsdk.edgeagent.protocols.issueCredential.Off
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationSubmission
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.RequestPresentation
import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import org.hyperledger.identus.walletsdk.logger.PrismLoggerMock
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLoggerMock
import org.hyperledger.identus.walletsdk.mercury.ApiMock
import org.hyperledger.identus.walletsdk.pollux.PolluxImpl
import org.hyperledger.identus.walletsdk.pollux.models.AnonCredential
Expand Down Expand Up @@ -114,7 +114,7 @@ class AnoncredsTests {
connectionManager = connectionManager,
seed = null,
api = ApiMock(statusCode = HttpStatusCode.OK, response = "{\"success\":\"true\"}"),
logger = PrismLoggerMock()
logger = EdgeAgentLoggerMock()
)

val attachmentDescriptor =
Expand Down Expand Up @@ -192,7 +192,7 @@ class AnoncredsTests {
connectionManager = connectionManager,
seed = null,
api = ApiMock(HttpStatusCode.OK, "{\"success\":\"true\"}"),
logger = PrismLoggerMock()
logger = EdgeAgentLoggerMock()
)

val attachmentDescriptor =
Expand Down Expand Up @@ -263,7 +263,7 @@ class AnoncredsTests {
connectionManager = connectionManagerMock,
seed = seed,
api = apiMock,
logger = PrismLoggerMock()
logger = EdgeAgentLoggerMock()
)

val credential = AnonCredential.fromStorableData(
Expand Down Expand Up @@ -355,7 +355,7 @@ class AnoncredsTests {
connectionManager = connectionManagerMock,
seed = seed,
api = apiMock,
logger = PrismLoggerMock()
logger = EdgeAgentLoggerMock()
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.SeedKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorableKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorablePrivateKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.TypeKey
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLogger
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLoggerImpl
import org.hyperledger.identus.walletsdk.logger.LogComponent

/**
* Apollo defines the set of cryptographic operations that are used in the Atala PRISM.
*/
class ApolloImpl : Apollo {
class ApolloImpl(
private val logger: EdgeAgentLogger = EdgeAgentLoggerImpl(LogComponent.APOLLO)
cristianIOHK marked this conversation as resolved.
Show resolved Hide resolved
) : Apollo {

/**
* Creates a random set of mnemonic phrases that can be used as a seed for generating a private key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PublicKey
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLogger
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLogger
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLoggerImpl

/**
* Castor is a powerful and flexible library for working with DIDs. Whether you are building a decentralised application
Expand All @@ -36,7 +36,7 @@ class CastorImpl
@JvmOverloads
constructor(
val apollo: Apollo,
private val logger: PrismLogger = PrismLoggerImpl(LogComponent.CASTOR)
private val logger: EdgeAgentLogger = EdgeAgentLoggerImpl(LogComponent.CASTOR)
) : Castor {
var resolvers: Array<DIDResolver> = arrayOf(
LongFormPrismDIDResolver(this.apollo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ import org.hyperledger.identus.walletsdk.domain.models.DIDUrl
import org.hyperledger.identus.walletsdk.domain.models.OctetPublicKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.KeyPair
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PublicKey
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLoggerImpl
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.kotlincrypto.hash.sha2.SHA256
import pbandk.decodeFromByteArray
import pbandk.encodeToByteArray
Expand All @@ -64,7 +64,7 @@ internal class CastorShared {
*
* @property logger The logger instance.
*/
private val logger = PrismLoggerImpl(LogComponent.CASTOR)
private val logger = EdgeAgentLoggerImpl(LogComponent.CASTOR)

/**
* parseDID parses a string representation of a Decentralized Identifier (DID) into a DID object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.RequestPresentation
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLogger
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLogger
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLoggerImpl
import org.hyperledger.identus.walletsdk.pluto.PlutoBackupTask
import org.hyperledger.identus.walletsdk.pluto.PlutoRestoreTask
import org.hyperledger.identus.walletsdk.pluto.models.backup.BackupV0_0_1
Expand Down Expand Up @@ -153,7 +153,7 @@ open class EdgeAgent {
private val edgeAgentScope: CoroutineScope = CoroutineScope(Dispatchers.Default)
private val api: Api
internal var connectionManager: ConnectionManager
private var logger: PrismLogger
private var logger: EdgeAgentLogger
private val agentOptions: AgentOptions

/**
Expand Down Expand Up @@ -181,7 +181,7 @@ open class EdgeAgent {
connectionManager: ConnectionManager,
seed: Seed?,
api: Api?,
logger: PrismLogger = PrismLoggerImpl(LogComponent.PRISM_AGENT),
logger: EdgeAgentLogger = EdgeAgentLoggerImpl(LogComponent.EDGE_AGENT),
agentOptions: AgentOptions = AgentOptions()
) {
edgeAgentScope.launch {
Expand Down Expand Up @@ -235,7 +235,7 @@ open class EdgeAgent {
seed: Seed? = null,
api: Api? = null,
mediatorHandler: MediationHandler,
logger: PrismLogger = PrismLoggerImpl(LogComponent.PRISM_AGENT),
logger: EdgeAgentLogger = EdgeAgentLoggerImpl(LogComponent.EDGE_AGENT),
agentOptions: AgentOptions = AgentOptions()
) {
edgeAgentScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ private const val METADATA_PRIVACY_STR = "------"
private val hashingLog = UUID.randomUUID().toString()

/**
* PrismLogger is an interface that defines methods for logging messages
* EdgeAgentLogger is an interface that defines methods for logging messages
* with different log levels and metadata.
*/
interface PrismLogger {
interface EdgeAgentLogger {
/**
* Logs a debug message with optional metadata.
*
Expand Down Expand Up @@ -66,22 +66,27 @@ interface PrismLogger {
* @param error The error to be logged.
* @param metadata An array of metadata objects to be included in the log message. Defaults to an empty array if not provided.
*
* @see PrismLogger.error
* @see EdgeAgentLogger.error
* @see Metadata
*/
fun error(error: Error, metadata: Array<Metadata> = arrayOf())
}

/**
* Implementation of the PrismLogger interface.
* Implementation of the EdgeAgentLogger interface.
*
* @property category the LogComponent category for this logger
*/
class PrismLoggerImpl(category: LogComponent) : PrismLogger {
class EdgeAgentLoggerImpl(category: LogComponent, private var logLevel: LogLevel = LogLevel.INFO, tag: String? = null) :
EdgeAgentLogger {

private val log = logging("[io.prism.kmm.sdk.$category]")

private var logLevel: LogLevel = LogLevel.INFO
private val log = logging(
if (tag != null) {
"$tag.$category"
} else {
"[org.hyperledger.identus.walletsdk.$category]"
}
)

/**
* Logs a debug message with optional metadata.
Expand Down Expand Up @@ -333,13 +338,13 @@ enum class LogLevel(val value: Int) {
* - MERCURY
* - PLUTO
* - POLLUX
* - PRISM_AGENT
* - EDGE_AGENT
*/
enum class LogComponent {
APOLLO,
CASTOR,
MERCURY,
PLUTO,
POLLUX,
PRISM_AGENT
EDGE_AGENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import org.hyperledger.identus.walletsdk.domain.models.DIDDocument
import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import org.hyperledger.identus.walletsdk.domain.models.MercuryError
import org.hyperledger.identus.walletsdk.domain.models.Message
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLogger
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLoggerImpl
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLogger
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.mercury.forward.ForwardMessage

/**
Expand Down Expand Up @@ -55,7 +55,7 @@ constructor(
private val castor: Castor,
private val protocol: DIDCommProtocol,
private val api: Api,
private val logger: PrismLogger = PrismLoggerImpl(LogComponent.MERCURY)
private val logger: EdgeAgentLogger = EdgeAgentLoggerImpl(LogComponent.MERCURY)
) : Mercury {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ import org.hyperledger.identus.walletsdk.domain.models.AttachmentDescriptor
import org.hyperledger.identus.walletsdk.domain.models.DID
import org.hyperledger.identus.walletsdk.domain.models.MercuryError
import org.hyperledger.identus.walletsdk.domain.models.Message
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLoggerImpl
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.mercury.ATTACHMENT_SEPARATOR
import org.hyperledger.identus.walletsdk.mercury.BASE64
import org.hyperledger.identus.walletsdk.mercury.DIDCommProtocol
import org.hyperledger.identus.walletsdk.mercury.HASH
import org.hyperledger.identus.walletsdk.mercury.JSON
import org.hyperledger.identus.walletsdk.mercury.LINKS
import java.time.Instant.now
import kotlin.jvm.Throws

/**
* Wrapper class for the DIDComm functionality.
Expand All @@ -57,7 +56,7 @@ class DIDCommWrapper(castor: Castor, pluto: Pluto, apollo: Apollo) : DIDCommProt
private val didDocResolver = DIDCommDIDResolver(castor)
private val secretsResolver = DIDCommSecretsResolver(pluto, apollo)
private val didComm = DIDComm(didDocResolver, secretsResolver)
private val logger = PrismLoggerImpl(LogComponent.MERCURY)
private val logger = EdgeAgentLoggerImpl(LogComponent.MERCURY)

/**
* Converts a JSON element to a map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.JWK
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PrivateKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorableKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorablePrivateKey
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLogger
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLoggerImpl
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.pluto.models.backup.BackupV0_0_1
import org.hyperledger.identus.walletsdk.pluto.data.DbConnection
import org.hyperledger.identus.walletsdk.pluto.data.isConnected
Expand All @@ -55,7 +58,10 @@ import org.hyperledger.identus.walletsdk.pluto.data.StorableCredential as Storab
* @property db The instance of `SdkPlutoDb` representing the connection to the database.
* @property isConnected A flag to indicate whether the database connection is established or not.
*/
class PlutoImpl(private val connection: DbConnection) : Pluto {
class PlutoImpl(
private val connection: DbConnection,
private val logger: EdgeAgentLogger = EdgeAgentLoggerImpl(LogComponent.PLUTO)
) : Pluto {
private var db: SdkPlutoDb? = null

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationSubmissionOptions
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationSubmissionOptionsAnoncreds
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationSubmissionOptionsJWT
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLogger
import org.hyperledger.identus.walletsdk.logger.EdgeAgentLoggerImpl
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.pluto.RestorationID
import org.hyperledger.identus.walletsdk.pollux.models.AnonCredential
import org.hyperledger.identus.walletsdk.pollux.models.AnoncredsPresentationDefinitionRequest
Expand All @@ -114,7 +117,8 @@ import org.hyperledger.identus.walletsdk.pollux.utils.BitString
open class PolluxImpl(
val apollo: Apollo,
val castor: Castor,
private val api: Api = ApiImpl(httpClient())
private val api: Api = ApiImpl(httpClient()),
private val logger: EdgeAgentLogger = EdgeAgentLoggerImpl(LogComponent.POLLUX)
) : Pollux {

/**
Expand Down
Loading
Loading