From db0c9ae3fbcd0b2d9cd2663a7cf0e96a6e45e76c Mon Sep 17 00:00:00 2001
From: pablof7z
Date: Wed, 28 Jun 2023 21:44:39 +0200
Subject: [PATCH] minor improvements
---
Dockerfile | 8 ++++++--
README.md | 18 ++++++++++++++++--
package.json | 4 ++--
prisma/schema.prisma | 31 +++++++++++++------------------
src/daemon/run.ts | 2 ++
src/index.ts | 2 +-
6 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index ca1b9e0..a322f76 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,15 +1,19 @@
-FROM --platform=linux/amd64 node:19 as build
+FROM --platform=linux/amd64 node:19-buster-slim as build
WORKDIR /app
COPY package.json package-lock.json .
RUN npm i
COPY src/ src/
-COPY prisma/ prisma/
+COPY prisma/schema.prisma prisma/
COPY tsconfig.json .
+RUN apt-get update -y && apt-get install -y openssl
+
RUN npm run build
+RUN npx prisma generate
RUN npx prisma migrate deploy
+
ENTRYPOINT [ "node", "dist/index.js" ]
CMD ["start"]
diff --git a/README.md b/README.md
index 0ff8201..3e7094e 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,21 @@ Daemon to remotely sign nostr events using keys.
To quickly install `nsecbunkerd` via Docker just run:
+### Prepare your config directory
```
-docker run -d --name nsecbunkerd pablof7z/nsecbunkerd start --admin
+mkdir $HOME/.nsecbunker-config
+```
+
+### Start nsecbunkerd
+```
+docker run -d --name nsecbunkerd -v $HOME/.nsecbunker-config:/app/config pablof7z/nsecbunkerd start --admin
+docker exec -i nsecbunkerd npx prisma db push
+```
+
+### Get the connection string
+
+```
+docker exec nsecbunkerd cat /app/connection.txt
```
nsecBunker will give you a connection string like:
@@ -15,7 +28,8 @@ nsecBunker will give you a connection string like:
bunker://npub1tj2dmc4udvgafxxxxxxxrtgne8j8l6rgrnaykzc8sys9mzfcz@relay.nsecbunker.com
```
-You can visit https://app.nsecbunker.com/ to administrate your nsecBunker remotely.
+You can visit https://app.nsecbunker.com/ to administrate your nsecBunker remotely, or explore `nsecbunkerd`'s CLI
+to find the options to add and approve keys from the CLI.
## Hard setup:
(If you installed via docker you don't need to do any of this, skip to the [Configure](#configure) section)
diff --git a/package.json b/package.json
index d29c137..5abc876 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "nsecbunkerd",
- "version": "0.6.2",
+ "version": "0.6.4",
"description": "nsecbunker daemon",
"main": "dist/index.js",
"bin": {
@@ -16,7 +16,7 @@
],
"repository": {
"type": "git",
- "url": "https://github.com/sanity-island/nsecbunker"
+ "url": "https://github.com/kind-0/nsecbunkerd"
},
"scripts": {
"build": "tsc",
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index be46f9c..817166b 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -1,40 +1,36 @@
-// This is your Prisma schema file,
-// learn more about it in the docs: https://pris.ly/d/prisma-schema
-
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
- url = "file:./nsecbunker.db"
+ url = "file:../config/nsecbunker.db"
}
model KeyUser {
id Int @id @default(autoincrement())
keyName String
userPubkey String
- description String?
- signingConditions SigningCondition[]
- logs Log[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
lastUsedAt DateTime?
+ description String?
+ logs Log[]
+ signingConditions SigningCondition[]
Token Token[]
@@unique([keyName, userPubkey], name: "unique_key_user")
}
model SigningCondition {
- id Int @id @default(autoincrement())
-
+ id Int @id @default(autoincrement())
method String?
kind String?
content String?
keyUserKeyName String?
allowed Boolean?
- KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
keyUserId Int?
+ KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
}
model Log {
@@ -43,18 +39,18 @@ model Log {
type String
method String?
params String?
- KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
keyUserId Int?
+ KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
}
model Policy {
id Int @id @default(autoincrement())
name String
- description String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
- deletedAt DateTime?
expiresAt DateTime?
+ deletedAt DateTime?
+ description String?
rules PolicyRule[]
Token Token[]
}
@@ -65,9 +61,8 @@ model PolicyRule {
kind String?
maxUsageCount Int?
currentUsageCount Int?
-
- Policy Policy? @relation(fields: [policyId], references: [id])
- policyId Int?
+ policyId Int?
+ Policy Policy? @relation(fields: [policyId], references: [id])
}
model Token {
@@ -81,8 +76,8 @@ model Token {
deletedAt DateTime?
expiresAt DateTime?
redeemedAt DateTime?
- KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
keyUserId Int?
- policy Policy? @relation(fields: [policyId], references: [id])
policyId Int?
+ policy Policy? @relation(fields: [policyId], references: [id])
+ KeyUser KeyUser? @relation(fields: [keyUserId], references: [id])
}
diff --git a/src/daemon/run.ts b/src/daemon/run.ts
index 1a276b6..d58be66 100644
--- a/src/daemon/run.ts
+++ b/src/daemon/run.ts
@@ -38,6 +38,8 @@ function getKeys(config: DaemonConfig) {
const key = {
name,
npub: user.npub,
+ userCount: await prisma.keyUser.count({ where: { keyName: name } }),
+ tokenCount: await prisma.token.count({ where: { keyName: name } })
};
lockedKeyNames = lockedKeyNames.filter((keyName) => keyName !== name);
diff --git a/src/index.ts b/src/index.ts
index 576d024..7ba25d8 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -68,7 +68,7 @@ const argv = yargs(hideBin(process.argv))
alias: 'c',
type: 'string',
description: 'Path to config file',
- default: 'nsecbunker.json',
+ default: 'config/nsecbunker.json',
},
})
.demandCommand(0, 1)