by
0 7
0
4
2,751
0
Top 1% !
Popular
Famous
Specified
Popularity: 5746th place
This snippet is Public
No tags for this snippet yet.
LanguageCoffeeScript
LicenseMIT_X11
SourceGitHub

AngularJS service to work with Chef DataBags via Knife CLI.

AngularJS service to work with Chef DataBags via Knife CLI.: 
DataBagService.coffee
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/137144/AngularJS-service-to-work-with-Chef-Data?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
'use strict'; class DataBagService _exec = {} _tmp = {} _fs = {} _knife = '' constructor: (@$q) -> console.log 'DataBagService: constructor called' _exec = require('child_process').exec _tmp = require('tmp') _fs = require('fs') this.setKnifePath() setKnifePath:(path) -> _knife = path || 'RBENV_VERSION=2.0.0-p353 knife' getDataBagItem: (client, data_bag, item) -> return {} unless client && data_bag && item deferred = @$q.defer() _exec "#{_knife} data bag show #{data_bag} #{item} "+ authString(client), (err, stdout, stderr) -> if err deferred.resolve(false) throw err else deferred.resolve(JSON.parse(stdout)) return deferred.promise putDataBagItem: (client, data_bag, item) -> return {} unless client && data_bag && item deferred = @$q.defer() _tmp.file {postfix: '.json'}, (err, path, fd) -> if (err) _tmp.setGracefulCleanup() deferred.resolve(false) throw err _fs.writeFileSync path, JSON.stringify(item) _exec "#{_knife} data bag from file #{data_bag} #{path} "+ authString(client), (err, stdout, stderr) -> if err deferred.resolve(false) throw err else deferred.resolve(true) return deferred.promise userName = (user) -> user.replace('-validator','') authString = (client) -> "-u #{client.user} "+ "-k #{process.env.HOME}/.chef/#{client.user}.pem "+ "--server-url #{client.base} "+ "--secret-file #{secretFile(client.user)} "+ "-F json" secretFile = (name) -> "#{process.env.HOME}/.chef/#{userName(name)}_secret " angular.module('app.services') .service 'DataBagService', [ '$q', DataBagService ]
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus