pub async fn create_if_not_exists(conn: ConnectionPool) -> Result<(), PrivateKeyError> {
        tokio::task::spawn_blocking(move || {
            info_span!("create_if_not_exists").in_scope(move || {
                let conn = conn.get()?;

                // diesel-tracing prints the UNIQUE constraint error even though we ignore it
                info!(
                    "Generating an ed25519 key if it doesn't already exist, UNIQUE constraint \
                        errors here can be safely ignored."
                );

                let ed25519_key = key::KeyPair::generate_ed25519()
                    .ok_or(PrivateKeyError::KeyGenerate("ed25519"))?;

                let res = insert_into(server_private_keys::table)
                    .values((
                        server_private_keys::ssh_key_type.eq("ed25519"),
                        server_private_keys::ssh_private_key.eq(private_key_bytes(&ed25519_key)?),
                    ))
                    .execute(&conn);

                match res {
                    Ok(_)
                    | Err(DieselError::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) => {
                        Ok(())
                    }
                    Err(e) => Err(e.into()),
                }
            })
        })
        .await?
    }
/// Creates all the required keys for the server (currently just ed25519), ignoring any
/// UNIQUE constraint errors.
Creates all the required keys for the server (currently just ed25519), ignoring any
UNIQUE constraint errors.
Creates all the required keys for the server ( currently just ed25519 ) ignoring any UNIQUE constraint errors .
pub async fn create_if_not_exists(conn: ConnectionPool) -> Result<(), PrivateKeyError> {
        tokio::task::spawn_blocking(move || {
            info_span!("create_if_not_exists").in_scope(move || {
                let conn = conn.get()?;
                // diesel-tracing prints the UNIQUE constraint error even though we ignore it
                info!(
                    "Generating an ed25519 key if it doesn't already exist, UNIQUE constraint \
                        errors here can be safely ignored."
                );
                let ed25519_key = key::KeyPair::generate_ed25519()
                    .ok_or(PrivateKeyError::KeyGenerate("ed25519"))?;
                let res = insert_into(server_private_keys::table)
                    .values((
                        server_private_keys::ssh_key_type.eq("ed25519"),
                        server_private_keys::ssh_private_key.eq(private_key_bytes(&ed25519_key)?),
                    ))
                    .execute(&conn);
                match res {
                    Ok(_)
                    | Err(DieselError::DatabaseError(DatabaseErrorKind::UniqueViolation, _)) => {
                        Ok(())
                    }
                    Err(e) => Err(e.into()),
                }
            })
        })
        .await?
    }
pub async fn create_if_not_exists ( conn : ConnectionPool ) -> Result < ( ) , PrivateKeyError > { tokio :: task :: spawn_blocking ( move | | { info_span ! ( " " ) . in_scope ( move | | { let conn = conn . get ( ) ? ; // diesel-tracing prints the UNIQUE constraint error even though we ignore it info ! ( " \
 " ) ; let ed25519_key = key :: KeyPair :: generate_ed25519 ( ) . ok_or ( PrivateKeyError :: KeyGenerate ( " " ) ) ? ; let res = insert_into ( server_private_keys :: table ) . values ( ( server_private_keys :: ssh_key_type . eq ( " " ) , server_private_keys :: ssh_private_key . eq ( private_key_bytes ( & ed25519_key ) ? ) , ) ) . execute ( & conn ) ; match res { Ok ( _ ) | Err ( DieselError :: DatabaseError ( DatabaseErrorKind :: UniqueViolation , _ ) ) => { Ok ( ( ) ) } Err ( e ) => Err ( e . into ( ) ) , } } ) } ) . await ? }
Creates all the required keys for the server (currently just ed25519), ignoring any
UNIQUE constraint errors.
Creates all the required keys for the server ( currently just ed25519 ) ignoring any UNIQUE constraint errors .
conn
ConnectionPool
conn
ConnectionPool