equitrac_utilities 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88383c0054aff33d3e6c0721086e3958b83caa850c4a35618f6731ea825e8465
4
- data.tar.gz: 13e974e458f10d5d223004e9f6b2f99fff0b79576d3037f0b1bbc152ed30ca2d
3
+ metadata.gz: 52ae01d71a54e67378d87b11a652a4049d5f51e1631a1daf61fc312a2b5dce1d
4
+ data.tar.gz: 237bc1a155e3f92aecb0eac93e1362186257621953b9b7b4d1aea1dc2e3a4bd9
5
5
  SHA512:
6
- metadata.gz: d53040ec3c9dc6f227af7f7a302e617f289e2ef658fd495b1914cd3ef4ee19d99784cf17d19c5b5210ab475da824dde1d0086754060447fc6c18f17a4d7fbbf2
7
- data.tar.gz: a89096a49465fe5dabb9a339b3dc6d2c9de08f23004f6e7f6fe505514c4f7bd62d28c42946b4cb7945226a70988e5811819b9c2954439ecb91721b4e2070e77b
6
+ metadata.gz: c8726000b99ac7de2d1c2a62049f882af02bfb09d2abccfd0c691deb4c08d53553d7edd6235daab814b09d5b03975613e427cf5c0eb1ad38e94bd60387e5affb
7
+ data.tar.gz: e48929ad346cf4015dcdd774deafa0b7327899a3cc183bdf92da9a28ba957fed9b9d6af3760105e35ab623bbe94fcd36af8472b5fcaddfc0c7aaf4e58cef3daa
@@ -38,7 +38,8 @@ module EquitracUtilities
38
38
  def run(command:, attributes:)
39
39
  result = ''
40
40
  begin
41
- action = send(:check_user_id, command, attributes)
41
+ action = send(command, attributes)
42
+ # action = send(:check_user_id, command, attributes)
42
43
  ssh_cmd = build_full_command(action)
43
44
  response = send_eqcmd(ssh_cmd)
44
45
  result = post_processing(command, response)
@@ -78,8 +79,14 @@ module EquitracUtilities
78
79
  end
79
80
 
80
81
  def post_processing(command, answer)
81
- return process_user_exists?(answer) if command.eql? :user_exists?
82
- answer
82
+ # return process_user_exists?(answer) if command.eql? :user_exists?
83
+ if command.eql? :user_exists?
84
+ return false if answer.include?("Can't find")
85
+ return true if answer.include?("User_ID")
86
+ raise
87
+ end
88
+ # error_count = answer.count { |r| r.include? 'Error' }
89
+ return answer
83
90
  end
84
91
 
85
92
  def defaults
@@ -4,25 +4,53 @@ module EquitracUtilities
4
4
  module UserActions
5
5
 
6
6
 
7
+ # # Be sure Actions have correct user_id data
8
+ # #
9
+ # # @param action [Symbol] the action to be formatted
10
+ # # @return [String] this attribute MUST include: { user_id: "userid" }
11
+ # def check_user_id(action, attribs)
12
+ # # attribs[:uid] = attribs[:uid].to_s.strip
13
+ # attribs[:user_id] = attribs[:user_id]&.strip
14
+ # answer = send(action, attribs)
15
+ # raise ArgumentError, "missing user_id" if attribs[:user_id].nil? or
16
+ # attribs[:user_id].empty?
17
+ # raise ArgumentError, "user_id has space" if attribs[:user_id].include?(' ')
18
+ # return answer
19
+ # end
20
+
7
21
  # Be sure Actions have correct user_id data
8
22
  #
9
23
  # @param action [Symbol] the action to be formatted
10
24
  # @return [String] this attribute MUST include: { user_id: "userid" }
11
- def check_user_id(action, attribs)
12
- attribs[:user_id] = attribs[:user_id]&.strip
13
- answer = send(action, attribs)
14
- raise ArgumentError, "missing user_id" if attribs[:user_id].nil? or
15
- attribs[:user_id].empty?
25
+ def check_atrribs(attrs, command=nil)
26
+ raise ArgumentError, "user_id missing" if attrs[:user_id].nil?
27
+ # attribs[:uid] = attribs[:uid].to_s.strip
28
+ attribs = {}
29
+ attrs.each do |k,v|
30
+ attribs[k] = v&.strip if v.is_a? String
31
+ attribs[k] = v unless v.is_a? String
32
+ end
33
+ # attribs[:user_id] = attribs[:user_id]&.strip
34
+ # attribs[:user_name] = attribs[:user_name]&.strip
35
+ # attribs[:email] = attribs[:email]&.strip
36
+ raise ArgumentError, "user_id empty" if attribs[:user_id].empty?
16
37
  raise ArgumentError, "user_id has space" if attribs[:user_id].include?(' ')
17
- return answer
38
+ if command.eql? :user_add
39
+ raise ArgumentError, " missing user_name" if attribs[:user_name].nil?
40
+ raise ArgumentError, " missing email" if attribs[:email].nil?
41
+ raise ArgumentError, " missing dept_name" if attribs[:dept_name].nil?
42
+ end
43
+ return attribs
18
44
  end
19
45
 
46
+
20
47
  # Get Equitrac User Info
21
48
  #
22
49
  # @param attr [Hash] this attribute MUST include: { user_id: "userid" }
23
50
  # @return [String] Formatted for EQCmd.exe command execution
24
- def user_query(attr)
25
- "query ur #{attr[:user_id]}"
51
+ def user_query(attribs)
52
+ attribs = check_atrribs(attribs)
53
+ "query ur #{attribs[:user_id]}"
26
54
  end
27
55
 
28
56
  # Query to test if user exists in Equitrac System
@@ -30,8 +58,9 @@ module EquitracUtilities
30
58
  #
31
59
  # @param attr [Hash] this attribute MUST include: { user_id: "userid" }
32
60
  # @return [String] Formatted for EQCmd.exe command execution
33
- def user_exists?(attr)
34
- user_query(attr)
61
+ def user_exists?(attribs)
62
+ attribs = check_atrribs(attribs)
63
+ user_query(attribs)
35
64
  end
36
65
 
37
66
  # Process to test if user exists in Equitrac System
@@ -49,59 +78,82 @@ module EquitracUtilities
49
78
  #
50
79
  # @param attributes [Hash] this attribute MUST include { user_id: "userid", init_bal: 0, username: "Test USER", dept_name: "Testdept", primary_pin: "99999"}
51
80
  # @return [String] Formatted for EQCmd.exe command execution
52
- def user_add(attributes)
53
- defaults = { min_bal: 0.0, secondary_pin: '""',quota: 0,
54
- alternate_pin: '""', home_server: '""', locked: 0,
55
- location: '""', additional_info: 0, home_folder: '""'}
56
- attr = defaults.merge( attributes )
57
-
58
- "add ur #{attr[:user_id]} #{attr[:init_bal]} \"#{attr[:user_name]}\" " +
59
- "#{attr[:min_bal]} #{attr[:email]} #{attr[:dept_name]}" +
60
- " #{attr[:primary_pin]} #{attr[:secondary_pin]} #{attr[:quota]}" +
61
- " #{attr[:alternate_pin]} #{attr[:home_server]} #{attr[:locked]}" +
62
- " #{attr[:location]} #{attr[:additional_info]} #{attr[:home_folder]}"
81
+ def user_add(attribs)
82
+ defaults = {init_bal: 50.0, min_bal: 0.0, secondary_pin: '""',quota: 0,
83
+ alternate_pin: '""', home_server: '""', locked: 0,
84
+ location: '""', additional_info: 0, home_folder: '""'}
85
+ attribs = defaults.merge( attribs )
86
+
87
+ attribs = check_atrribs(attribs, :user_add)
88
+
89
+ "add ur #{attribs[:user_id]} #{attribs[:init_bal]}" +
90
+ " \"#{attribs[:user_name]}\" #{attribs[:min_bal]}" +
91
+ " #{attribs[:email]} #{attribs[:dept_name]}" +
92
+ " #{attribs[:primary_pin]} #{attribs[:secondary_pin]}" +
93
+ " #{attribs[:quota]} #{attribs[:alternate_pin]}" +
94
+ " #{attribs[:home_server]} #{attribs[:locked]}" +
95
+ " #{attribs[:location]} #{attribs[:additional_info]}" +
96
+ " #{attribs[:home_folder]}"
63
97
  end
64
98
 
65
99
  # Process to delete a user from the Equitrac System
66
100
  #
67
101
  # @param attr [Hash] this attribute MUST include: { user_id: "userid" }
68
102
  # @return [String] Formatted for EQCmd.exe command execution
69
- def user_delete(attr)
70
- "delete ur #{attr[:user_id]}"
103
+ def user_delete(attribs)
104
+ attribs = check_atrribs(attribs)
105
+ "delete ur #{attribs[:user_id]}"
71
106
  end
