capistrano-hivequeen 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  ## If your rubyforge_project name is different, then edit it and comment out
7
7
  ## the sub! line in the Rakefile
8
8
  s.name = 'capistrano-hivequeen'
9
- s.version = '0.2.0'
10
- s.date = '2011-10-03'
9
+ s.version = '0.3.0'
10
+ s.date = '2011-10-04'
11
11
 
12
12
  ## Make sure your summary is short. The description may be as long
13
13
  ## as you like.
@@ -5,6 +5,7 @@ Capistrano::Configuration.instance(:must_exist).load do
5
5
  HiveQueen.endpoint = hivequeen_endpoint
6
6
  HiveQueen.project = application
7
7
  HiveQueen.logger = logger
8
+ HiveQueen.set_credentials!
8
9
 
9
10
  # Redefine stage tasks from multistage extension
10
11
  # Set the list of available stages
@@ -13,6 +14,7 @@ Capistrano::Configuration.instance(:must_exist).load do
13
14
  set :default_stage, :staging
14
15
 
15
16
  set :repository, HiveQueen.repository
17
+ set :scm, :git
16
18
 
17
19
  # Load capistrano multi-stage extension
18
20
  require 'fileutils' # required until https://github.com/capistrano/capistrano-ext/commit/930ca840a0b4adad0ec53546790b3f5ffe726538 is released
@@ -1,17 +1,18 @@
1
1
  # HTTP Client for Hive Queen environment configuration
2
- require 'open-uri'
3
2
  require 'json'
4
3
  require 'fileutils'
4
+ require 'excon'
5
+ require 'base64'
5
6
 
6
7
  # Special cases:
7
8
  # - environment not found
8
9
  # - environment not ready: fail
9
10
  class HiveQueen
10
11
  class << self
11
- attr_accessor :endpoint, :logger, :project
12
+ attr_accessor :endpoint, :logger, :project, :username, :password
12
13
 
13
14
  def project_data
14
- @project_data ||= fetch("/projects/#{project}")
15
+ @project_data ||= fetch("/projects/#{project}.json")
15
16
  end
16
17
 
17
18
  def environments
@@ -29,14 +30,43 @@ class HiveQueen
29
30
  def roles(env_id)
30
31
  env_id = env_id.to_sym
31
32
  @roles ||= {}
32
- @roles[env_id] ||= fetch("/environments/#{env_id}")
33
+ @roles[env_id] ||= fetch("/environments/#{env_id}.json")
34
+ end
35
+
36
+ # Try to load credentials, or read them from ~/.hivequeen
37
+ def set_credentials!
38
+ @username, @password = File.read(credential_path).chomp.split(':')
39
+ raise unless username && password
40
+ rescue Errno::ENOENT, RuntimeError
41
+ puts "Could not read HiveQueen credentials from #{credential_path}."
42
+ puts "#{credential_path} should contain your username and password seperated by a colon"
43
+ puts "Run this command with your credentials:"
44
+ puts " $ echo username:password > #{credential_path}"
45
+ exit 1
33
46
  end
34
47
 
35
48
  protected
49
+ def credential_path
50
+ File.join(ENV['HOME'], '.hivequeen')
51
+ end
52
+
53
+ def connection
54
+ @connection ||= Excon.new(endpoint)
55
+ end
56
+
57
+ def auth_header
58
+ value = Base64.encode64([username, password] * ':').chomp
59
+ { 'Authorization' => "Basic #{value}" }
60
+ end
61
+
36
62
  def fetch(path)
37
- url = endpoint + path + '.json'
63
+ url = "#{endpoint}#{path}"
38
64
  logger.trace "Fetching #{url}"
39
- JSON.parse(open(url).read)
65
+ response = connection.get(:path => path, :headers => auth_header)
66
+ unless (200..299).include?(response.status)
67
+ raise "Request to #{url} returned #{response.status} status"
68
+ end
69
+ JSON.parse(response.body)
40
70
  end
41
71
 
42
72
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-hivequeen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aaron Suggs
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-03 00:00:00 -04:00
18
+ date: 2011-10-04 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency