mirror of
				https://github.com/fog/fog.git
				synced 2022-11-09 13:51:43 -05:00 
			
		
		
		
	break out credential files for easier access
This commit is contained in:
		
							parent
							
								
									4e7f7c7ad1
								
							
						
					
					
						commit
						99e8b9a32a
					
				
					 3 changed files with 46 additions and 40 deletions
				
			
		
							
								
								
									
										1
									
								
								bin/fog
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								bin/fog
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -4,6 +4,7 @@ require File.join(lib_dir, 'fog')
 | 
			
		|||
require 'irb'
 | 
			
		||||
require 'yaml'
 | 
			
		||||
 | 
			
		||||
require File.join(lib_dir, 'fog', 'credentials')
 | 
			
		||||
require File.join(lib_dir, 'fog', 'bin')
 | 
			
		||||
 | 
			
		||||
Fog.credential = (ARGV.first && :"#{ARGV.first}") || :default
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,46 +1,6 @@
 | 
			
		|||
module Fog
 | 
			
		||||
  class << self
 | 
			
		||||
 | 
			
		||||
    def credential=(new_credential)
 | 
			
		||||
      @credential = new_credential
 | 
			
		||||
      @credentials = nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def credential
 | 
			
		||||
      @credential || :default
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def credentials
 | 
			
		||||
      @credentials ||= begin
 | 
			
		||||
        path = File.expand_path('~/.fog')
 | 
			
		||||
        credentials = if File.exists?(path)
 | 
			
		||||
          File.open(path) do |file|
 | 
			
		||||
            YAML.load(file.read)
 | 
			
		||||
          end
 | 
			
		||||
        else
 | 
			
		||||
          nil
 | 
			
		||||
        end
 | 
			
		||||
        unless credentials && credentials[credential]
 | 
			
		||||
          print("\n  To run as '#{credential}', add the following to ~/.fog\n")
 | 
			
		||||
          yml = <<-YML
 | 
			
		||||
 | 
			
		||||
:#{credential}:
 | 
			
		||||
  :aws_access_key_id:     INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :aws_secret_access_key: INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :rackspace_api_key:     INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :rackspace_username:    INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :slicehost_password:    INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :terremark_username:    INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :terremark_password:    INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
 | 
			
		||||
YML
 | 
			
		||||
          print(yml)
 | 
			
		||||
          raise(ArgumentError.new("Missing Credentials"))
 | 
			
		||||
        end
 | 
			
		||||
        credentials[credential]
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def services
 | 
			
		||||
      services = []
 | 
			
		||||
      [::AWS, ::Rackspace, ::Slicehost, ::Terremark].each do |service|
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										45
									
								
								lib/fog/credentials.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								lib/fog/credentials.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,45 @@
 | 
			
		|||
module Fog
 | 
			
		||||
  class << self
 | 
			
		||||
 | 
			
		||||
    def credential=(new_credential)
 | 
			
		||||
      @credential = new_credential
 | 
			
		||||
      @credentials = nil
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def credential
 | 
			
		||||
      @credential || :default
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def credentials
 | 
			
		||||
      @credentials ||= begin
 | 
			
		||||
        path = File.expand_path('~/.fog')
 | 
			
		||||
        credentials = if File.exists?(path)
 | 
			
		||||
          File.open(path) do |file|
 | 
			
		||||
            YAML.load(file.read)
 | 
			
		||||
          end
 | 
			
		||||
        else
 | 
			
		||||
          nil
 | 
			
		||||
        end
 | 
			
		||||
        unless credentials && credentials[credential]
 | 
			
		||||
          print("\n  To run as '#{credential}', add the following to ~/.fog\n")
 | 
			
		||||
          yml = <<-YML
 | 
			
		||||
 | 
			
		||||
:#{credential}:
 | 
			
		||||
  :aws_access_key_id:     INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :aws_secret_access_key: INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :rackspace_api_key:     INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :rackspace_username:    INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :slicehost_password:    INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :terremark_username:    INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
  :terremark_password:    INTENTIONALLY_LEFT_BLANK
 | 
			
		||||
 | 
			
		||||
YML
 | 
			
		||||
          print(yml)
 | 
			
		||||
          raise(ArgumentError.new("Missing Credentials"))
 | 
			
		||||
        end
 | 
			
		||||
        credentials[credential]
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue