Class: Vagrant::Node::NodeServerPasswd

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-node/nodeserverpasswd.rb

Instance Method Summary collapse

Instance Method Details

#ask_for_configObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-node/nodeserverpasswd.rb', line 10

def ask_for_config
  puts "Configuring Vagrant Node"
  puts "Insert database user:"
  user=STDIN.noecho(&:gets).chomp
  print "\n"
  print "Insert database password:"
  password=STDIN.noecho(&:gets).chomp
  print "\n"
  print "Insert database name:"
  database=STDIN.noecho(&:gets).chomp
  print "\n"

  DB::DBManager.create_config_file(@env.data_dir,'localhost',database,user,password)

  DB::DBManager.check_bbdd_structure

end

#executeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/vagrant-node/nodeserverpasswd.rb', line 28

def execute
	     options = {}

  opts = OptionParser.new do |opts|
    opts.banner = "Usage: vagrant nodeserver passwd"
  end
  
  # argv = parse_options(opts)
  # raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length > 1
  
  
  
  # if (argv.length==0)
  
    i=0


    begin    

      if (!DB::DBManager.check_config_file(@env.data_dir))

        

        puts "Configuring Vagrant Node"
        print "Insert privileged database user:  "
        user=STDIN.cooked(&:gets).chomp
        
        print "Insert privileged database user password:  "
        password=STDIN.noecho(&:gets).chomp
        print "\n"
        print "Insert database name:  "
        database=STDIN.cooked(&:gets).chomp
        print "\n"

        DB::DBManager.create_config_file(@env.data_dir,'localhost',database,user,password)


      end

      
      db = DB::DBManager.new(@env.data_dir)  

    rescue Exception => e            
      
      if (!DB::DBManager.check_config_file(@env.data_dir))
        retry
      end
      
      if (e.class==Mysql2::Error)              
        print "Can't connect to mysql with current configuration, please review provided credentials. Please execute again this command to reconfigure"
        DB::DBManager.delete_config_file(@env.data_dir)                
      end
      
    end
    
    if (!db.nil?)
      #Checking if user knows the old password
      if (db.node_password_set? && !db.node_default_password_set?)              
        print "Insert current password: "
        old_password=STDIN.noecho(&:gets).chomp
        print "\n"
        if !db.node_check_password?(old_password)
          @env.ui.error("Password failed!")
          return 0
        end            
      end
      
      pass_m = "Insert your new password for this Node: "
      confirm_m = "Please Insert again the new password: "
      
     
      if STDIN.respond_to?(:noecho)
        print pass_m
        password=STDIN.noecho(&:gets).chomp
        print "\n#{confirm_m}"
        confirm=STDIN.noecho(&:gets).chomp
        print "\n"
      else
        #FIXME Don't show password 
        password = @env.ui.ask(pass_m)
        confirm = @env.ui.ask(confirm_m)
      end
      
      if (password==confirm)              
        db.node_password_set(password)
        @env.ui.success("Password changed!")
      else
        @env.ui.error("Passwords does not match!")
      end
    end
  
  
  
    
         
  
  
  		         		
  0
end