jenfig 0.1.0.pre → 0.1.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: becb9f3de2778f57d7257ee86f3a97919755d548b60b6901c69ce6e0826e0c84
4
- data.tar.gz: 6e3555a2e1c4c0289cdde02e9786b85ddfc4f923a07a9ce2603a797890d59560
3
+ metadata.gz: 2904cd8f21213cc70a522af31461cadb559fa770f27d2f95057806be87237ce0
4
+ data.tar.gz: df3d1ee50f19251064ce38468670fbbebd1180e28a2f9b16283cec28d95e4e46
5
5
  SHA512:
6
- metadata.gz: 7e614a64433dff9b23bf6bbd98185719508b8f66371ba1cda383a208185ee93b793e8c8127f2cc17808207d9615318f77edee6514ab21b84ea98f11bcef8bce1
7
- data.tar.gz: 0dc17ea74a968efda30ced9624752c98bf3bf1eaa9b9eef874d454df11ab407fb8a47e271dd3f3857d7308b0005fb739874e8d0fd4a2905eb01fce0cfdef59ed
6
+ metadata.gz: 2908dc0581f76aacdc2933d29cb2c53e878a3f6fc70b1f473bb6da76cf801931fdca0a0c8cc14518069411b0c0e4d27980668dae5198a2a38fd3120d1774f7f7
7
+ data.tar.gz: 9f903086a2bd90722752fd90294c611babff123d05908e5b73eab1c793707c1afd5d6f1e5beeb31fab77bdb000809b17e6a1dc422f50c49cd2ba4d88b760393b
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jenfig (0.1.1.pre)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.11.3)
10
+ rake (10.5.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 2.0)
17
+ jenfig!
18
+ minitest (~> 5.0)
19
+ rake (~> 10.0)
20
+
21
+ BUNDLED WITH
22
+ 2.0.2
data/bin/jenfig ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'jenfig'
5
+ require 'jenfig/cli'
6
+ case ARGV[0]
7
+ when 'crumb'
8
+ Jenfig::CLI::Crumb.init(ARGV).exec
9
+ when 'download'
10
+ when 'upload'
11
+ Jenfig::CLI::Upload.new.exec
12
+ else
13
+ puts "Usage: jenfig [command] [options]
14
+ commands: crumb, push, download, init"
15
+ end
data/jenfig.gemspec CHANGED
@@ -24,8 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
25
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
26
  end
27
- spec.bindir = "exe"
28
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.executables << 'jenfig'
29
28
  spec.require_paths = ["lib"]
30
29
 
31
30
  spec.add_development_dependency "bundler", "~> 2.0"
data/lib/jenfig.rb CHANGED
@@ -1,4 +1,8 @@
1
- require "jenfig/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'jenfig/version'
4
+ require 'jenfig/api'
5
+ require 'jenfig/config'
2
6
 
3
7
  module Jenfig
4
8
  class Error < StandardError; end
