salt_client 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6666e78e797611e3450818cb9c790242d00c478f
4
+ data.tar.gz: dbdae3d242c75e3915ee29bdd5efc692abe6559d
5
+ SHA512:
6
+ metadata.gz: b962cacfd72d8179f5931a7ab3531cbe03d7e69eb59c39a1ac50fa668efcf23dc31ad007b711b48ed9cdb086dd573f36f067ae3460c00aa25ac009647a3e6d88
7
+ data.tar.gz: ecbc9b6d7dbf47f7d01648040f1cde59769cbfb2565864d45c18a5efb396f4fa328ced081303768b0447bc43db4c2fb7a82b941a19aa066377e378e44e0b829c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in salt_client.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # SaltClient
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/salt_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'salt_client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install salt_client
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec salt_client` to use the code located in this directory, ignoring other installed copies of this gem.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/salt_client/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "salt_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/salt_client ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "salt_client"
4
+ require "optparse"
5
+
6
+ options = {}
7
+
8
+ parser = OptionParser.new do |opts|
9
+ opts.banner = "Usage: salt.rb [options] command target args"
10
+
11
+ opts.on('-s', '--server SERVER', String, 'The saltstack master to call') do |server|
12
+ options[:server] = server
13
+ end
14
+
15
+ opts.on('-u', '--user USERNAME', String, 'The user to authenticate with') do |user|
16
+ options[:user] = user
17
+ end
18
+
19
+ opts.on('-p', '--pass PASSWORD', String, 'The password to authenticate with') do |pass|
20
+ options[:pass] = pass
21
+ end
22
+ end
23
+
24
+ begin
25
+ parser.parse!
26
+ mandatory = [:server, :user, :pass]
27
+ missing = mandatory.select{ |param| options[param].nil? }
28
+ unless missing.empty?
29
+ puts "Missing options: #{missing.join(', ')}"
30
+ puts ""
31
+ puts parser
32
+ exit
33
+ end
34
+
35
+ if ARGV.length < 3
36
+ puts parser
37
+ exit
38
+ end
39
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
40
+ puts $!.to_s
41
+ puts ""
42
+ puts parser
43
+ exit
44
+ end
45
+
46
+ c = SaltClient::Client.new options[:server], options[:user], options[:pass]
47
+ response = c.call ARGV[0], ARGV[1], ARGV[2]
48
+
49
+ response.each do |server, reply|
50
+ puts "#{server} => #{reply}"
51
+ end
@@ -0,0 +1,42 @@
1
+ require 'unirest'
2
+
3
+ module SaltClient
4
+ class Client
5
+ def initialize(server, user, pass)
6
+ @server = server
7
+ response = Unirest.post "#{server}/login",
8
+ headers: {"Accept": "application/json"},
9
+ parameters: {
10
+ :username => user,
11
+ :password => pass,
12
+ :eauth => "pam"
13
+ }
14
+
15
+ if response.code != 200
16
+ abort("Could not login to the salt master")
17
+ end
18
+
19
+ @token = response.body.fetch("return")[0]["token"]
20
+ end
21
+
22
+ def call(target, function, arguments)
23
+ response = Unirest.post @server,
24
+ headers: {
25
+ "Accept": "application/json",
26
+ "X-Auth-Token": @token
27
+ },
28
+ parameters: {
29
+ :client => "local",
30
+ :tgt => target,
31
+ :fun => function,
32
+ :arg => arguments
33
+ }
34
+
35
+ if response.code != 200
36
+ abort("Something went wrong when calling your method")
37
+ end
38
+
39
+ response.body["return"][0]
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module SaltClient
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'salt_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "salt_client"
8
+ spec.version = SaltClient::VERSION
9
+ spec.authors = ["Alex Bularca"]
10
+ spec.email = ["abu@everymatrix.com"]
11
+
12
+ spec.summary = %q{Simple CLI client for interacting with the SaltStack remote API}
13
+ spec.description = %q{A CLI client for the SaltStack API that allows you to remotely execute code on your SaltStack minions}
14
+ spec.homepage = "https://github.com/arcade/salt_client"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "unirest", "~> 1.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.8"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: salt_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Bularca
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unirest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A CLI client for the SaltStack API that allows you to remotely execute
56
+ code on your SaltStack minions
57
+ email:
58
+ - abu@everymatrix.com
59
+ executables:
60
+ - salt_client
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - exe/salt_client
72
+ - lib/salt_client.rb
73
+ - lib/salt_client/version.rb
74
+ - salt_client.gemspec
75
+ homepage: https://github.com/arcade/salt_client
76
+ licenses: []
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.5
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Simple CLI client for interacting with the SaltStack remote API
98
+ test_files: []