Skip to content

Commit fd8ee0f

Browse files
committed
Added self-signed option
1 parent cf4e94f commit fd8ee0f

File tree

25 files changed

+170
-145
lines changed

25 files changed

+170
-145
lines changed

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Appwrite Command Line SDK
22

3-
![License](https://img.shields.io/github/license/appwrite/sdk-for-cli.svg?v=1)
4-
![Version](https://img.shields.io/badge/api%20version-0.7.0-blue.svg?v=1)
3+
![License](https://img.shields.io/github/license/appwrite/sdk-for-cli.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-0.7.0-blue.svg?style=flat-square)
5+
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite_io?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite_io)
6+
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
57

6-
**This SDK is compatible with Appwrite server version 0.7.0. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).**
8+
**This SDK is compatible with Appwrite server version 0.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).**
79

810
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way.
911
Use the Command Line SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools.
@@ -35,21 +37,23 @@ $ appwrite init
3537

3638
The CLI requires an endpoint, project ID, API key and a locale to be able to communicate with the Appwrite backend server. There are two ways to achieve this
3739

38-
### 1. Environment file
39-
```sh
40-
$ appwrite --env-file path/to/your/environment/file init
41-
```
42-
The .env file must have the following keys
40+
### 1. Pass in the project settings along with `appwrite init`
41+
4342
```sh
44-
endpoint=http://192.168.1.6/v1
45-
X-Appwrite-Project=5ff450422d42f
46-
X-Appwrite-Key=0773c7...a2672a
47-
X-Appwrite-Locale=en-US
43+
$ appwrite init --endpoint="YOUR ENDPOINT" --project="YOUR PROJECT ID" --key="YOUR API KEY" --locale="YOUR LOCALE"
4844
```
4945

46+
If any of the required values are missing, a prompt will show up, asking for those missing values.
47+
5048
### 2. Using the prompt
5149

52-
Invoking `appwrite init` without an env file triggers an interactive prompt where you can manually enter the details. These values are saved locally so that you dont have to re-enter them everytime.
50+
Invoking `appwrite init` without any params triggers an interactive prompt where you can manually enter the details. These values are saved locally so that you dont have to re-enter them everytime.
51+
52+
### Note
53+
By default, requests to domains with self signed SSL certificates (or no certificates) are disabled. If you trust the domain, you can bypass the certificate validation by using
54+
```sh
55+
$ appwrite client setSelfSigned --value=true
56+
```
5357

5458
## Usage
5559

