Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Updates for tenant system, make cloud tenants optional and add local …
Browse files Browse the repository at this point in the history
…tenant configuration
  • Loading branch information
waltkb committed Dec 4, 2023
1 parent 28fca19 commit 86efd9c
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 24 deletions.
10 changes: 6 additions & 4 deletions src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package id.walt.db.models

import id.walt.crypto.utils.JsonUtils.toJsonObject
import id.walt.service.WalletService
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.toKotlinInstant
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonObject
import kotlinx.uuid.UUID
import kotlinx.uuid.exposed.KotlinxUUIDTable
import kotlinx.uuid.generateUUID
Expand All @@ -28,15 +30,15 @@ data class WalletOperationHistory(
val wallet: UUID,
val timestamp: Instant,
val operation: String,
val data: String,
val data: JsonObject,
) {
constructor(result: ResultRow) : this(
id = result[WalletOperationHistories.id].value,
account = result[WalletOperationHistories.account].value,
wallet = result[WalletOperationHistories.wallet].value,
timestamp = result[WalletOperationHistories.timestamp].toKotlinInstant(),
operation = result[WalletOperationHistories.operation],
data = result[WalletOperationHistories.data],
data = Json.parseToJsonElement(result[WalletOperationHistories.data]).jsonObject,
)

companion object {
Expand All @@ -45,7 +47,7 @@ data class WalletOperationHistory(
wallet = wallet.walletId,
timestamp = Clock.System.now(),
operation = operation,
data = Json.encodeToString(data)
data = data.toJsonObject()
)
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/id/walt/service/WalletServiceManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ object WalletServiceManager {
fun createWallet(forAccount: UUID): UUID {
val accountName = AccountsService.getNameFor(forAccount)

// TODO: remove testing code / lock behind dev-mode
if (accountName?.contains("multi-wallet") == true) {
val second = Wallets.insert {
it[name] = "ABC Company wallet"
it[createdOn] = Clock.System.now().toJavaInstant()
}[Wallets.id].value

AccountWalletMappings.insert {
it[account] = forAccount
it[wallet] = second
it[permissions] = AccountWalletPermissions.READ_ONLY
it[addedOn] = Clock.System.now().toJavaInstant()
}
}

val walletId = Wallets.insert {
it[name] = "Wallet of $accountName"
it[createdOn] = Clock.System.now().toJavaInstant()
Expand Down
2 changes: 1 addition & 1 deletion web/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default defineNuxtConfig({
runtimeConfig: {
public: {
projectId: process.env.ProjectId,
issuerCallbackUrl: process.env.IssuerCallbackUrl ?? "http://localhost:3000"
issuerCallbackUrl: process.env.IssuerCallbackUrl ?? "http://localhost:3000",
}
},

Expand Down
10 changes: 10 additions & 0 deletions web/src/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default defineAppConfig({
enableCloudTenants: false,
localTenant: {
name : "walt.id GmbH",
logoImage : "/svg/waltid.svg",
inWalletLogoImage : "/svg/walt-s.svg",
bgImage : "/images/start-page-background.png",
showWaltidLoadingSpinner : true,
}
})
2 changes: 0 additions & 2 deletions web/src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ InitApp();
const locale = useState<string>("locale.i18n");
const tenant = await (useTenant()).value
const bgImg = tenant?.bgImg
const name = tenant?.name
const logoImg = tenant?.logoImage
const showWaltidLoadingSpinner = tenant?.showWaltidLoadingSpinner
</script>

<style lang="postcss">
Expand Down
41 changes: 28 additions & 13 deletions web/src/composables/tenants.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
export function useTenant() {
return useState("tenant-config", async () => {
const baseTenantDomain = useRequestURL().host.replace(":3000", ":8080");
console.log("Base tenant domain is: ", baseTenantDomain)
console.log("Getting tenant config...");
const config = useAppConfig();
console.log("App config: ", config);

const { data , error } = await useFetch("http://" + baseTenantDomain + "/config/wallet");
console.log("Tenant configuration: ", data.value)
if (config.enableCloudTenants) {
const baseTenantDomain = useRequestURL().host.replace(":3000", ":8080");
console.log("Base tenant domain is: ", baseTenantDomain);

if (error.value) {
console.log("Tenant error: ", error.value.message)
throw createError({
statusCode: 404,
statusMessage: "Tenant error: " + error.value?.data?.message,
fatal: true
})
}
const { data, error } = await useFetch("http://" + baseTenantDomain + "/config/wallet");
console.log("Tenant configuration: ", data.value);

if (error.value) {
const dataMessage = error.value?.data?.message;
const localErrorMessage = error.value?.message;

console.log("Tenant error, error message: ", dataMessage);
console.log("Tenant error, data message: ", dataMessage);

return data.value;
const errorMessage = dataMessage ? dataMessage : localErrorMessage;

throw createError({
statusCode: 404,
statusMessage: "Tenant error: " + errorMessage,
fatal: true
});
}

return data.value;
} else {
return config.localTenant;
}
});
}
3 changes: 2 additions & 1 deletion web/src/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<div class="mx-auto w-full max-w-sm lg:w-96 p-3 lg:backdrop-blur-md lg:rounded-3xl lg:shadow lg:bg-neutral-100 lg:bg-opacity-40">
<div class="">
<img alt="walt.id logo" class="h-24 lg:h-16 w-auto mx-auto mt-2" :src="logoImg" />
<h2 class="mt-4 text-3xl font-bold tracking-tight text-gray-800">Sign in to your SSI wallet</h2>
<h2 v-if="name?.includes('NEOM')" class="mt-4 text-3xl font-bold tracking-tight text-gray-800 text-center" style="direction: rtl;">تسجيل الدخول إلى محفظة SSI</h2> <!-- TODO: i18n system -->
<h2 v-else class="mt-4 text-3xl font-bold tracking-tight text-gray-800">Sign in to your SSI wallet</h2>
<p class="mt-2 text-sm text-gray-600">
Or {{ " " }}
<NuxtLink class="font-medium text-blue-600 hover:text-blue-500" to="/signup">sign up for your SSI wallet</NuxtLink>!
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/signup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function validatePassword(): boolean {
}
definePageMeta({
title: "register to your wallet - walt.id",
title: "Register for your wallet - walt.id",
layout: "minimal",
auth: {
unauthenticatedOnly: true,
Expand All @@ -228,7 +228,7 @@ definePageMeta({
});
useHead({
title: "register to your wallet - walt.id",
title: "Register for your wallet - walt.id",
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/wallet/[wallet]/exchange/presentation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

<Disclosure>
<DisclosureButton class="py-2">
<ButtonsWaltButton class="bg-gray-50 text-black">View presentation definition JSON</ButtonsWaltButton>
<ButtonsWaltButton class="bg-gray-400 text-white">View presentation definition JSON</ButtonsWaltButton>
</DisclosureButton>
<DisclosurePanel class="text-gray-500 overflow-x-scroll pb-2">
<pre>{{ presentationDefinition }}</pre>
Expand Down
File renamed without changes.

0 comments on commit 86efd9c

Please sign in to comment.