Convert to Deno

This commit is contained in:
2024-06-17 14:52:29 -04:00
parent 68bccbf8ac
commit e3b0a3a2d7
6 changed files with 25 additions and 46 deletions

View File

@@ -1,3 +0,0 @@
{
"ansible.python.interpreterPath": "/home/ptoal/.virtualenvs/ansible/bin/python"
}

Binary file not shown.

View File

@@ -1,37 +0,0 @@
import { Client, Users } from 'node-appwrite';
import validator from 'validator';
// This is your Appwrite function
// It's executed each time we get a request
export default async ({ req, res, log, error }) => {
const client = new Client()
.setEndpoint('https://appwrite.oys.undock.ca/v1')
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(process.env.APPWRITE_API_KEY);
// You can log messages to the console
// log('Hello, Logs!');
// If something goes wrong, log an error
// error('Hello, Errors!');
// The `req` object contains the request data
if (req.headers['x-appwrite-user-jwt']) {
const [_,path,userId] = req.path.split('/')
if (req.method === 'GET' && path === 'userinfo' && validator.isByteLength(userId,{min: 1, max: 32})) {
// Send a response with the res object helpers
// `res.send()` dispatches a string back to the client
const users = new Users(client);
const user = await users.get(userId);
return res.json({'name':user.name});
} else {
error('Query Error');
return res.send("Query Error", 404);
}
} else {
return res.send('Unauthorized',403)
}
};

File diff suppressed because one or more lines are too long

View File

@@ -1,12 +1,13 @@
---
- name: Provision Beta Test User Accounts
hosts: appwrite:&prod
hosts: appwrite
gather_facts: false
tasks:
- name: Load json for boats
ansible.builtin.set_fact:
boat_docs: "{{ lookup( 'ansible.builtin.file', 'files/database/boat.json' ) | ansible.builtin.from_json }}"
interval_template_docs: "{{ lookup( 'ansible.builtin.file', 'files/database/intervalTemplate.json' ) | ansible.builtin.from_json }}"
- name: Use Appwrite REST API to Load data
ansible.builtin.uri:
@@ -25,3 +26,21 @@
register: appwrite_api_result
loop: '{{ boat_docs.documents }}'
delegate_to: localhost
- name: Use Appwrite REST API to Load IntervalTemplate data
ansible.builtin.uri:
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}/collections/intervalTemplate/documents"
method: POST
body_format: json
headers:
X-Appwrite-Response-Format: '{{ appwrite_response_format }}'
X-Appwrite-Project: '{{ appwrite_project }}'
X-Appwrite-Key: '{{ appwrite_api_key }}'
body:
documentId: "{{ item['$id'] }}"
data: "{{ item| ansible.utils.remove_keys(target=['$id','$databaseId','$collectionId']) }}"
status_code: [201, 409]
return_content: true
register: appwrite_api_result
loop: '{{ interval_template_docs.documents }}'
delegate_to: localhost

View File

@@ -1,7 +1,7 @@
---
# TODO: This doesn't have any real idempotency. Can't compare current and desired states.
- name: Provision Database
hosts: prod:&appwrite
hosts: appwrite
gather_facts: false
module_defaults:
ansible.builtin.uri:
@@ -34,7 +34,7 @@
permissions: "{{ item.permissions }}"
status_code: [201, 409]
register: appwrite_api_result
loop: '{{ bab_database.collections }}'
loop: '{{ db_schema.collections }}'
delegate_to: localhost
# - name: Create Attributes
@@ -46,12 +46,12 @@
- name: Create Attributes
ansible.builtin.uri:
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}/collections/{{ item[0].id }}/attributes/{{ (item[1].format is defined and item[1].format != '' ) |ternary(item[1].format, item[1].type) }}"
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}/collections/{{ item[0].id }}/attributes/{{ ( item[1].format is defined and item[1].format != '' ) |ternary(item[1].format, item[1].type) }}"
method: POST
body: "{{ lookup('ansible.builtin.template', 'appwrite_attribute_template.json.j2') }}"
status_code: [202, 409]
register: appwrite_api_result
loop: "{{ bab_database.collections | subelements('attributes', skip_missing=True) }}"
loop: "{{ db_schema.collections | subelements('attributes', skip_missing=True) }}"
delegate_to: localhost
# - name: Display response