Skip to content

Commit

Permalink
New feature: read vault_pass_file from ansible.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
sydro committed Jun 27, 2017
1 parent c7b8de6 commit 7c6e34b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ npm-debug.log
node_modules
lib/bin/test*
NOTES
ansible.cfg
Binary file modified images/screenshot-settings.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion lib/ansible-vault-utils.js
Expand Up @@ -5,6 +5,8 @@ import AnsibleVaultView from './ansible-vault-view';
import { CompositeDisposable } from 'atom';
import { File } from 'atom';
import fs from 'fs';
import ini from 'ini';


export default class AnsibleVaultUtils {

Expand Down Expand Up @@ -70,6 +72,7 @@ export default class AnsibleVaultUtils {
execChild(cmd, (error, stdout, stderr) => {
if (error) {
exitCode = 1;
output = stderr;
} else {
exitCode = 0;
output = vault_filepath + ": OK"
Expand All @@ -88,7 +91,23 @@ export default class AnsibleVaultUtils {
let unlinkF = false;

if (atom.config.get("ansible-vault.vault_password_file_flag")) {
password_file = atom.config.get("ansible-vault.vault_password_file_path")
if (atom.config.get("ansible-vault.vault_password_file_forcing")) {
password_file = atom.config.get("ansible-vault.vault_password_file_path");
} else {
project_path = atom.project.relativizePath(vault_filepath)[0]
const listFiles = require('fs-plus').listSync;
ansible_cfg_file = listFiles(project_path, ['cfg']).map(function(el) { if (el.includes('ansible.cfg')) return el ; } );
if (ansible_cfg_file.length <= 0) {
password_file = atom.config.get("ansible-vault.vault_password_file_path");
} else {
let ansible_cfg = ini.parse(fs.readFileSync(ansible_cfg_file[0],'utf-8'));
if(ansible_cfg.defaults.vault_password_file) {
password_file = ansible_cfg.defaults.vault_password_file;
} else {
password_file = atom.config.get("ansible-vault.vault_password_file_path");
}
}
}
}

if (password_file == "") {
Expand Down
6 changes: 5 additions & 1 deletion lib/config-schema.coffee
Expand Up @@ -4,7 +4,11 @@ module.exports =
type: 'string'
default: '/usr/local/bin/ansible-vault'
vault_password_file_flag:
title: 'Use a global vault password file'
title: 'Use vault password file defined in ansible.cfg project'
type: 'boolean'
default: false
vault_password_file_forcing:
title: 'Force specific vault password file'
type: 'boolean'
default: false
vault_password_file_path:
Expand Down

0 comments on commit 7c6e34b

Please sign in to comment.