@@ -16,14 +16,14 @@ use super::{
16
16
error:: * ,
17
17
project:: { find_project_file, ProjectDir } ,
18
18
BuildContext , BuildContextImpl , ClientSecurity , CloudCerts , Config , DatabaseBranch ,
19
- FromParamStr , InstanceName , Logging , Param , ParamSource , TcpKeepalive , TlsSecurity ,
19
+ FromParamStr , InstanceName , Logging , Param , ParamSource , TcpKeepalive , TlsSecurity , UnixPath ,
20
20
DEFAULT_CONNECT_TIMEOUT , DEFAULT_PORT , DEFAULT_WAIT ,
21
21
} ;
22
22
use crate :: {
23
23
env:: SystemEnvVars ,
24
24
file:: SystemFileAccess ,
25
25
gel:: { context_trace, Authentication } ,
26
- host:: { Host , HostTarget , HostType } ,
26
+ host:: { Host , HostType } ,
27
27
user:: SystemUserProfile ,
28
28
EnvVar , FileAccess , UserProfile ,
29
29
} ;
@@ -233,12 +233,7 @@ define_params!(
233
233
/// The port.
234
234
port: u16 ,
235
235
/// The unix socket path.
236
- ///
237
- /// If set, the client will connect to the database via a Unix socket.
238
- /// If a port is also set, this must refer to a directory in the filesystem
239
- /// containing a Gel admin socket. If no port is set, the client will
240
- /// connect to the database via a Unix socket on the exact given path.
241
- unix_path: PathBuf ,
236
+ unix_path: UnixPath ,
242
237
/// The database name. Used for EdgeDB < 5. For Gel or EdgeDB >= 5, use
243
238
/// [`Builder::branch`].
244
239
database: String ,
@@ -788,42 +783,38 @@ impl Params {
788
783
789
784
let instance = instance?;
790
785
if let Some ( instance) = & instance {
791
- // Special case: if the unix path is set we ignore the instance
792
- // credentials.
793
- if explicit. unix_path . is_none ( ) {
794
- match & instance {
795
- InstanceName :: Local ( local) => {
796
- let instance = parse_instance ( local, context) ?;
797
- context_trace ! ( context, "Instance: {:?}" , instance) ;
798
- explicit. merge ( instance) ;
799
- }
800
- InstanceName :: Cloud { .. } => {
801
- let profile = explicit
802
- . cloud_profile
803
- . get ( context) ?
804
- . unwrap_or ( "default" . to_string ( ) ) ;
805
- let cloud = parse_cloud ( & profile, context) ?;
806
- context_trace ! ( context, "Cloud: {:?}" , cloud) ;
807
- explicit. merge ( cloud) ;
808
-
809
- if let Some ( secret_key) = explicit. secret_key . get ( context) ? {
810
- match instance. cloud_address ( & secret_key) {
811
- Ok ( Some ( address) ) => {
812
- explicit. host = Param :: Unparsed ( address) ;
813
- }
814
- Ok ( None ) => {
815
- unreachable ! ( ) ;
816
- }
817
- Err ( e) => {
818
- // Special case: we ignore the secret key error until the final phase
819
- if phase == BuildPhase :: Project {
820
- return Err ( e) ;
821
- }
786
+ match & instance {
787
+ InstanceName :: Local ( local) => {
788
+ let instance = parse_instance ( local, context) ?;
789
+ context_trace ! ( context, "Instance: {:?}" , instance) ;
790
+ explicit. merge ( instance) ;
791
+ }
792
+ InstanceName :: Cloud { .. } => {
793
+ let profile = explicit
794
+ . cloud_profile
795
+ . get ( context) ?
796
+ . unwrap_or ( "default" . to_string ( ) ) ;
797
+ let cloud = parse_cloud ( & profile, context) ?;
798
+ context_trace ! ( context, "Cloud: {:?}" , cloud) ;
799
+ explicit. merge ( cloud) ;
800
+
801
+ if let Some ( secret_key) = explicit. secret_key . get ( context) ? {
802
+ match instance. cloud_address ( & secret_key) {
803
+ Ok ( Some ( address) ) => {
804
+ explicit. host = Param :: Unparsed ( address) ;
805
+ }
806
+ Ok ( None ) => {
807
+ unreachable ! ( ) ;
808
+ }
809
+ Err ( e) => {
810
+ // Special case: we ignore the secret key error until the final phase
811
+ if phase == BuildPhase :: Project {
812
+ return Err ( e) ;
822
813
}
823
814
}
824
- } else {
825
- return Err ( ParseError :: SecretKeyNotFound ) ;
826
815
}
816
+ } else {
817
+ return Err ( ParseError :: SecretKeyNotFound ) ;
827
818
}
828
819
}
829
820
}
@@ -859,27 +850,15 @@ impl Params {
859
850
}
860
851
861
852
let host = if let Some ( unix_path) = computed. unix_path {
862
- match port {
863
- Some ( port) => Host :: new (
864
- HostType :: from_unix_path ( unix_path) ,
865
- port,
866
- HostTarget :: GelAdmin ,
867
- ) ,
868
- None => Host :: new (
869
- HostType :: from_unix_path ( unix_path) ,
870
- DEFAULT_PORT ,
871
- HostTarget :: Raw ,
872
- ) ,
873
- }
853
+ let path = unix_path
854
+ . path_with_port ( port. unwrap_or ( DEFAULT_PORT ) )
855
+ . into_owned ( ) ;
856
+ Host :: new ( HostType :: from_unix_path ( path) , DEFAULT_PORT )
874
857
} else {
875
858
let host = match ( computed. host , port) {
876
- ( Some ( host) , Some ( port) ) => Host :: new ( host, port, HostTarget :: Gel ) ,
877
- ( Some ( host) , None ) => Host :: new ( host, DEFAULT_PORT , HostTarget :: Gel ) ,
878
- ( None , Some ( port) ) => Host :: new (
879
- HostType :: try_from_str ( "localhost" ) . unwrap ( ) ,
880
- port,
881
- HostTarget :: Gel ,
882
- ) ,
859
+ ( Some ( host) , Some ( port) ) => Host :: new ( host, port) ,
860
+ ( Some ( host) , None ) => Host :: new ( host, DEFAULT_PORT ) ,
861
+ ( None , Some ( port) ) => Host :: new ( HostType :: try_from_str ( "localhost" ) . unwrap ( ) , port) ,
883
862
( None , None ) => {
884
863
return Ok ( None ) ;
885
864
}
@@ -1524,26 +1503,32 @@ mod tests {
1524
1503
eprintln ! ( "{:?}" , params) ;
1525
1504
1526
1505
let params = Builder :: default ( )
1527
- . unix_path ( Path :: new ( "/" ) )
1506
+ . unix_path ( UnixPath :: with_port_suffix ( PathBuf :: from (
1507
+ "/.s.EDGEDB.admin." ,
1508
+ ) ) )
1528
1509
. port ( 1234 )
1529
1510
. without_system ( )
1530
1511
. build ( )
1531
1512
. expect ( "Unix path and port is OK" ) ;
1532
1513
assert_eq ! ( params. host. to_string( ) , "/.s.EDGEDB.admin.1234" ) ;
1533
1514
eprintln ! ( "{:?}" , params) ;
1534
1515
1535
- // This is allowed, but instance credentials are ignored in this case
1536
- // and just transferred to the output Config.
1516
+ // Pull the port from the credentials.
1537
1517
let params = Builder :: default ( )
1538
- . instance ( InstanceName :: Local ( "instancedoesnotexist " . to_string ( ) ) )
1539
- . unix_path ( Path :: new ( "/" ) )
1518
+ . instance ( InstanceName :: Local ( "instancename " . to_string ( ) ) )
1519
+ . unix_path ( UnixPath :: with_port_suffix ( PathBuf :: from ( "/tmp/port." ) ) )
1540
1520
. without_system ( )
1521
+ . with_fs_impl ( HashMap :: from_iter ( [ (
1522
+ PathBuf :: from ( "/home/edgedb/.config/edgedb/credentials/instancename.json" ) ,
1523
+ r#"{ "user": "user", "port": 12345 }"# . to_string ( ) ,
1524
+ ) ] ) )
1525
+ . with_user_impl ( "edgedb" )
1541
1526
. build ( )
1542
1527
. expect ( "Unix path and instance is OK" ) ;
1543
- assert_eq ! ( params. host. to_string( ) , "/" ) ;
1528
+ assert_eq ! ( params. host. to_string( ) , "/tmp/port.12345 " ) ;
1544
1529
assert_eq ! (
1545
1530
params. instance_name,
1546
- Some ( InstanceName :: Local ( "instancedoesnotexist " . to_string( ) ) )
1531
+ Some ( InstanceName :: Local ( "instancename " . to_string( ) ) )
1547
1532
) ;
1548
1533
eprintln ! ( "{:?}" , params) ;
1549
1534
}
0 commit comments