app/Appwrite/Services/avatars.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
->param('width', 100 , new Mock(), 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
5050
->param('height', 100 , new Mock(), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
5151
->param('quality', 100 , new Mock(), 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
52-
->action(function ( $code, $width, $height, $quality ) use ($parser) {
52+
->action(function ( $code, $width, $height, $quality ) use ($parser) {
5353
$client = new Client();
5454
$path = str_replace(['{code}'], [$code], '/avatars/browsers/{code}');
5555
$params = [];
@@ -69,7 +69,7 @@
6969
->param('width', 100 , new Mock(), 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
7070
->param('height', 100 , new Mock(), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
7171
->param('quality', 100 , new Mock(), 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
72-
->action(function ( $code, $width, $height, $quality ) use ($parser) {
72+
->action(function ( $code, $width, $height, $quality ) use ($parser) {
7373
$client = new Client();
7474
$path = str_replace(['{code}'], [$code], '/avatars/credit-cards/{code}');
7575
$params = [];
@@ -87,7 +87,7 @@
8787
->label('description', "Use this endpoint to fetch the favorite icon (AKA favicon) of any remote website URL.
8888
\n\n")
8989
->param('url', '' , new Mock(), 'Website URL which you want to fetch the favicon from.', false)
90-
->action(function ( $url ) use ($parser) {
90+
->action(function ( $url ) use ($parser) {
9191
$client = new Client();
9292
$path = str_replace([], [], '/avatars/favicon');
9393
$params = [];
@@ -105,7 +105,7 @@
105105
->param('width', 100 , new Mock(), 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
106106
->param('height', 100 , new Mock(), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
107107
->param('quality', 100 , new Mock(), 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
108-
->action(function ( $code, $width, $height, $quality ) use ($parser) {
108+
->action(function ( $code, $width, $height, $quality ) use ($parser) {
109109
$client = new Client();
110110
$path = str_replace(['{code}'], [$code], '/avatars/flags/{code}');
111111
$params = [];
@@ -124,7 +124,7 @@
124124
->param('url', '' , new Mock(), 'Image URL which you want to crop.', false)
125125
->param('width', 400 , new Mock(), 'Resize preview image width, Pass an integer between 0 to 2000.', true)
126126
->param('height', 400 , new Mock(), 'Resize preview image height, Pass an integer between 0 to 2000.', true)
127-
->action(function ( $url, $width, $height ) use ($parser) {
127+
->action(function ( $url, $width, $height ) use ($parser) {
128128
$client = new Client();
129129
$path = str_replace([], [], '/avatars/image');
130130
$params = [];
@@ -147,7 +147,7 @@
147147
->param('height', 500 , new Mock(), 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
148148
->param('color', '' , new Mock(), 'Changes text color. By default a random color will be picked and stay will persistent to the given name.', true)
149149
->param('background', '' , new Mock(), 'Changes background color. By default a random color will be picked and stay will persistent to the given name.', true)
150-
->action(function ( $name, $width, $height, $color, $background ) use ($parser) {
150+
->action(function ( $name, $width, $height, $color, $background ) use ($parser) {
151151
$client = new Client();
152152
$path = str_replace([], [], '/avatars/initials');
153153
$params = [];
@@ -169,7 +169,7 @@
169169
->param('size', 400 , new Mock(), 'QR code size. Pass an integer between 0 to 1000. Defaults to 400.', true)
170170
->param('margin', 1 , new Mock(), 'Margin from edge. Pass an integer between 0 to 10. Defaults to 1.', true)
171171
->param('download', false , new Mock(), 'Return resulting image with 'Content-Disposition: attachment ' headers for the browser to start downloading it. Pass 0 for no header, or 1 for otherwise. Default value is set to 0.', true)
172-
->action(function ( $text, $size, $margin, $download ) use ($parser) {
172+
->action(function ( $text, $size, $margin, $download ) use ($parser) {
173173
$client = new Client();
174174
$path = str_replace([], [], '/avatars/qr');
175175
$params = [];

app/Appwrite/Services/client.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,21 @@
4646
->task('setEndpoint')
4747
->param('endpoint', '', new Mock(), 'Your Appwrite endpoint', false)
4848
->action(function($endpoint) use ($client) {
49-
$client->setPreference('endpoint', $endpoint);
50-
$result = $client->savePreferences();
49+
$result = $client->setPreference('endpoint', $endpoint)
50+
->savePreferences();
51+
if ($result === false) {
52+
Console::error('❌ Could not save preferences.');
53+
} else {
54+
Console::success('✅ Preferences saved successfully');
55+
}
56+
});
57+
58+
$cli
59+
->task('setSelfSigned')
60+
->param('value', '', new Mock(), 'A boolean representing whether you are using a self signed certificate', false)
61+
->action(function($value) use ($client) {
62+
$result = $client->setPreference('selfSigned', $value)
63+
->savePreferences();
5164
if ($result === false) {
5265
Console::error('❌ Could not save preferences.');
5366
} else {
@@ -60,8 +73,8 @@
6073
->task('setProject')
6174
->param('project', '', new Mock(), 'Your project ID', false)
6275
->action(function($project) use ($client) {
63-
$client->setPreference('X-Appwrite-Project', $project);
64-
$result = $client->savePreferences();
76+
$result = $client->setPreference('X-Appwrite-Project', $project)
77+
->savePreferences();
6578
if ($result === false) {
6679
Console::error('❌ Could not save preferences.');
6780
} else {
@@ -73,8 +86,8 @@
7386
->task('setKey')
7487
->param('key', '', new Mock(), 'Your secret API key', false)
7588
->action(function($key) use ($client) {
76-
$client->setPreference('X-Appwrite-Key', $key);
77-
$result = $client->savePreferences();
89+
$result = $client->setPreference('X-Appwrite-Key', $key)
90+
->savePreferences();
7891
if ($result === false) {
7992
Console::error('❌ Could not save preferences.');
8093
} else {
@@ -86,8 +99,8 @@
8699
->task('setLocale')
87100
->param('locale', '', new Mock(), '', false)
88101
->action(function($locale) use ($client) {
89-
$client->setPreference('X-Appwrite-Locale', $locale);
90-
$result = $client->savePreferences();
102+
$result = $client->setPreference('X-Appwrite-Locale', $locale)
103+
->savePreferences();
91104
if ($result === false) {
92105
Console::error('❌ Could not save preferences.');
93106
} else {
@@ -99,7 +112,7 @@
99112
$cli
100113
->task('version')
101114
->action(function() {
102-
Console::log('CLI Version : 0.6.0');
115+
Console::log('CLI Version : 0.7.0');
103116
Console::log('Server Version : 0.7.0');
104117
});
105118

@@ -121,7 +134,9 @@
121134
"setEndpoint" => "Set your server endpoint.",
122135
"setProject" => "Set the project you want to connect to.",
123136
"setKey" => "Set the API key for the project.",
124-
"setLocale" => "Set your preferred locale (eg: en-US)."
137+
"setLocale" => "Set your preferred locale (eg: en-US).",
138+
"setSelfSigned" => "Set whether you are using a self signed certificate",
139+
"version" => "Get the current cli version"
125140
];
126141
$parser->formatArray($commands);
127142
Console::log("\nRun 'appwrite client COMMAND --help' for more information on a command.");

app/Appwrite/Services/database.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
->param('limit', 25 , new Mock(), 'Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request.', true)
5050
->param('offset', 0 , new Mock(), 'Results offset. The default value is 0. Use this param to manage pagination.', true)
5151
->param('orderType', 'ASC' , new Mock(), 'Order result by ASC or DESC order.', true)
52-
->action(function ( $search, $limit, $offset, $orderType ) use ($parser) {
52+
->action(function ( $search, $limit, $offset, $orderType ) use ($parser) {
5353
$client = new Client();
5454
$path = str_replace([], [], '/database/collections');
5555
$params = [];
@@ -71,7 +71,7 @@
7171
->param('read', '' , new Mock(), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', false)
7272
->param('write', '' , new Mock(), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', false)
7373
->param('rules', '' , new Mock(), 'Array of [rule objects](/docs/rules). Each rule define a collection field name, data type and validation.', false)
74-
->action(function ( $name, $read, $write, $rules ) use ($parser) {
74+
->action(function ( $name, $read, $write, $rules ) use ($parser) {
7575
$client = new Client();
7676
$path = str_replace([], [], '/database/collections');
7777
$params = [];
@@ -90,7 +90,7 @@
9090
->task('getCollection')
9191
->label('description', "Get a collection by its unique ID. This endpoint response returns a JSON object with the collection metadata.\n\n")
9292
->param('collectionId', '' , new Mock(), 'Collection unique ID.', false)
93-
->action(function ( $collectionId ) use ($parser) {
93+
->action(function ( $collectionId ) use ($parser) {
9494
$client = new Client();
9595
$path = str_replace(['{collectionId}'], [$collectionId], '/database/collections/{collectionId}');
9696
$params = [];
@@ -109,7 +109,7 @@
109109
->param('read', '' , new Mock(), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions(/docs/permissions) and get a full list of available permissions.', false)
110110
->param('write', '' , new Mock(), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', false)
111111
->param('rules', [] , new Mock(), 'Array of [rule objects](/docs/rules). Each rule define a collection field name, data type and validation.', true)
112-
->action(function ( $collectionId, $name, $read, $write, $rules ) use ($parser) {
112+
->action(function ( $collectionId, $name, $read, $write, $rules ) use ($parser) {
113113
$client = new Client();
114114
$path = str_replace(['{collectionId}'], [$collectionId], '/database/collections/{collectionId}');
115115
$params = [];
@@ -128,7 +128,7 @@
128128
->task('deleteCollection')
129129
->label('description', "Delete a collection by its unique ID. Only users with write permissions have access to delete this resource.\n\n")
130130
->param('collectionId', '' , new Mock(), 'Collection unique ID.', false)
131-
->action(function ( $collectionId ) use ($parser) {
131+
->action(function ( $collectionId ) use ($parser) {
132132
$client = new Client();
133133
$path = str_replace(['{collectionId}'], [$collectionId], '/database/collections/{collectionId}');
134134
$params = [];
@@ -150,7 +150,7 @@
150150
->param('orderType', 'ASC' , new Mock(), 'Order direction. Possible values are DESC for descending order, or ASC for ascending order.', true)
151151
->param('orderCast', 'string' , new Mock(), 'Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.', true)
152152
->param('search', '' , new Mock(), 'Search query. Enter any free text search. The database will try to find a match against all document attributes and children. Max length: 256 chars.', true)
153-
->action(function ( $collectionId, $filters, $limit, $offset, $orderField, $orderType, $orderCast, $search ) use ($parser) {
153+
->action(function ( $collectionId, $filters, $limit, $offset, $orderField, $orderType, $orderCast, $search ) use ($parser) {
154154
$client = new Client();
155155
$path = str_replace(['{collectionId}'], [$collectionId], '/database/collections/{collectionId}/documents');
156156
$params = [];
@@ -178,7 +178,7 @@
178178
->param('parentDocument', '' , new Mock(), 'Parent document unique ID. Use when you want your new document to be a child of a parent document.', true)
179179
->param('parentProperty', '' , new Mock(), 'Parent document property name. Use when you want your new document to be a child of a parent document.', true)
180180
->param('parentPropertyType', 'assign' , new Mock(), 'Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document.', true)
181-
->action(function ( $collectionId, $data, $read, $write, $parentDocument, $parentProperty, $parentPropertyType ) use ($parser) {
181+
->action(function ( $collectionId, $data, $read, $write, $parentDocument, $parentProperty, $parentPropertyType ) use ($parser) {
182182
$client = new Client();
183183
$path = str_replace(['{collectionId}'], [$collectionId], '/database/collections/{collectionId}/documents');
184184
$params = [];
@@ -200,7 +200,7 @@
200200
->label('description', "Get a document by its unique ID. This endpoint response returns a JSON object with the document data.\n\n")
201201
->param('collectionId', '' , new Mock(), 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).', false)
202202
->param('documentId', '' , new Mock(), 'Document unique ID.', false)
203-
->action(function ( $collectionId, $documentId ) use ($parser) {
203+
->action(function ( $collectionId, $documentId ) use ($parser) {
204204
$client = new Client();
205205
$path = str_replace(['{collectionId}', '{documentId}'], [$collectionId, $documentId], '/database/collections/{collectionId}/documents/{documentId}');
206206
$params = [];
@@ -219,7 +219,7 @@
219219
->param('data', '' , new Mock(), 'Document data as JSON object.', false)
220220
->param('read', '' , new Mock(), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', false)
221221
->param('write', '' , new Mock(), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', false)
222-
->action(function ( $collectionId, $documentId, $data, $read, $write ) use ($parser) {
222+
->action(function ( $collectionId, $documentId, $data, $read, $write ) use ($parser) {
223223
$client = new Client();
224224
$path = str_replace(['{collectionId}', '{documentId}'], [$collectionId, $documentId], '/database/collections/{collectionId}/documents/{documentId}');
225225
$params = [];
@@ -238,7 +238,7 @@
238238
->label('description', "Delete a document by its unique ID. This endpoint deletes only the parent documents, its attributes and relations to other documents. Child documents **will not** be deleted.\n\n")
239239
->param('collectionId', '' , new Mock(), 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).', false)
240240
->param('documentId', '' , new Mock(), 'Document unique ID.', false)
241-
->action(function ( $collectionId, $documentId ) use ($parser) {
241+
->action(function ( $collectionId, $documentId ) use ($parser) {
242242
$client = new Client();
243243
$path = str_replace(['{collectionId}', '{documentId}'], [$collectionId, $documentId], '/database/collections/{collectionId}/documents/{documentId}');
244244
$params = [];

0 commit comments

Comments
 (0)