Validate client configuration before running commands
This commit is contained in:
		
							parent
							
								
									0b296f9fcf
								
							
						
					
					
						commit
						febcadc3ba
					
				
					 1 changed files with 22 additions and 1 deletions
				
			
		
							
								
								
									
										23
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										23
									
								
								src/main.rs
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -3,7 +3,8 @@ include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
 | 
			
		|||
use crate::args::Commands;
 | 
			
		||||
use args::{PeopleCommands, ServerCommands};
 | 
			
		||||
use clap::Parser;
 | 
			
		||||
use color_eyre::eyre::Result;
 | 
			
		||||
use color_eyre::eyre::{Result, WrapErr};
 | 
			
		||||
use color_eyre::Section;
 | 
			
		||||
use commands::missing_date_of_birth::missing_date_of_birth;
 | 
			
		||||
use commands::server_version::server_version;
 | 
			
		||||
use commands::sync_date_of_birth::sync_date_of_birth;
 | 
			
		||||
| 
						 | 
				
			
			@ -46,6 +47,8 @@ async fn main() -> Result<()> {
 | 
			
		|||
 | 
			
		||||
    let client = get_client(&conf.server_url, &conf.api_key)?;
 | 
			
		||||
 | 
			
		||||
    validate_client_connection(&client).await?;
 | 
			
		||||
 | 
			
		||||
    match &args.command {
 | 
			
		||||
        Commands::People { people_command } => match people_command {
 | 
			
		||||
            PeopleCommands::MissingDateOfBirths {} => missing_date_of_birth(&client).await,
 | 
			
		||||
| 
						 | 
				
			
			@ -79,3 +82,21 @@ fn get_client(url: &str, api_key: &str) -> Result<Client> {
 | 
			
		|||
            .unwrap(),
 | 
			
		||||
    ))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async fn validate_client_connection(client: &Client) -> Result<()> {
 | 
			
		||||
    client
 | 
			
		||||
        .validate_access_token()
 | 
			
		||||
        .await
 | 
			
		||||
        .wrap_err_with(|| "Unable to connect to Immich")
 | 
			
		||||
        .with_suggestion(|| "The API key might be invalid")
 | 
			
		||||
        .with_suggestion(|| "There server URL might be invalid, it should likely end in /api")
 | 
			
		||||
        .with_note(|| format!("The provided server URL was {}", client.baseurl()))
 | 
			
		||||
        .with_note(|| {
 | 
			
		||||
            format!(
 | 
			
		||||
                "The API version for this client is {}, make sure the server version is compatible",
 | 
			
		||||
                client.api_version()
 | 
			
		||||
            )
 | 
			
		||||
        })?;
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue