-
Notifications
You must be signed in to change notification settings - Fork 1
Stop Using Custom Strfry Image #98
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const axios = require("axios"); | ||
| const nostrTools = require("nostr-tools"); | ||
|
|
||
| const GRAPHQL_URL = "https://api.flashapp.me/graphql"; // Replace with your actual GraphQL endpoint | ||
|
|
||
| const rl = require("readline").createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout, | ||
| terminal: false, | ||
| }); | ||
|
|
||
| const checkWhitelist = async (hexPubkey) => { | ||
| try { | ||
| let npub = nostrTools.nip19.npubEncode(hexPubkey); | ||
| const query = ` | ||
| query Query($input: IsFlashNpubInput!) { | ||
| isFlashNpub(input: $input) { | ||
| isFlashNpub | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const variables = { | ||
| input: { npub: npub }, | ||
| }; | ||
|
|
||
| console.error( | ||
| "Making API request with variables:", | ||
| JSON.stringify(variables) | ||
| ); // Log request to stderr | ||
|
|
||
| try { | ||
| const response = await axios.post( | ||
| GRAPHQL_URL, | ||
| { | ||
| query, | ||
| variables, | ||
| }, | ||
| { | ||
| headers: { "Content-Type": "application/json" }, | ||
| } | ||
| ); | ||
| console.error("API response:", response.data); // Log response to stderr | ||
| return response.data.data.isFlashNpub.isFlashNpub; | ||
| } catch (error) { | ||
| console.error("Error fetching whitelist status:", error.message); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we should add open-telemetry traces |
||
| console.error("Request variables were:", JSON.stringify(variables)); | ||
| return false; | ||
| } | ||
| } catch (error) { | ||
| console.error("Error encoding pubkey:", error.message); | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| rl.on("line", async (line) => { | ||
| let req; | ||
| let res = {}; | ||
|
|
||
| // Parse the input line | ||
| try { | ||
| req = JSON.parse(line); | ||
| } catch (error) { | ||
| console.error("Invalid JSON format:", error.message); | ||
| console.log( | ||
| JSON.stringify({ | ||
| action: "reject", | ||
| msg: "invalid JSON format", | ||
| }) | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| // Check if the request has an event ID | ||
| if (!req.event || !req.event.id) { | ||
| console.error("Missing event ID"); | ||
| console.log( | ||
| JSON.stringify({ | ||
| action: "reject", | ||
| msg: "missing event ID", | ||
| }) | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| // Set the event ID for the response | ||
| res.id = req.event.id; | ||
|
|
||
| // Check request type | ||
| if (req.type !== "new") { | ||
| console.error("Unexpected request type:", req.type); | ||
| res.action = "reject"; | ||
| res.msg = "unexpected request type"; | ||
| console.log(JSON.stringify(res)); | ||
| return; | ||
| } | ||
|
|
||
| // Check for p tag | ||
| const hexPubkey = req.event.tags.filter((t) => t[0] === "p")[0]?.[1]; | ||
| console.error("Hex pubkey is", hexPubkey, "Request event is", req.event); | ||
|
|
||
| if (!hexPubkey) { | ||
| console.error("No referenced pubkey"); | ||
| res.action = "reject"; | ||
| res.msg = "no referenced pubkey (p tag)"; | ||
| console.log(JSON.stringify(res)); | ||
| return; | ||
| } | ||
|
|
||
| // Check if the pubkey is on the whitelist via GraphQL query | ||
| const isWhitelisted = await checkWhitelist(hexPubkey); | ||
|
|
||
| if (isWhitelisted) { | ||
| res.action = "accept"; | ||
| } else { | ||
| res.action = "reject"; | ||
| res.msg = "blocked: not on white-list"; | ||
| } | ||
|
|
||
| console.log(JSON.stringify(res)); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,28 @@ spec: | |
| labels: | ||
| app: strfry | ||
| spec: | ||
| initContainers: | ||
| - name: npm-install | ||
| image: node:alpine | ||
| command: ["sh", "-c"] | ||
| args: | ||
| - | | ||
| cd /app | ||
| npm install | ||
| echo "Dependencies installed successfully" | ||
| volumeMounts: | ||
| - name: app-deps | ||
| mountPath: /app | ||
| - name: package-json | ||
| mountPath: /app/package.json | ||
| subPath: package.json | ||
| resources: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems fairly small. Not sure the load we're expecting here, but may be useful to either increase the limit or monitor resource usage |
||
| limits: | ||
| memory: 128Mi | ||
| cpu: 200m | ||
| requests: | ||
| memory: 64Mi | ||
| cpu: 50m | ||
| containers: | ||
| - name: strfry | ||
| image: {{ .Values.image.repository }}:{{ .Values.image.tag }}@sha256:{{ .Values.image.digest }} | ||
|
|
@@ -25,6 +47,12 @@ spec: | |
| subPath: strfry.conf | ||
| - name: strfry-logs | ||
| mountPath: /app/logs | ||
| - name: strfry-plugin | ||
| mountPath: /app/whitelist.js | ||
| subPath: whitelist.js | ||
| - name: app-deps | ||
| mountPath: /app/node_modules | ||
| subPath: node_modules | ||
|
|
||
| - name: vector | ||
| image: timberio/vector:0.34.X-debian | ||
|
|
@@ -37,7 +65,7 @@ spec: | |
| cpu: 100m | ||
| volumeMounts: | ||
| - name: strfry-logs | ||
| mountPath: /app/logs # changed from /logs to /app/logs | ||
| mountPath: /app/logs | ||
| - name: vector-config | ||
| mountPath: /etc/vector | ||
| readOnly: true | ||
|
|
@@ -49,8 +77,17 @@ spec: | |
| - name: strfry-conf | ||
| configMap: | ||
| name: {{ include "strfry.fullname" . }}-configmap | ||
| - name: strfry-plugin | ||
| configMap: | ||
| name: {{ include "strfry.fullname" . }}-plugin-configmap | ||
| defaultMode: 0755 | ||
| - name: package-json | ||
| configMap: | ||
| name: {{ include "strfry.fullname" . }}-package-json-configmap | ||
| - name: app-deps | ||
| emptyDir: {} | ||
| - name: strfry-logs | ||
| emptyDir: {} | ||
| - name: vector-config | ||
| configMap: | ||
| name: vector-config | ||
| name: vector-config | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking but I imagine it would be more convenient to have a |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: {{ include "strfry.fullname" . }}-package-json-configmap | ||
| data: | ||
| package.json: | | ||
| { | ||
| "name": "strfry-custom", | ||
| "version": "1.0.0", | ||
| "dependencies": { | ||
| "axios": "^1.7.7", | ||
| "nostr-tools": "^2.8.1" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: {{ include "strfry.fullname" . }}-plugin-configmap | ||
| data: | ||
| whitelist.js: | | ||
| {{ .Files.Get "files/whitelist.js" | indent 4 }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to info message?