72
107
 
73
108
  # Process to lock a user in the Equitrac System
74
109
  #
75
110
  # @param attr [Hash] this attribute MUST include: { user_id: "userid" }
76
111
  # @return [String] Formatted for EQCmd.exe command execution
77
- def user_lock(attr)
78
- "lock ur #{attr[:user_id]}"
112
+ def user_lock(attribs)
113
+ attribs = check_atrribs(attribs)
114
+ "lock ur #{attribs[:user_id]}"
79
115
  end
80
116
 
81
117
  # Process to unlock a user in the Equitrac System
82
118
  #
83
119
  # @param attr [Hash] this attribute MUST include: { user_id: "userid" }
84
120
  # @return [String] Formatted for EQCmd.exe command execution
85
- def user_unlock(attr)
86
- "unlock ur #{attr[:user_id]}"
121
+ def user_unlock(attribs)
122
+ attribs = check_atrribs(attribs)
123
+ "unlock ur #{attribs[:user_id]}"
87
124
  end
88
125
 
89
126
  # Process to lock a user in the Equitrac System
90
127
  #
91
128
  # @param attr [Hash] this attribute MUST include: { user_id: "userid" }
92
129
  # @return [String] Formatted for EQCmd.exe command execution
93
- def user_modify(attributes)
130
+ def user_modify(attribs)
94
131
  defaults = {user_name: "!", min_bal: "!",
95
132
  email: "!", dept_name: "!", pimary_pin: "!",
96
133
  secondary_pin: "!", quota: "!", alternate_pin: "!",
97
134
  home_server: "!", locked: "!", location: "!",
98
135
  default_bc: "!", additional_info: "!", home_folder: "!"}
99
- attr = defaults.merge( attributes )
100
- "modify ur #{attr[:user_id]} \"#{attr[:user_name]}\" #{attr[:min_bal]}" +
101
- " #{attr[:email]} #{attr[:dept_name]} #{attr[:primary_pin]}" +
102
- " #{attr[:secondary_pin]} #{attr[:quota]} #{attr[:alternate_pin]}" +
103
- " #{attr[:home_server]} #{attr[:locked]} #{attr[:location]}" +
104
- " #{attr[:default_bc]} #{attr[:additional_info]} #{attr[:home_folder]}"
136
+ attribs = defaults.merge(attribs)
137
+ attribs = check_atrribs(attribs)
138
+ "modify ur #{attribs[:user_id]} \"#{attribs[:user_name]}\"" +
139
+ " #{attribs[:min_bal]} #{attribs[:email]} #{attribs[:dept_name]}" +
140
+ " #{attribs[:primary_pin]} #{attribs[:secondary_pin]}" +
141
+ " #{attribs[:quota]} #{attribs[:alternate_pin]}" +
142
+ " #{attribs[:home_server]} #{attribs[:locked]}" +
143
+ " #{attribs[:location]} #{attribs[:default_bc]}" +
144
+ " #{attribs[:additional_info]} #{attribs[:home_folder]}"
145
+ end
146
+
147
+ # Process to set a new balance for a user in the Equitrac System
148
+ #
149
+ # @param attr [Hash] this attribute MUST include: { user_id: "userid" }
150
+ # @note attr new_bal defaults to 0, if not included in the attributes
151
+ # @return [String] Formatted for EQCmd.exe command execution
152
+ def user_adjust_set(attribs)
153
+ defaults = {new_bal: 0.0, description: nil}
154
+ attribs = defaults.merge(attribs)
155
+ attribs = check_atrribs(attribs)
156
+ "adjust ur #{attribs[:user_id]} set #{attribs[:new_bal]} #{attribs[:description]}"
105
157
  end
106
158
  end
107
159
  end
@@ -1,5 +1,5 @@
1
1
  module EquitracUtilities
2
2
  module Version
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: equitrac_utilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill Tihen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2018-05-25 00:00:00.000000000 Z
13
+ date: 2018-05-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: net-ssh
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '4.0'
21
+ version: '4.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '4.0'
28
+ version: '4.2'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: bundler
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -46,28 +46,28 @@ dependencies:
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '10.0'
49
+ version: '10.5'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '10.0'
56
+ version: '10.5'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rspec
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '3.0'
63
+ version: '3.7'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: '3.0'
70
+ version: '3.7'
71
71
  description: uses ssh to connect to an Equitrac server and send user commands
72
72
  email:
73
73
  - btihen@gmail.com