Update appwrite provitioning
This commit is contained in:
24
appwrite.json
Normal file
24
appwrite.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"projectId": "65ede55a213134f2b688",
|
||||||
|
"projectName": "oys-dev",
|
||||||
|
"functions": [
|
||||||
|
{
|
||||||
|
"$id": "664038294b5473ef0c8d",
|
||||||
|
"name": "userinfo",
|
||||||
|
"runtime": "node-16.0",
|
||||||
|
"execute": ["any"],
|
||||||
|
"events": [],
|
||||||
|
"schedule": "",
|
||||||
|
"timeout": 15,
|
||||||
|
"enabled": true,
|
||||||
|
"logging": true,
|
||||||
|
"entrypoint": "src/main.js",
|
||||||
|
"commands": "npm install",
|
||||||
|
"ignore": [
|
||||||
|
"node_modules",
|
||||||
|
".npm"
|
||||||
|
],
|
||||||
|
"path": "functions/userinfo"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import { Client,Users } from 'node-appwrite';
|
|
||||||
|
|
||||||
// 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.toal.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']) {
|
|
||||||
if (req.method === 'GET') {
|
|
||||||
// Send a response with the res object helpers
|
|
||||||
// `res.send()` dispatches a string back to the client
|
|
||||||
|
|
||||||
const users = new Users(client);
|
|
||||||
|
|
||||||
const queryid = req.query.id
|
|
||||||
|
|
||||||
log(client)
|
|
||||||
log(req)
|
|
||||||
const user = await users.get(queryid)
|
|
||||||
return res.json(user);
|
|
||||||
|
|
||||||
// } else {
|
|
||||||
// return res.send("Must log in")
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -34,7 +34,7 @@ Sample `200` Response:
|
|||||||
## ⚙️ Configuration
|
## ⚙️ Configuration
|
||||||
|
|
||||||
| Setting | Value |
|
| Setting | Value |
|
||||||
|-------------------|---------------|
|
| ----------------- | ------------- |
|
||||||
| Runtime | Node (16.0) |
|
| Runtime | Node (16.0) |
|
||||||
| Entrypoint | `src/main.js` |
|
| Entrypoint | `src/main.js` |
|
||||||
| Build Commands | `npm install` |
|
| Build Commands | `npm install` |
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
"name": "starter-template",
|
"name": "starter-template",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-appwrite": "^9.0.0"
|
"node-appwrite": "^9.0.0",
|
||||||
|
"validator": "^13.12.0",
|
||||||
|
"validatorjs": "^3.22.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^3.0.0"
|
"prettier": "^3.0.0"
|
||||||
@@ -20,11 +22,11 @@
|
|||||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "1.4.0",
|
"version": "1.6.8",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
|
||||||
"integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==",
|
"integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.15.0",
|
"follow-redirects": "^1.15.6",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"proxy-from-env": "^1.1.0"
|
"proxy-from-env": "^1.1.0"
|
||||||
}
|
}
|
||||||
@@ -49,9 +51,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/follow-redirects": {
|
"node_modules/follow-redirects": {
|
||||||
"version": "1.15.2",
|
"version": "1.15.6",
|
||||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
|
||||||
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
|
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "individual",
|
"type": "individual",
|
||||||
@@ -127,6 +129,19 @@
|
|||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||||
|
},
|
||||||
|
"node_modules/validator": {
|
||||||
|
"version": "13.12.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz",
|
||||||
|
"integrity": "sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/validatorjs": {
|
||||||
|
"version": "3.22.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/validatorjs/-/validatorjs-3.22.1.tgz",
|
||||||
|
"integrity": "sha512-451KiCt/3E8qV/8fOUdO0YkA8zUdQBNVxubg9jvgEB+JAg9IlRKrClzwq2ir2ndj7TWmPYQ7bXFb4BxcyX2iWw=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "starter-template",
|
"name": "userinfo",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
"format": "prettier --write ."
|
"format": "prettier --write ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-appwrite": "^9.0.0"
|
"node-appwrite": "^9.0.0",
|
||||||
|
"validator": "^13.12.0",
|
||||||
|
"validatorjs": "^3.22.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^3.0.0"
|
"prettier": "^3.0.0"
|
||||||
37
functions/userinfo/src/main.js
Normal file
37
functions/userinfo/src/main.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
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.toal.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)
|
||||||
|
}
|
||||||
|
};
|
||||||
1
playbooks/files/database/boat.json
Normal file
1
playbooks/files/database/boat.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"total": 4, "documents": [{"name": "ProjectX", "displayName": "PX", "class": "J/27", "year": null, "imgSrc": "https://appwrite.toal.ca/v1/storage/buckets/663594f7001155eee5aa/files/663595c800394eaed548/view?project=65ede55a213134f2b688&mode=admin", "iconSrc": "https://appwrite.toal.ca/v1/storage/buckets/663594f7001155eee5aa/files/663595bd002db349c47b/view?project=65ede55a213134f2b688&mode=admin", "requiredCerts": [], "maxPassengers": 8, "defects": [], "bookingAvailable": null, "$id": "663594a70039a8408753", "$createdAt": "2024-05-04T01:51:35.800+00:00", "$updatedAt": "2024-05-04T01:59:25.214+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "66341910003e287cd71c"}, {"name": "Take5", "displayName": "T5", "class": "J/27", "year": null, "imgSrc": "https://appwrite.toal.ca/v1/storage/buckets/663594f7001155eee5aa/files/663595c800394eaed548/view?project=65ede55a213134f2b688&mode=admin", "iconSrc": "https://appwrite.toal.ca/v1/storage/buckets/663594f7001155eee5aa/files/663595ad002e45213604/view?project=65ede55a213134f2b688&mode=admin", "requiredCerts": [], "maxPassengers": 8, "defects": [], "bookingAvailable": null, "$id": "663596b9000235ffea55", "$createdAt": "2024-05-04T02:00:24.871+00:00", "$updatedAt": "2024-05-04T02:00:24.871+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "66341910003e287cd71c"}, {"name": "Wee Beestie", "displayName": "WB", "class": "Capri 25", "year": null, "imgSrc": "https://apidev.bab.toal.ca/v1/storage/buckets/663594f7001155eee5aa/files/663595d1002085458d4a/view?project=65ede55a213134f2b688", "iconSrc": null, "requiredCerts": [], "maxPassengers": 8, "defects": [], "bookingAvailable": null, "$id": "663597030029b71c7a9b", "$createdAt": "2024-05-04T02:01:39.517+00:00", "$updatedAt": "2024-05-04T02:29:32.827+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "66341910003e287cd71c"}, {"name": "Just My Imagination", "displayName": "JMI", "class": "Siruis 28", "year": null, "imgSrc": "https://appwrite.toal.ca/v1/storage/buckets/663594f7001155eee5aa/files/663595980004adc65134/view?project=65ede55a213134f2b688&mode=admin", "iconSrc": null, "requiredCerts": [], "maxPassengers": 8, "defects": [], "bookingAvailable": true, "$id": "66359729003825946ae1", "$createdAt": "2024-05-04T02:02:17.749+00:00", "$updatedAt": "2024-05-04T11:08:42.882+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "66341910003e287cd71c"}]}
|
||||||
1
playbooks/files/database/interval.json
Normal file
1
playbooks/files/database/interval.json
Normal file
File diff suppressed because one or more lines are too long
1
playbooks/files/database/intervalTemplate.json
Normal file
1
playbooks/files/database/intervalTemplate.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"total": 2, "documents": [{"name": "Weekend - Summer", "timeTuple": ["07:00", "11:00", "11:00", "15:00"], "$id": "663c17d70010075c2506", "$createdAt": "2024-05-09T00:24:54.989+00:00", "$updatedAt": "2024-05-09T02:27:55.456+00:00", "$permissions": ["read(\"user:65ede5a2ca44888379bd\")", "update(\"user:65ede5a2ca44888379bd\")", "delete(\"user:65ede5a2ca44888379bd\")"], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "66361f480007fdd639af"}, {"name": "Weekday - Summer", "timeTuple": ["09:00", "12:00", "12:00", "15:00", "15:00", "18:00"], "$id": "663d0890001d054f9cd2", "$createdAt": "2024-05-09T17:32:00.192+00:00", "$updatedAt": "2024-05-10T12:32:42.320+00:00", "$permissions": ["read(\"user:65ede5a2ca44888379bd\")", "update(\"user:65ede5a2ca44888379bd\")", "delete(\"user:65ede5a2ca44888379bd\")"], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "66361f480007fdd639af"}]}
|
||||||
1
playbooks/files/database/reservation.json
Normal file
1
playbooks/files/database/reservation.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"total": 3, "documents": [{"user": "65ede5a2ca44888379bd", "start": "2024-05-13T16:00:00.000+00:00", "end": "2024-05-13T19:00:00.000+00:00", "resource": "66359729003825946ae1", "status": "tentative", "$id": "663f8a0b000d219e05c6", "$createdAt": "2024-05-11T15:08:58.860+00:00", "$updatedAt": "2024-05-14T01:50:04.662+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "663f8847000b8f5e29bb"}, {"user": "rich.ohare", "start": "2024-05-17T13:00:00.000+00:00", "end": "2024-05-17T16:00:00.000+00:00", "resource": "66359729003825946ae1", "status": "tentative", "$id": "663f8d880005f9c86b11", "$createdAt": "2024-05-11T15:23:51.749+00:00", "$updatedAt": "2024-05-14T01:49:19.743+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "663f8847000b8f5e29bb"}, {"user": "663e66b200284eb00659", "start": "2024-05-18T13:00:00.000+00:00", "end": "2024-05-18T16:00:00.000+00:00", "resource": "663597030029b71c7a9b", "status": "tentative", "$id": "6642bf91001a583ae6dc", "$createdAt": "2024-05-14T01:34:09.029+00:00", "$updatedAt": "2024-05-17T22:29:26.569+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "663f8847000b8f5e29bb"}]}
|
||||||
1
playbooks/files/database/skillTag.json
Normal file
1
playbooks/files/database/skillTag.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"total": 3, "documents": [{"name": "basic", "description": "Basic Skills", "tagColour": "", "$id": "660725e4666f2c2ed4b2", "$createdAt": "2024-03-29T20:34:44.420+00:00", "$updatedAt": "2024-04-07T16:19:07.205+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "66072582a74d94a4bd01"}, {"name": "intermediate", "description": "Intermediate Skills", "tagColour": "", "$id": "660725f01f0c4fd286e9", "$createdAt": "2024-03-29T20:34:56.127+00:00", "$updatedAt": "2024-04-07T16:18:56.523+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "66072582a74d94a4bd01"}, {"name": "advanced", "description": "Advanced Skills", "tagColour": "", "$id": "660725f9d40e34565514", "$createdAt": "2024-03-29T20:35:05.869+00:00", "$updatedAt": "2024-04-07T16:18:45.953+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "66072582a74d94a4bd01"}]}
|
||||||
1
playbooks/files/database/task.json
Normal file
1
playbooks/files/database/task.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"total": 5, "documents": [{"title": "Wash Boat", "description": "Wash the deck, and hull<br>", "required_skills": ["660725e4666f2c2ed4b2"], "tags": ["65ee231947b1dceca3ef"], "duration": 2, "volunteers": [], "volunteers_required": 2, "status": "ready", "depends_on": [], "boat": "", "due_date": "2024-04-02T00:00:00.000+00:00", "$id": "660c73e3c42d9027ffde", "$createdAt": "2024-04-02T21:08:51.804+00:00", "$updatedAt": "2024-04-08T01:27:34.750+00:00", "$permissions": ["read(\"user:65ede5a2ca44888379bd\")", "update(\"user:65ede5a2ca44888379bd\")", "delete(\"user:65ede5a2ca44888379bd\")"], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "65ee1cd5b550023fae4f"}, {"title": "Float the plane", "description": "What does this have to do with boats?<br>", "required_skills": ["660725f9d40e34565514"], "tags": ["65ee231947b1dceca3ef"], "duration": 4, "volunteers": [], "volunteers_required": 2, "status": "ready", "depends_on": [null], "boat": "4", "due_date": "2024-04-05T00:00:00.000+00:00", "$id": "66109c930ed300707ad6", "$createdAt": "2024-04-06T00:51:31.061+00:00", "$updatedAt": "2024-05-03T18:27:55.819+00:00", "$permissions": ["read(\"user:65ede5a2ca44888379bd\")", "update(\"user:65ede5a2ca44888379bd\")", "delete(\"user:65ede5a2ca44888379bd\")"], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "65ee1cd5b550023fae4f"}, {"title": "Testing 123", "description": "This is a testing.<br>", "required_skills": ["660725e4666f2c2ed4b2", "660725f01f0c4fd286e9"], "tags": ["65ee231947b1dceca3ef", "65ee235be89c369cad44"], "duration": 2, "volunteers": [], "volunteers_required": 2, "status": "ready", "depends_on": [], "boat": "2", "due_date": "2024-04-06T00:00:00.000+00:00", "$id": "66118c702d4b5ed06979", "$createdAt": "2024-04-06T17:54:56.186+00:00", "$updatedAt": "2024-04-08T01:27:43.278+00:00", "$permissions": ["read(\"user:65ede5a2ca44888379bd\")", "update(\"user:65ede5a2ca44888379bd\")", "delete(\"user:65ede5a2ca44888379bd\")"], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "65ee1cd5b550023fae4f"}, {"title": "Repair Rudder ", "description": "Rudder is broken. Fix it", "required_skills": ["660725f01f0c4fd286e9"], "tags": ["65ee231947b1dceca3ef"], "duration": 5, "volunteers": [], "volunteers_required": 2, "status": "ready", "depends_on": [], "boat": "3", "due_date": "2024-04-12T00:00:00.000+00:00", "$id": "6614745a1f576420fbed", "$createdAt": "2024-04-08T22:48:58.128+00:00", "$updatedAt": "2024-04-08T22:48:58.128+00:00", "$permissions": ["read(\"user:65ede5a2ca44888379bd\")", "update(\"user:65ede5a2ca44888379bd\")", "delete(\"user:65ede5a2ca44888379bd\")"], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "65ee1cd5b550023fae4f"}, {"title": "Test 53", "description": "", "required_skills": [], "tags": [], "duration": 0, "volunteers": [], "volunteers_required": 0, "status": "ready", "depends_on": [], "boat": null, "due_date": "2024-05-03T00:00:00.000+00:00", "$id": "6634c914ec70293b93a1", "$createdAt": "2024-05-03T11:23:00.969+00:00", "$updatedAt": "2024-05-03T11:23:00.969+00:00", "$permissions": ["read(\"user:65ede5a2ca44888379bd\")", "update(\"user:65ede5a2ca44888379bd\")", "delete(\"user:65ede5a2ca44888379bd\")"], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "65ee1cd5b550023fae4f"}]}
|
||||||
1
playbooks/files/database/taskTag.json
Normal file
1
playbooks/files/database/taskTag.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"total": 2, "documents": [{"description": "Tasks required for Launch", "name": "launch", "colour": null, "$id": "65ee231947b1dceca3ef", "$createdAt": "2024-03-10T21:16:09.294+00:00", "$updatedAt": "2024-03-30T14:16:46.407+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "65ee21d72d5c8007c34c"}, {"description": "Tasks related to Haulout", "name": "haulout", "colour": null, "$id": "65ee235be89c369cad44", "$createdAt": "2024-03-10T21:17:15.952+00:00", "$updatedAt": "2024-03-30T14:16:32.125+00:00", "$permissions": [], "$databaseId": "65ee1cbf9c2493faf15f", "$collectionId": "65ee21d72d5c8007c34c"}]}
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
- name: Create Problem Template # noqa: no-relative-paths
|
- name: Create Problem Template # noqa: no-relative-paths
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
src: '../templates/cpuhog_ticket.j2'
|
src: 'cpuhog_ticket.j2'
|
||||||
dest: /tmp/cpuhog_details.txt
|
dest: /tmp/cpuhog_details.txt
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
|
|||||||
27
playbooks/load_data.yml
Normal file
27
playbooks/load_data.yml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
- name: Provision Beta Test User Accounts
|
||||||
|
hosts: appwrite:&prod
|
||||||
|
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 }}"
|
||||||
|
|
||||||
|
- name: Use Appwrite REST API to Load data
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}/collections/boat/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: '{{ boat_docs.documents }}'
|
||||||
|
delegate_to: localhost
|
||||||
59
playbooks/provision_database.yml
Normal file
59
playbooks/provision_database.yml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
---
|
||||||
|
# TODO: This doesn't have any real idempotency. Can't compare current and desired states.
|
||||||
|
- name: Provision Database
|
||||||
|
hosts: prod:&appwrite
|
||||||
|
gather_facts: false
|
||||||
|
module_defaults:
|
||||||
|
ansible.builtin.uri:
|
||||||
|
body_format: json
|
||||||
|
headers:
|
||||||
|
X-Appwrite-Response-Format: '{{ appwrite_response_format }}'
|
||||||
|
X-Appwrite-Project: '{{ appwrite_project }}'
|
||||||
|
X-Appwrite-Key: '{{ appwrite_api_key }}'
|
||||||
|
return_content: true
|
||||||
|
tasks:
|
||||||
|
- name: Use Appwrite REST API to create new database
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ appwrite_api_uri }}/databases"
|
||||||
|
method: POST
|
||||||
|
body:
|
||||||
|
databaseId: "{{ bab_database.id }}"
|
||||||
|
name: "{{ bab_database.name }}"
|
||||||
|
enabled: "{{ bab_database.enabled }}"
|
||||||
|
status_code: [201, 409]
|
||||||
|
register: appwrite_api_result
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
- name: Create Collections
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}/collections/"
|
||||||
|
method: POST
|
||||||
|
body:
|
||||||
|
collectionId: "{{ item.id }}"
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
permissions: "{{ item.permissions }}"
|
||||||
|
status_code: [201, 409]
|
||||||
|
register: appwrite_api_result
|
||||||
|
loop: '{{ bab_database.collections }}'
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
# - name: Create Attributes
|
||||||
|
# ansible.builtin.debug:
|
||||||
|
# msg: "{{ lookup('ansible.builtin.template', 'appwrite_attribute_template.json.j2') }}"
|
||||||
|
# register: appwrite_api_result
|
||||||
|
# loop: "{{ bab_database.collections | subelements('attributes', skip_missing=True) }}"
|
||||||
|
# # delegate_to: localhost
|
||||||
|
|
||||||
|
- 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) }}"
|
||||||
|
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) }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
# - name: Display response
|
||||||
|
# ansible.builtin.debug:
|
||||||
|
# var: appwrite_api_result
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: Provision Beta Test User Accounts
|
- name: Provision Beta Test User Accounts
|
||||||
hosts: apidev.bab.toal.ca
|
hosts: appwrite:&prod
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: Use Appwrite REST API to create new user
|
- name: Use Appwrite REST API to create new user
|
||||||
|
|||||||
52
playbooks/read_database.yml
Normal file
52
playbooks/read_database.yml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
---
|
||||||
|
- name: Gather Information about Database
|
||||||
|
hosts: appwrite:&dev
|
||||||
|
gather_facts: false
|
||||||
|
module_defaults:
|
||||||
|
ansible.builtin.uri:
|
||||||
|
body_format: json
|
||||||
|
headers:
|
||||||
|
X-Appwrite-Response-Format: '{{ appwrite_response_format }}'
|
||||||
|
X-Appwrite-Project: '{{ appwrite_project }}'
|
||||||
|
X-Appwrite-Key: '{{ appwrite_api_key }}'
|
||||||
|
return_content: true
|
||||||
|
tasks:
|
||||||
|
- name: Get Users
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ appwrite_api_uri }}/users"
|
||||||
|
method: GET
|
||||||
|
register: appwrite_api_result
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
- name: Display response
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: appwrite_api_result
|
||||||
|
|
||||||
|
- name: Get database info
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}"
|
||||||
|
method: GET
|
||||||
|
register: appwrite_api_result
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
- name: Get collection info
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}/collections"
|
||||||
|
method: GET
|
||||||
|
register: appwrite_collections
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
- name: Get documents from each table
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}/collections/{{ item['$id'] }}/documents"
|
||||||
|
method: GET
|
||||||
|
loop: "{{ appwrite_collections.json.collections }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
register: document_results
|
||||||
|
|
||||||
|
- name: Save Data
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: 'files/database/{{ item.item.name }}.json'
|
||||||
|
content: '{{ item.json }}'
|
||||||
|
loop: "{{ document_results.results }}"
|
||||||
|
delegate_to: localhost
|
||||||
11
playbooks/templates/appwrite_attribute_template.json.j2
Normal file
11
playbooks/templates/appwrite_attribute_template.json.j2
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"key": "{{ item[1].key }}",
|
||||||
|
"required": {{ item[1].required }},
|
||||||
|
{% if item[1].default is defined and item[1].default and item[1].default != "null" %}"default": "{{ item[1].default }}",{% endif %}
|
||||||
|
{% if item[1].array is defined %}"array": {{ item[1].array }}, {% endif %}
|
||||||
|
{% if item[1].elements is defined %}"elements": [{% for e in item[1].elements %}"{{ e }}"{%- if not loop.last %},{% endif %}{% endfor %}],{% endif %}
|
||||||
|
{% if item[1].min is defined %}"min": {{ item[1].min | int }},{% endif %}
|
||||||
|
{% if item[1].max is defined %}"max": {{ item[1].max | int }},{% endif %}
|
||||||
|
{% if item[1].size is defined %}"size": {{ item[1].size | int }},{% endif %}
|
||||||
|
{% if item[1].encrypt is defined %}"encrypt": {{ item[1].encrypt }}{% endif%}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user