Class: Conify::Command::Global

Inherits:
AbstractCommand show all
Defined in:
lib/conify/command/global.rb

Defined Under Namespace

Modules: CommandInfo

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args, #options

Instance Method Summary collapse

Methods inherited from AbstractCommand

#initialize

Methods included from Helpers

#allow_user_response, #ask_for_conflux_creds, #ask_for_password, #ask_for_password_on_windows, #camelize, #display, #echo_off, #echo_on, #error, #exclusive_deep_merge, #format_with_bang, #host, #host_url, #kensa_manifest_name, #kensa_manifest_path, #manifest_content, #manifest_filename, #manifest_path, #manually_added_methods, #open_url, #running_on_a_mac?, #running_on_windows?, #site_url, #to_table, #with_tty

Constructor Details

This class inherits a constructor from Conify::Command::AbstractCommand

Instance Method Details

#initObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/conify/command/global.rb', line 10

def init
  # Error out if conflux-manifest.json already exists
  if File.exists?(manifest_path)
    error "Manifest File #{manifest_filename} already exists."
  else
    begin
      # Create new conflux-manifest.json file from template
      File.open(manifest_path, 'w+') do |f|
        f.write(Conify::Manifest.template)
      end

      display([
        "Created new manifest template at #{manifest_filename}.",
        "Modify it to your service's specs and then run 'conify test'."
      ].join("\n"))
    rescue Exception => e
      File.delete(manifest_path) # Remove file if something screws up during file creation
      display "Error initializing conify manifest: #{e.message}"
    end
  end
end

#openObject



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/conify/command/global.rb', line 69

def open
  # First ensure manifest exists.
  if !File.exists?(manifest_path)
    error "No Conflux manifest exists yet.\nRun 'conflux init' to create a new manifest."
  end

  service_id = manifest_content['id'] || ''
  error 'Manifest must have an "id" field.' if service_id.empty?

  edit_service_url = "#{site_url}/services/#{service_id}/edit"
  display "Opening Conflux Service at: #{edit_service_url}"
  open_url(edit_service_url)
end

#pushObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/conify/command/global.rb', line 48

def push
  # First ensure manifest exists.
  if !File.exists?(manifest_path)
    error "No Conflux manifest exists yet.\nRun 'conflux init' to create a new manifest."
  end

  # Run Manifest Test to ensure file is valid.
  Conify::ManifestTest.new(manifest_content).call

  # Request Conflux email/password creds.
  creds = ask_for_conflux_creds

  # Login to Conflux with these creds, returning a valid user-token.
  auth_resp = Conify::Api::Users.new.(creds)

  # Push new service to Conflux.
  push_resp = Conify::Api::Addons.new.push(manifest_content, auth_resp['user_token'])

  display "Successfully pushed draft service to Conflux!\nRun 'conify open' to finish editing your service's information."
end

#testObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/conify/command/global.rb', line 32

def test
  begin
    # Get the content from conflux-manifest.json and add the 'env'
    # key specifying which environment to test.
    data = manifest_content
    data['env'] = (@args[0] === '--production') ? 'production' : 'test'

    # Run all tests to ensure Conflux integration is set up correctly
    Conify::AllTest.new(data).call

    display "Everything checks out!\nRun 'conify push' to push your service to Conflux."
  rescue Exception => e
    display e.message
  end
end