chore: static-typed structure for apiConfig

This commit is contained in:
MishkaRogachev 2024-06-26 18:36:29 +02:00
parent d5084d43e4
commit cef6db81d6
5 changed files with 45 additions and 23 deletions

View File

@ -271,14 +271,3 @@ var NODE_CONFIG* = %* {
}, },
"OutputMessageCSVEnabled": false "OutputMessageCSVEnabled": false
} }
var STATUS_NODE_API_CONFIG* = %* {
"APIModules": "connector",
"ConnectorEnabled": true,
"HTTPEnabled": true,
"HTTPHost": "0.0.0.0",
"HTTPPort": 8545,
"WSEnabled": true,
"WSHost": "0.0.0.0",
"WSPort": 8586,
}

View File

@ -0,0 +1,33 @@
import json
type APIConfig* = object
apiModules*: string
connectorEnabled*: bool
httpEnabled*: bool
httpHost*: string
httpPort*: int
wsEnabled*: bool
wsHost*: string
wsPort*: int
proc defaultAPIConfig*(): APIConfig =
result.apiModules = "connector"
result.connectorEnabled = true
result.httpEnabled = true
result.httpHost = "0.0.0.0"
result.httpPort = 8545
result.wsEnabled = true
result.wsHost = "0.0.0.0"
result.wsPort = 8586
proc toJson*(self: APIConfig): JsonNode =
return %* {
"apiModules": self.apiModules,
"connectorEnabled": self.connectorEnabled,
"httpEnabled": self.httpEnabled,
"httpHost": self.httpHost,
"httpPort": self.httpPort,
"wsEnabled": self.wsEnabled,
"wsHost": self.wsHost,
"wsPort": self.wsPort
}

View File

@ -1,9 +1,11 @@
import json, std/options import json, std/options
import ./wallet_secretes_config import wallet_secretes_config
import ./image_crop_rectangle import image_crop_rectangle
import api_config
export wallet_secretes_config export wallet_secretes_config
export image_crop_rectangle export image_crop_rectangle
export api_config
type type
CreateAccountRequest* = object CreateAccountRequest* = object
@ -40,7 +42,7 @@ type
keycardInstanceUID*: string keycardInstanceUID*: string
keycardPairingDataFile*: string keycardPairingDataFile*: string
apiConfig*: Option[JsonNode] apiConfig*: APIConfig
proc toJson*(self: CreateAccountRequest): JsonNode = proc toJson*(self: CreateAccountRequest): JsonNode =
result = %*{ result = %*{
@ -60,6 +62,7 @@ proc toJson*(self: CreateAccountRequest): JsonNode =
"upstreamConfig": self.upstreamConfig, "upstreamConfig": self.upstreamConfig,
"keycardInstanceUID": self.keycardInstanceUID, "keycardInstanceUID": self.keycardInstanceUID,
"keycardPairingDataFile": self.keycardPairingDataFile, "keycardPairingDataFile": self.keycardPairingDataFile,
"apiConfig": self.apiConfig
} }
if self.logLevel.isSome(): if self.logLevel.isSome():
@ -91,6 +94,3 @@ proc toJson*(self: CreateAccountRequest): JsonNode =
for key, value in self.walletSecretsConfig.toJson().pairs(): for key, value in self.walletSecretsConfig.toJson().pairs():
result[key] = value result[key] = value
if self.apiConfig.isSome():
result["apiConfig"] = %self.apiConfig.get()

View File

@ -1,7 +1,9 @@
import json, std/options import json, std/options
import wallet_secretes_config import wallet_secretes_config
import api_config
export wallet_secretes_config export wallet_secretes_config
export api_config
type type
LoginAccountRequest* = object LoginAccountRequest* = object
@ -14,7 +16,7 @@ type
keycardWhisperPrivateKey*: string keycardWhisperPrivateKey*: string
mnemonic*: string mnemonic*: string
walletSecretsConfig*: WalletSecretsConfig walletSecretsConfig*: WalletSecretsConfig
apiConfig*: Option[JsonNode] apiConfig*: APIConfig
proc toJson*(self: LoginAccountRequest): JsonNode = proc toJson*(self: LoginAccountRequest): JsonNode =
result = %* { result = %* {
@ -26,9 +28,7 @@ proc toJson*(self: LoginAccountRequest): JsonNode =
"bandwidthStatsEnabled": self.bandwidthStatsEnabled, "bandwidthStatsEnabled": self.bandwidthStatsEnabled,
"keycardWhisperPrivateKey": self.keycardWhisperPrivateKey, "keycardWhisperPrivateKey": self.keycardWhisperPrivateKey,
"mnemonic": self.mnemonic, "mnemonic": self.mnemonic,
"apiConfig": self.apiConfig
} }
for key, value in self.walletSecretsConfig.toJson().pairs(): for key, value in self.walletSecretsConfig.toJson().pairs():
result[key] = value result[key] = value
if self.apiConfig.isSome():
result["apiConfig"] = %self.apiConfig.get()

View File

@ -238,7 +238,7 @@ QtObject:
torrentConfigPort: some(TORRENT_CONFIG_PORT), torrentConfigPort: some(TORRENT_CONFIG_PORT),
keycardPairingDataFile: main_constants.KEYCARDPAIRINGDATAFILE, keycardPairingDataFile: main_constants.KEYCARDPAIRINGDATAFILE,
walletSecretsConfig: self.buildWalletSecrets(), walletSecretsConfig: self.buildWalletSecrets(),
apiConfig: some(STATUS_NODE_API_CONFIG) apiConfig: defaultApiConfig()
) )
proc createAccountAndLogin*(self: Service, password: string, displayName: string, imagePath: string, imageCropRectangle: ImageCropRectangle): string = proc createAccountAndLogin*(self: Service, password: string, displayName: string, imagePath: string, imageCropRectangle: ImageCropRectangle): string =
@ -422,7 +422,7 @@ QtObject:
mnemonic: mnemonic, mnemonic: mnemonic,
walletSecretsConfig: self.buildWalletSecrets(), walletSecretsConfig: self.buildWalletSecrets(),
bandwidthStatsEnabled: true, bandwidthStatsEnabled: true,
apiConfig: some(STATUS_NODE_API_CONFIG) apiConfig: defaultApiConfig()
) )
if main_constants.runtimeLogLevelSet(): if main_constants.runtimeLogLevelSet():