@@ -16,17 +16,18 @@ import (
1616)
1717
1818type Database struct {
19- ID string `json:"dbId" mapstructure:"dbId"`
20- Name string
21- Regions []string
22- PrimaryRegion string
23- Hostname string
24- Version string
25- Group string
26- Sleeping bool
27- Schema string
28- IsSchema bool `json:"is_schema" mapstructure:"is_schema"`
29- Parent * Database `json:"parent,omitempty"`
19+ ID string `json:"dbId" mapstructure:"dbId"`
20+ Name string
21+ Regions []string
22+ PrimaryRegion string
23+ Hostname string
24+ Version string
25+ Group string
26+ Sleeping bool
27+ Schema string
28+ IsSchema bool `json:"is_schema" mapstructure:"is_schema"`
29+ Parent * Database `json:"parent,omitempty"`
30+ EncryptionCipher string `json:"encryption_cipher,omitempty"`
3031}
3132
3233type DatabasesClient client
@@ -133,19 +134,25 @@ type DBSeed struct {
133134 Filepath string `json:"-"`
134135}
135136
137+ type RemoteEncryption struct {
138+ EncryptionKey string `json:"encryption_key"`
139+ EncryptionCipher string `json:"encryption_cipher"`
140+ }
141+
136142type CreateDatabaseBody struct {
137- Name string `json:"name"`
138- Location string `json:"location"`
139- Image string `json:"image,omitempty"`
140- Extensions string `json:"extensions,omitempty"`
141- Group string `json:"group,omitempty"`
142- Seed * DBSeed `json:"seed,omitempty"`
143- Schema string `json:"schema,omitempty"`
144- IsSchema bool `json:"is_schema,omitempty"`
145- SizeLimit string `json:"size_limit,omitempty"`
146- }
147-
148- func (d * DatabasesClient ) Create (name , location , image , extensions , group string , schema string , isSchema bool , seed * DBSeed , sizeLimit string , spinner * prompt.SpinnerT ) (* CreateDatabaseResponse , error ) {
143+ Name string `json:"name"`
144+ Location string `json:"location"`
145+ Image string `json:"image,omitempty"`
146+ Extensions string `json:"extensions,omitempty"`
147+ Group string `json:"group,omitempty"`
148+ Seed * DBSeed `json:"seed,omitempty"`
149+ Schema string `json:"schema,omitempty"`
150+ IsSchema bool `json:"is_schema,omitempty"`
151+ SizeLimit string `json:"size_limit,omitempty"`
152+ RemoteEncryption * RemoteEncryption `json:"remote_encryption,omitempty"`
153+ }
154+
155+ func (d * DatabasesClient ) Create (name , location , image , extensions , group string , schema string , isSchema bool , seed * DBSeed , sizeLimit , remoteEncryptionCipher , remoteEncryptionKey string , spinner * prompt.SpinnerT ) (* CreateDatabaseResponse , error ) {
149156 isTursoServerUpload := seed != nil && seed .Type == "database_upload" && seed .Filepath != ""
150157 var uploadFilepath string
151158 var params CreateDatabaseBody
@@ -163,7 +170,14 @@ func (d *DatabasesClient) Create(name, location, image, extensions, group string
163170 Seed : seed ,
164171 }
165172 } else {
166- params = CreateDatabaseBody {name , location , image , extensions , group , seed , schema , isSchema , sizeLimit }
173+ params = CreateDatabaseBody {name , location , image , extensions , group , seed , schema , isSchema , sizeLimit , nil }
174+ }
175+
176+ if remoteEncryptionKey != "" {
177+ params .RemoteEncryption = & RemoteEncryption {
178+ EncryptionKey : remoteEncryptionKey ,
179+ EncryptionCipher : remoteEncryptionCipher ,
180+ }
167181 }
168182
169183 body , err := marshal (params )
@@ -196,7 +210,7 @@ func (d *DatabasesClient) Create(name, location, image, extensions, group string
196210 }
197211
198212 if isTursoServerUpload {
199- if _ , err = d .UploadDatabaseAWS (data , group , uploadFilepath , spinner ); err != nil {
213+ if _ , err = d .UploadDatabaseAWS (data , group , uploadFilepath , remoteEncryptionCipher , remoteEncryptionKey , spinner ); err != nil {
200214 // Clean up the database if the upload fails
201215 if deleteErr := d .Delete (data .Database .Name ); deleteErr != nil {
202216 fmt .Printf ("%v" , deleteErr )
@@ -217,7 +231,7 @@ func (d *DatabasesClient) Create(name, location, image, extensions, group string
217231// This call happens in DatabasesClient.Create() above, after which it calls this function.
218232// 2. This function creates a DB token for the newly-created DB, and then calls turso-server to upload the database file.
219233// turso-server will perform validations on the file and 'activate' the db if everything is ok.
220- func (d * DatabasesClient ) UploadDatabaseAWS (resp * CreateDatabaseResponse , group string , uploadFilepath string , spinner * prompt.SpinnerT ) (* CreateDatabaseResponse , error ) {
234+ func (d * DatabasesClient ) UploadDatabaseAWS (resp * CreateDatabaseResponse , group , uploadFilepath , remoteEncryptionCipher , remoteEncryptionKey string , spinner * prompt.SpinnerT ) (* CreateDatabaseResponse , error ) {
221235 // Create a short-lived DB token for the newly created database to facilitate the upload
222236 token , err := d .Token (resp .Database .Name , "1h" , false , nil , nil )
223237 if err != nil {
@@ -235,7 +249,7 @@ func (d *DatabasesClient) UploadDatabaseAWS(resp *CreateDatabaseResponse, group
235249
236250 // Upload the database file
237251 spinner .Text (fmt .Sprintf ("Uploading database %s in group %s, this may take a while..." , internal .Emph (resp .Database .Name ), internal .Emph (group )))
238- err = tursoServerClient .UploadFile (uploadFilepath , func (progressPct int , uploadedBytes int64 , totalBytes int64 , elapsedTime time.Duration , done bool ) {
252+ err = tursoServerClient .UploadFile (uploadFilepath , remoteEncryptionCipher , remoteEncryptionKey , func (progressPct int , uploadedBytes int64 , totalBytes int64 , elapsedTime time.Duration , done bool ) {
239253 totalSeconds := int (elapsedTime .Seconds ())
240254 minutes := totalSeconds / 60
241255 seconds := totalSeconds % 60
@@ -267,7 +281,7 @@ func (d *DatabasesClient) UploadDatabaseAWS(resp *CreateDatabaseResponse, group
267281 return resp , nil
268282}
269283
270- func (d * DatabasesClient ) Export (dbName , dbUrl , outputFile string , withMetadata bool , overwrite bool ) error {
284+ func (d * DatabasesClient ) Export (dbName , dbUrl , outputFile string , withMetadata bool , overwrite bool , remoteEncryptionKey string ) error {
271285 if ! overwrite {
272286 if _ , err := os .Stat (outputFile ); err == nil {
273287 return fmt .Errorf ("file %s already exists, use `--overwrite` flag to overwrite it" , outputFile )
@@ -285,7 +299,7 @@ func (d *DatabasesClient) Export(dbName, dbUrl, outputFile string, withMetadata
285299 if err != nil {
286300 return fmt .Errorf ("could not create Turso server client: %w" , err )
287301 }
288- return tursoServerClient .Export (outputFile , withMetadata )
302+ return tursoServerClient .Export (outputFile , withMetadata , remoteEncryptionKey )
289303}
290304
291305func (d * DatabasesClient ) Seed (name string , dbFile * os.File ) error {
0 commit comments