netrc: w/ dnixd, don't update netrc, require it to be right path
This commit is contained in:
parent
d9d748267f
commit
08c8cf0275
|
@ -1,5 +1,5 @@
|
||||||
use crate::env::Environment;
|
use crate::env::Environment;
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{self, Error, Result};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use attic::cache::CacheName;
|
use attic::cache::CacheName;
|
||||||
use attic::nix_store::{NixStore, StorePath};
|
use attic::nix_store::{NixStore, StorePath};
|
||||||
|
@ -9,6 +9,7 @@ use attic_client::{
|
||||||
config::ServerConfig,
|
config::ServerConfig,
|
||||||
push::{PushConfig, Pusher},
|
push::{PushConfig, Pusher},
|
||||||
};
|
};
|
||||||
|
|
||||||
use reqwest::header::HeaderValue;
|
use reqwest::header::HeaderValue;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -35,7 +36,16 @@ pub async fn init_cache(
|
||||||
flakehub_cache_server: &Url,
|
flakehub_cache_server: &Url,
|
||||||
flakehub_flake_name: Option<String>,
|
flakehub_flake_name: Option<String>,
|
||||||
store: Arc<NixStore>,
|
store: Arc<NixStore>,
|
||||||
|
using_dnixd: bool,
|
||||||
) -> Result<State> {
|
) -> Result<State> {
|
||||||
|
if using_dnixd {
|
||||||
|
let dnixd_state_dir: &Path = Path::new(&crate::DETERMINATE_STATE_DIR);
|
||||||
|
let expected_netrc_path = dnixd_state_dir.join("netrc");
|
||||||
|
if flakehub_api_server_netrc != expected_netrc_path {
|
||||||
|
let err = format!("flakehub-api-server-netrc was ({}), expected ({}) since determinate-nixd is available", flakehub_api_server_netrc.display(), expected_netrc_path.display());
|
||||||
|
return Err(error::Error::Config(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
// Parse netrc to get the credentials for api.flakehub.com.
|
// Parse netrc to get the credentials for api.flakehub.com.
|
||||||
let netrc = {
|
let netrc = {
|
||||||
let mut netrc_file = File::open(flakehub_api_server_netrc).await.map_err(|e| {
|
let mut netrc_file = File::open(flakehub_api_server_netrc).await.map_err(|e| {
|
||||||
|
@ -89,41 +99,43 @@ pub async fn init_cache(
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Append an entry for the FlakeHub cache server to netrc.
|
if !using_dnixd {
|
||||||
if !netrc
|
// Append an entry for the FlakeHub cache server to netrc.
|
||||||
.machines
|
if !netrc
|
||||||
.iter()
|
.machines
|
||||||
.any(|machine| machine.name.as_ref() == Some(&flakehub_cache_server_hostname))
|
.iter()
|
||||||
{
|
.any(|machine| machine.name.as_ref() == Some(&flakehub_cache_server_hostname))
|
||||||
let mut netrc_file = tokio::fs::OpenOptions::new()
|
{
|
||||||
.create(false)
|
let mut netrc_file = tokio::fs::OpenOptions::new()
|
||||||
.append(true)
|
.create(false)
|
||||||
.open(flakehub_api_server_netrc)
|
.append(true)
|
||||||
.await
|
.open(flakehub_api_server_netrc)
|
||||||
.map_err(|e| {
|
.await
|
||||||
Error::Internal(format!(
|
.map_err(|e| {
|
||||||
"Failed to open {} for appending: {}",
|
Error::Internal(format!(
|
||||||
flakehub_api_server_netrc.display(),
|
"Failed to open {} for appending: {}",
|
||||||
e
|
flakehub_api_server_netrc.display(),
|
||||||
))
|
e
|
||||||
})?;
|
))
|
||||||
|
})?;
|
||||||
|
|
||||||
netrc_file
|
netrc_file
|
||||||
.write_all(
|
.write_all(
|
||||||
format!(
|
format!(
|
||||||
"\nmachine {} login {} password {}\n\n",
|
"\nmachine {} login {} password {}\n\n",
|
||||||
flakehub_cache_server_hostname, flakehub_login, flakehub_password,
|
flakehub_cache_server_hostname, flakehub_login, flakehub_password,
|
||||||
|
)
|
||||||
|
.as_bytes(),
|
||||||
)
|
)
|
||||||
.as_bytes(),
|
.await
|
||||||
)
|
.map_err(|e| {
|
||||||
.await
|
Error::Internal(format!(
|
||||||
.map_err(|e| {
|
"Failed to write credentials to {}: {}",
|
||||||
Error::Internal(format!(
|
flakehub_api_server_netrc.display(),
|
||||||
"Failed to write credentials to {}: {}",
|
e
|
||||||
flakehub_api_server_netrc.display(),
|
))
|
||||||
e
|
})?;
|
||||||
))
|
}
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let server_config = ServerConfig {
|
let server_config = ServerConfig {
|
||||||
|
|
|
@ -233,6 +233,7 @@ async fn main_cli() -> Result<()> {
|
||||||
&flakehub_cache_server,
|
&flakehub_cache_server,
|
||||||
flakehub_flake_name,
|
flakehub_flake_name,
|
||||||
store.clone(),
|
store.clone(),
|
||||||
|
dnixd_available,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue