@@ -62,15 +62,12 @@ NEWSCHEMA('Infrastructures', function (schema) {
6262
6363 schema . action ( 'create' , {
6464 name : 'Create project' ,
65- input : '*name:String, *icon:Icon, *color:Color, *description:String, *admin_ip:String, *admin_login:String, *admin_pass:String ' ,
65+ input : '*name:String, *icon:Icon, *color:Color, *description:String' ,
6666 action : async function ( $ , model ) {
6767 // Input validation – early exit on first failure
6868 const validators = [
6969 { fn : REGEX_PROJECTS . name , field : 'name' } ,
70- { fn : REGEX_PROJECTS . description , field : 'description' } ,
71- { fn : REGEX_PROJECTS . admin_ip , field : 'admin_ip' } ,
72- { fn : REGEX_PROJECTS . admin_login , field : 'admin_login' } ,
73- { fn : REGEX_PROJECTS . admin_pass , field : 'admin_pass' }
70+ { fn : REGEX_PROJECTS . description , field : 'description' }
7471 ] ;
7572 for ( const v of validators ) {
7673 if ( v . optional && ( model [ v . field ] === '' || model [ v . field ] == null ) ) continue ;
@@ -83,7 +80,6 @@ NEWSCHEMA('Infrastructures', function (schema) {
8380 // Populate system fields
8481 model . id = UID ( ) ;
8582 model . uid = $ . user . id ;
86- model . admin_pass = model . admin_pass . sha256 ( process . env . AUTH_SECRET ) ;
8783 model . dtcreated = new Date ( ) ;
8884 model . isarchived = false ;
8985 model . tfstate = { version : 4 } ;
@@ -102,7 +98,7 @@ NEWSCHEMA('Infrastructures', function (schema) {
10298 . read ( 'nosql/infrastructures' )
10399 . where ( 'uid' , $ . user . id )
104100 . where ( 'id' , id )
105- . fields ( 'id,name,description,admin_login,admin_ip, icon,color' )
101+ . fields ( 'id,name,description,icon,color' )
106102 . error ( '@(Error)' )
107103 . promise ( $ ) ;
108104 $ . callback ( result ) ;
@@ -112,42 +108,21 @@ NEWSCHEMA('Infrastructures', function (schema) {
112108 schema . action ( 'update' , {
113109 name : 'Update project' ,
114110 params : '*id:UID' ,
115- input : '*name:String, *icon:Icon, *color:Color, *description:String, *admin_ip:String, *admin_login:String, admin_pass:String ' ,
111+ input : '*name:String, *icon:Icon, *color:Color, *description:String' ,
116112 action : async function ( $ , model ) {
117113 const { id } = $ . params ;
118114
119115 // Validate mutable fields
120116 const validators = [
121117 { fn : REGEX_PROJECTS . name , field : 'name' } ,
122118 { fn : REGEX_PROJECTS . description , field : 'description' } ,
123- { fn : REGEX_PROJECTS . admin_ip , field : 'admin_ip' } ,
124- { fn : REGEX_PROJECTS . admin_login , field : 'admin_login' }
125119 ] ;
126120 for ( const v of validators ) {
127121 if ( ! FUNC . regex ( v . fn , model [ v . field ] ) ) {
128122 $ . invalid ( `${ v . fn . comment } ` ) ;
129123 return ;
130124 }
131125 }
132-
133- // Password handling – only hash when a new password is supplied
134- if ( model . admin_pass ) {
135- if ( ! FUNC . regex ( REGEX_PROJECTS . admin_pass , model . admin_pass ) ) {
136- $ . invalid ( `${ REGEX_PROJECTS . admin_pass . comment } ` ) ;
137- return ;
138- }
139- model . admin_pass = model . admin_pass . sha256 ( process . env . AUTH_SECRET ) ;
140- } else {
141- // Preserve existing hash
142- const existing = await DATA
143- . read ( 'nosql/infrastructures' )
144- . where ( 'uid' , $ . user . id )
145- . where ( 'id' , id )
146- . fields ( 'admin_pass' )
147- . error ( '@(Error)' )
148- . promise ( $ ) ;
149- model . admin_pass = existing . admin_pass ;
150- }
151126
152127 model . dtupdated = new Date ( ) ;
153128
@@ -202,4 +177,35 @@ NEWSCHEMA('Infrastructures', function (schema) {
202177 $ . success ( ) ;
203178 }
204179 } ) ;
180+
181+ schema . action ( 'export' , {
182+ name : 'Export all infrastructures' ,
183+ params : '*ids:String' ,
184+ action : async function ( $ ) {
185+ const result = await DATA
186+ . list ( 'nosql/infrastructures' )
187+ . where ( 'uid' , $ . user . id )
188+ . in ( 'id' , $ . params . ids . split ( ',' ) )
189+ . error ( '@(Error)' )
190+ . promise ( $ ) ;
191+ $ . callback ( result . items ) ;
192+ }
193+ } ) ;
194+
195+ schema . action ( 'import' , {
196+ name : 'Import an infrastructure' ,
197+ params : '*id:UID' ,
198+ input : '*color:Color, *description:String, *dtcreated:String, *icon:Icon, isarchived:Boolean, *name:String, *tfstate:Json' ,
199+ action : async function ( $ , model ) {
200+ const { id } = $ . params ;
201+ model . tfstate = JSON . parse ( model . tfstate ) ;
202+
203+ DATA . modify ( 'nosql/infrastructures' , model , true ) . where ( 'id' , id ) . insert ( function ( doc ) {
204+ doc . uid = $ . user . id ;
205+ doc . id = id ;
206+ doc . dtupdated = NOW ;
207+ } ) ;
208+ $ . success ( ) ;
209+ }
210+ } ) ;
205211} ) ;
0 commit comments