Module: ClusterFsck::Setup

Defined in:
lib/clusterfsck/setup.rb

Class Method Summary collapse

Class Method Details

.configObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/clusterfsck/setup.rb', line 3

def self.config
  puts <<-UI
    ClusterFsck stores your configuration(s) in an S3 bucket, which must have a globally unique name.
    The name will be stored in `#{ClusterFsck::CLUSTER_FSCK_PATHS[2]}` on this machine, and should be placed in
    `#{ClusterFsck::CLUSTER_FSCK_PATHS[1]}` on your production box (with a different ENV setting if desired).
    It may also be overridden on a per project basis by creating a `#{ClusterFsck::CLUSTER_FSCK_PATHS[0]}`
    file in the project root. The bucket and ENV setting are first checked from environment
    variables, so you can set the environment to override the files. The bucket is read from CLUSTER_FSCK_BUCKET
    and the environment (production, staging, development, etc) is read from CLUSTER_FSCK_ENV.
  UI
  unless ClusterFsck.config_hash['cluster_fsck_bucket']
    set_bucket_name
  end
  unless ClusterFsck::CredentialGrabber.find
    set_aws_keys
  end
  unless ClusterFsck::S3Methods.s3.buckets[ClusterFsck.config_hash['cluster_fsck_bucket']].exists?
    warn_create_bucket
  end
  ClusterFsck.config_hash['cluster_fsck_env'] ||= ClusterFsck.default_env
  File.open(File.expand_path(ClusterFsck::CLUSTER_FSCK_PATHS[2]), 'w') do |f|
    f.write(YAML.dump(ClusterFsck.config_hash))
  end
  ClusterFsck.config_hash['cluster_fsck_bucket']
end

.set_aws_keysObject



39
40
41
42
# File 'lib/clusterfsck/setup.rb', line 39

def self.set_aws_keys
  ClusterFsck.config_hash['aws_access_key_id'] = ask("Enter your AWS access key: ")
  ClusterFsck.config_hash['aws_secret_access_key'] = ask("Enter your AWS secret access key: ")
end

.set_bucket_nameObject



29
30
31
32
33
34
35
36
37
# File 'lib/clusterfsck/setup.rb', line 29

def self.set_bucket_name
  random_name = "clusterfsck_#{RandomWord.adjs.next}_#{RandomWord.nouns.next}"
  puts <<-UI
    Enter a name for your bucket, or press enter to accept the randomly generated name:
    #{random_name}
  UI
  input_name = ask("bucket name: ")
  ClusterFsck.config_hash['cluster_fsck_bucket'] = input_name.empty? ? random_name : input_name
end

.warn_create_bucketObject



44
45
46
47
48
49
# File 'lib/clusterfsck/setup.rb', line 44

def self.warn_create_bucket
  puts "WARNING: #{ClusterFsck.config_bucket} does not exist.  Type yes below to have it created for you, or return to abort."
  input = ask("Create bucket #{ClusterFsck.config_bucket}?: ")
  S3Methods.s3.buckets.create(ClusterFsck.config_bucket) unless input.empty?
  raise "No bucket present, not created" if input.empty?
end