borg-hive 0.0.2

Automated backups using Borg Backup
// borg-hive - Zero-configuration wrapper for borg
// Copyright (C) 2017  Lorenzo Villani
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

use keyring;

use errors::*;

const KEYRING_SERVICE: &'static str = "borg-hive";
const KEYRING_USERNAME: &'static str = "borg-hive";

pub fn set_password(password: &str) -> Result<()> {
    keyring::Keyring::new(KEYRING_SERVICE, KEYRING_USERNAME)
        .set_password(password)
        .chain_err(|| "cannot store password in the keyring")
}

pub fn get_password() -> Result<String> {
    keyring::Keyring::new(KEYRING_SERVICE, KEYRING_USERNAME)
        .get_password()
        .chain_err(|| "cannot retrieve password from the keyring")
}