Class: HostedChef::ConfigValidator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hosted-chef/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_client, options) ⇒ ConfigValidator

Returns a new instance of ConfigValidator.



39
40
41
# File 'lib/hosted-chef/cli.rb', line 39

def initialize(api_client, options)
  @api_client, @options = api_client, options
end

Instance Method Details

#validate!Object



43
44
45
46
47
48
# File 'lib/hosted-chef/cli.rb', line 43

def validate!
  puts "Validating your account information..."
  validate_username
  validate_password
  validate_orgname
end

#validate_orgnameObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/hosted-chef/cli.rb', line 68

def validate_orgname
  page = RestClient.get("https://www.opscode.com/account/organizations/#{orgname}/plan", :cookies => @api_client.)
  # TODO: use actual HTTP response codes.
  puts "* Organization name '#{orgname}' is correct"
rescue RestClient::ResourceNotFound
  STDERR.puts "The organization '#{orgname}' does not exist or you dont "\
    "have permission to access it. Check your spelling, or visit "\
    "https://manage.opscode.com/organizations to create your organization"
  exit 1
end

#validate_passwordObject



58
59
60
61
62
63
64
65
66
# File 'lib/hosted-chef/cli.rb', line 58

def validate_password
  @api_client.
  puts "* Password is correct"
rescue InvalidPassword
  STDERR.puts "Could not login with the password you gave. Check your "\
    "typing, or visit http://community.opscode.com/password_reset_requests/new"\
    " to reset your password."
  exit 1
end

#validate_usernameObject



50
51
52
53
54
55
56
# File 'lib/hosted-chef/cli.rb', line 50

def validate_username
  RestClient.head("http://community.opscode.com/users/#{username}")
  puts "* Username '#{username}' is valid."
rescue RestClient::ResourceNotFound
  STDERR.puts "The user '#{username}' does not exist. Check your spelling, or visit http://www.opscode.com/hosted-chef/ to sign up."
  exit 1
end