@@ -42,16 +42,27 @@ pub static DB_SYNC_PORT_FINALIZER: &str = "dbsyncports.demeter.run";
42
42
pub struct DbSyncPortSpec {
43
43
pub network : String ,
44
44
pub throughput_tier : Option < String > ,
45
+ pub username : Option < String > ,
46
+ pub password : Option < String > ,
45
47
}
46
48
#[ derive( Deserialize , Serialize , Clone , Debug , JsonSchema ) ]
47
49
pub struct DbSyncPortStatus {
48
50
pub username : String ,
49
51
pub password : String ,
50
52
}
51
53
impl DbSyncPortStatus {
52
- pub async fn try_new ( name : & str , ns : & str ) -> Result < Self , Error > {
53
- let username = gen_username_hash ( & format ! ( "{name}.{ns}" ) ) . await ?;
54
- let password = Alphanumeric . sample_string ( & mut rand:: thread_rng ( ) , 16 ) ;
54
+ pub async fn try_new ( port : & DbSyncPort ) -> Result < Self , Error > {
55
+ let ns = port. namespace ( ) . unwrap ( ) ;
56
+ let name = port. name_any ( ) ;
57
+
58
+ let username = match & port. spec . username {
59
+ Some ( username) => username. clone ( ) ,
60
+ None => gen_username_hash ( & format ! ( "{name}.{ns}" ) ) . await ?,
61
+ } ;
62
+ let password = match & port. spec . password {
63
+ Some ( password) => password. clone ( ) ,
64
+ None => Alphanumeric . sample_string ( & mut rand:: thread_rng ( ) , 16 ) ,
65
+ } ;
55
66
56
67
Ok ( Self { username, password } )
57
68
}
@@ -71,7 +82,7 @@ impl DbSyncPort {
71
82
let status = self
72
83
. status
73
84
. clone ( )
74
- . unwrap_or ( DbSyncPortStatus :: try_new ( & name , & ns ) . await ?) ;
85
+ . unwrap_or ( DbSyncPortStatus :: try_new ( self ) . await ?) ;
75
86
76
87
if self . status . is_none ( ) {
77
88
let payload = json ! ( { "status" : status } ) ;
0 commit comments