data/lib/jenfig/api.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jenfig
4
+ module API
5
+ end
6
+ end
7
+
8
+ require 'jenfig/api/crumb'
9
+ require 'jenfig/api/job'
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ class Jenfig::API::Crumb
8
+ def self.load(options)
9
+ uri = URI.parse(options[:url] + '/crumbIssuer/api/json')
10
+ http = Net::HTTP.new(uri.host, uri.port)
11
+ request = Net::HTTP::Get.new(uri.request_uri)
12
+ request.basic_auth(options[:user], options[:password])
13
+ response = http.request(request)
14
+ JSON.parse(response.body)['crumb']
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jenfig
4
+ module API
5
+ class Job
6
+ def self.exists?(job, options)
7
+ uri = URI.parse(options[:url] + "/job/#{job.name}/api/json")
8
+ http = Net::HTTP.new(uri.host, uri.port)
9
+ request = Net::HTTP::Get.new(uri.request_uri)
10
+ request.basic_auth(options[:user], options[:password])
11
+ request['Jenkins-Crumb'] = options[:crumb]
12
+ response = http.request(request)
13
+ response.is_a?(Net::HTTPOK)
14
+ end
15
+
16
+ def self.create_or_update(job, options)
17
+ if exists?(job, options)
18
+ update(job, options)
19
+ else
20
+ create(job, options)
21
+ end
22
+ end
23
+
24
+ def self.create(job, options)
25
+ uri = URI.parse(options[:url] + "/createItem?name=#{job.name}")
26
+ http = Net::HTTP.new(uri.host, uri.port)
27
+ request = Net::HTTP::Post.new(uri.request_uri)
28
+ request.basic_auth(options[:user], options[:password])
29
+ request['Jenkins-Crumb'] = options[:crumb]
30
+ request['Content-Type'] = 'text/xml'
31
+ request.body = File.open(File.join(options[:directory], job.relative_path)).read
32
+ puts request.body
33
+ response = http.request(request)
34
+ puts response
35
+ puts response.body
36
+ end
37
+
38
+ def self.update(job, options)
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/jenfig/cli.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jenfig::CLI
4
+ end
5
+ require 'jenfig/cli/upload'
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Jenfig::CLI::Crumb
4
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+ require 'jenfig/api'
5
+ require 'io/console'
6
+
7
+ class Jenfig::CLI::Upload
8
+ def initialize
9
+ @options = {}
10
+
11
+ option_parser = OptionParser.new do |opts|
12
+ opts.banner = 'Usage: example.rb [options]'
13
+
14
+ opts.on('-uUSER', '--user=USER', 'Jenkins Username') do |user|
15
+ @options[:user] = user
16
+ end
17
+ opts.on('-pPASSWORD', '--password=PASSWORD', 'Jenkins Username or API Key') do |password|
18
+ @options[:password] = password
19
+ end
20
+ opts.on('-jURL', '--url=URL', 'Jenkins URL including http/https and Port e.g. http://localhost:8080') do |url|
21
+ @options[:url] = url
22
+ end
23
+ opts.on('-fCONFIGURATION', '--file=fCONFIGURATION', 'jenfig Configuration') do |file|
24
+ @options[:file] = file
25
+ end
26
+ opts.on('-dDIRECTORY', '--directory=DIRECTORY', 'jenfig root directory') do |directory|
27
+ @options[:directory] = directory
28
+ end
29
+ end
30
+ option_parser.parse!
31
+ @options[:directory] = File.join(File.dirname(File.realpath(@options[:file]))) unless @options[:directory]
32
+ if @options[:password].nil?
33
+ unless ENV['JENKINS_API_KEY'].nil?
34
+ @options[:passworde] = ENV['JENKINS_API_KEY']
35
+ else
36
+ @options[:password] = IO::console.getpass "Enter Password or API Key: "
37
+ end
38
+ end
39
+ end
40
+
41
+ def exec
42
+ config = Jenfig::Config::Config.load(@options[:file])
43
+ @options[:crumb] = Jenfig::API::Crumb.load(user: @options[:user], password: @options[:password], url: @options[:url])
44
+ puts @options[:crumb]
45
+ puts config.to_yaml
46
+ config.jobs.each { |job| Jenfig::API::Job.create_or_update(job, @options) }
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jenfig
4
+ module Config
5
+ end
6
+ end
7
+ require 'jenfig/config/config'
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'jenfig/config/job'
5
+
6
+
7
+ module Jenfig
8
+ module Config
9
+ class Config
10
+ attr_reader :jobs
11
+
12
+ def self.load(file_path)
13
+ yaml = YAML.load_file(file_path)
14
+ puts yaml['jobs']
15
+ puts yaml['jobs'].first['name']
16
+ jobs = []
17
+ yaml['jobs'].each { |job| jobs << Jenfig::Config::Job.new(job['name'], job['relative_path']) }
18
+ new(jobs)
19
+ end
20
+
21
+ def initialize(jobs)
22
+ @jobs = jobs
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Jenfig::Config::Job
4
+ attr_reader :name, :relative_path
5
+
6
+ def initialize(name, relative_path)
7
+ @name = name
8
+ @relative_path = relative_path
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jenfig
2
- VERSION = "0.1.0.pre"
4
+ VERSION = '0.1.1.pre'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre
4
+ version: 0.1.1.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Erler
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-16 00:00:00.000000000 Z
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,20 +55,32 @@ dependencies:
55
55
  description: Simple CLI Gem for Jenkins provisioning
56
56
  email:
57
57
  - daviderler1995@gmail.com
58
- executables: []
58
+ executables:
59
+ - jenfig
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
62
63
  - ".gitignore"
63
64
  - ".travis.yml"
64
65
  - Gemfile
66
+ - Gemfile.lock
65
67
  - LICENSE.txt
66
68
  - README.md
67
69
  - Rakefile
68
70
  - bin/console
71
+ - bin/jenfig
69
72
  - bin/setup
70
73
  - jenfig.gemspec
71
74
  - lib/jenfig.rb
75
+ - lib/jenfig/api.rb
76
+ - lib/jenfig/api/crumb.rb
77
+ - lib/jenfig/api/job.rb
78
+ - lib/jenfig/cli.rb
79
+ - lib/jenfig/cli/crumb.rb
80
+ - lib/jenfig/cli/upload.rb
81
+ - lib/jenfig/config.rb
82
+ - lib/jenfig/config/config.rb
83
+ - lib/jenfig/config/job.rb
72
84
  - lib/jenfig/version.rb
73
85
  homepage: https://github.com/Dave1995/jenfig
74
86
  licenses: