refactor(journaldriver): Use anyhow instead of failure
Apparently failure is not hip anymore, and crate updates are forcing the use of anyhow now. Whatever. The functionality basically stays the same, maybe error messages will look a little bit different now. Change-Id: I173d644688785339c16161ddeec47a534123710f Reviewed-on: https://cl.tvl.fyi/c/depot/+/5307 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org> Autosubmit: tazjin <tazjin@tvl.su>
This commit is contained in:
		
							parent
							
								
									4ce2b49cd9
								
							
						
					
					
						commit
						ede837b687
					
				
					 3 changed files with 240 additions and 312 deletions
				
			
		
							
								
								
									
										540
									
								
								ops/journaldriver/Cargo.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										540
									
								
								ops/journaldriver/Cargo.lock
									
										
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
					@ -5,9 +5,9 @@ authors = ["Vincent Ambo <mail@tazj.in>"]
 | 
				
			||||||
license = "GPL-3.0-or-later"
 | 
					license = "GPL-3.0-or-later"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
 | 
					anyhow = "1.0"
 | 
				
			||||||
chrono = { version = "0.4", features = [ "serde" ]}
 | 
					chrono = { version = "0.4", features = [ "serde" ]}
 | 
				
			||||||
env_logger = "0.5"
 | 
					env_logger = "0.5"
 | 
				
			||||||
failure = "0.1"
 | 
					 | 
				
			||||||
lazy_static = "1.0"
 | 
					lazy_static = "1.0"
 | 
				
			||||||
log = "0.4"
 | 
					log = "0.4"
 | 
				
			||||||
medallion = "2.2"
 | 
					medallion = "2.2"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@
 | 
				
			||||||
//! `LOG_NAME` environment variables.
 | 
					//! `LOG_NAME` environment variables.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[macro_use]
 | 
					#[macro_use]
 | 
				
			||||||
extern crate failure;
 | 
					extern crate anyhow;
 | 
				
			||||||
#[macro_use]
 | 
					#[macro_use]
 | 
				
			||||||
extern crate log;
 | 
					extern crate log;
 | 
				
			||||||
#[macro_use]
 | 
					#[macro_use]
 | 
				
			||||||
| 
						 | 
					@ -49,9 +49,9 @@ extern crate serde;
 | 
				
			||||||
extern crate systemd;
 | 
					extern crate systemd;
 | 
				
			||||||
extern crate ureq;
 | 
					extern crate ureq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use anyhow::{Context, Result};
 | 
				
			||||||
use chrono::offset::LocalResult;
 | 
					use chrono::offset::LocalResult;
 | 
				
			||||||
use chrono::prelude::{DateTime, TimeZone, Utc};
 | 
					use chrono::prelude::{DateTime, TimeZone, Utc};
 | 
				
			||||||
use failure::ResultExt;
 | 
					 | 
				
			||||||
use serde_json::{from_str, Value};
 | 
					use serde_json::{from_str, Value};
 | 
				
			||||||
use std::fs::{self, rename, File};
 | 
					use std::fs::{self, rename, File};
 | 
				
			||||||
use std::io::{self, ErrorKind, Read, Write};
 | 
					use std::io::{self, ErrorKind, Read, Write};
 | 
				
			||||||
| 
						 | 
					@ -72,9 +72,6 @@ const METADATA_ZONE_URL: &str = "http://metadata.google.internal/computeMetadata
 | 
				
			||||||
const METADATA_PROJECT_URL: &str =
 | 
					const METADATA_PROJECT_URL: &str =
 | 
				
			||||||
    "http://metadata.google.internal/computeMetadata/v1/project/project-id";
 | 
					    "http://metadata.google.internal/computeMetadata/v1/project/project-id";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Convenience type alias for results using failure's `Error` type.
 | 
					 | 
				
			||||||
type Result<T> = std::result::Result<T, failure::Error>;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/// Representation of static service account credentials for GCP.
 | 
					/// Representation of static service account credentials for GCP.
 | 
				
			||||||
#[derive(Debug, Deserialize)]
 | 
					#[derive(Debug, Deserialize)]
 | 
				
			||||||
struct Credentials {
 | 
					struct Credentials {
 | 
				
			||||||
| 
						 | 
					@ -158,8 +155,7 @@ fn get_metadata(url: &str) -> Result<String> {
 | 
				
			||||||
/// Convenience helper for determining the project ID.
 | 
					/// Convenience helper for determining the project ID.
 | 
				
			||||||
fn get_project_id() -> String {
 | 
					fn get_project_id() -> String {
 | 
				
			||||||
    env::var("GOOGLE_CLOUD_PROJECT")
 | 
					    env::var("GOOGLE_CLOUD_PROJECT")
 | 
				
			||||||
        .map_err(Into::into)
 | 
					        .or_else(|_| get_metadata(METADATA_PROJECT_URL))
 | 
				
			||||||
        .or_else(|_: failure::Error| get_metadata(METADATA_PROJECT_URL))
 | 
					 | 
				
			||||||
        .expect("Could not determine project ID")
 | 
					        .expect("Could not determine project ID")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue