summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsnehaldwivedi <sdwivedi@msystechnologies.com>2020-09-21 06:19:57 -0700
committersnehaldwivedi <sdwivedi@msystechnologies.com>2021-02-16 02:45:13 -0800
commitb64b1072c70168ea8111537e69cc689f3e168dfd (patch)
treed9fea27c774ffbd68965b92efe38df5953480ae2
parentad08878d5dfa053083740d934cec8ec4cef91196 (diff)
downloadchef-b64b1072c70168ea8111537e69cc689f3e168dfd.tar.gz
Updated changes for variable name and class name
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
-rw-r--r--lib/chef/abstract_user.rb106
-rw-r--r--lib/chef/user.rb4
-rw-r--r--lib/chef/user_v1.rb4
-rw-r--r--lib/chef/userable.rb6
4 files changed, 113 insertions, 7 deletions
diff --git a/lib/chef/abstract_user.rb b/lib/chef/abstract_user.rb
new file mode 100644
index 0000000000..dc53488349
--- /dev/null
+++ b/lib/chef/abstract_user.rb
@@ -0,0 +1,106 @@
+#
+# Author:: Snehal Dwivedi (sdwivedi@chef.io)
+# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# common methods of User and UserV1
+class Chef
+ class AbstractUser
+
+ def initialize
+ @name = ""
+ @password = nil
+ @admin = false
+ @username = nil
+ @display_name = nil
+ @first_name = nil
+ @middle_name = nil
+ @last_name = nil
+ @email = nil
+ @public_key = nil
+ @private_key = nil
+ @create_key = nil
+ end
+
+ def chef_root_rest_v0
+ @chef_root_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "0" })
+ end
+
+ def chef_root_rest_v1
+ @chef_root_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "1" })
+ end
+
+ def name(arg = nil)
+ set_or_return(:name, arg,
+ regex: /^[a-z0-9\-_]+$/)
+ end
+
+ def admin(arg = nil)
+ set_or_return(:admin,
+ arg, kind_of: [TrueClass, FalseClass])
+ end
+
+ def username(arg = nil)
+ set_or_return(:username, arg,
+ regex: /^[a-z0-9\-_]+$/)
+ end
+
+ def display_name(arg = nil)
+ set_or_return(:display_name,
+ arg, kind_of: String)
+ end
+
+ def first_name(arg = nil)
+ set_or_return(:first_name,
+ arg, kind_of: String)
+ end
+
+ def middle_name(arg = nil)
+ set_or_return(:middle_name,
+ arg, kind_of: String)
+ end
+
+ def last_name(arg = nil)
+ set_or_return(:last_name,
+ arg, kind_of: String)
+ end
+
+ def email(arg = nil)
+ set_or_return(:email,
+ arg, kind_of: String)
+ end
+
+ def create_key(arg = nil)
+ set_or_return(:create_key, arg,
+ kind_of: [TrueClass, FalseClass])
+ end
+
+ def public_key(arg = nil)
+ set_or_return(:public_key,
+ arg, kind_of: String)
+ end
+
+ def private_key(arg = nil)
+ set_or_return(:private_key,
+ arg, kind_of: String)
+ end
+
+ def password(arg = nil)
+ set_or_return(:password,
+ arg, kind_of: String)
+ end
+ end
+end
diff --git a/lib/chef/user.rb b/lib/chef/user.rb
index 1350db5f10..8691bb4a50 100644
--- a/lib/chef/user.rb
+++ b/lib/chef/user.rb
@@ -22,7 +22,7 @@ require_relative "mash"
require_relative "json_compat"
require_relative "search/query"
require_relative "server_api"
-require_relative "userable"
+require_relative "abstract_user"
# TODO
# DEPRECATION NOTE
@@ -36,7 +36,7 @@ require_relative "userable"
# This file and corresponding osc_user knife files
# should be removed once client support for Open Source Chef Server 11 expires.
class Chef
- class User < Chef::Userable
+ class User < Chef::AbstractUser
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
diff --git a/lib/chef/user_v1.rb b/lib/chef/user_v1.rb
index a8dc9215c5..e5c3f07eff 100644
--- a/lib/chef/user_v1.rb
+++ b/lib/chef/user_v1.rb
@@ -24,7 +24,7 @@ require_relative "search/query"
require_relative "mixin/api_version_request_handling"
require_relative "exceptions"
require_relative "server_api"
-require_relative "userable"
+require_relative "abstract_user"
# OSC 11 BACKWARDS COMPATIBILITY NOTE (remove after OSC 11 support ends)
#
@@ -34,7 +34,7 @@ require_relative "userable"
#
# Exception: self.list is backwards compatible with OSC 11
class Chef
- class UserV1 < Chef::Userable
+ class UserV1 < Chef::AbstractUser
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
diff --git a/lib/chef/userable.rb b/lib/chef/userable.rb
index 2c25f5237d..46b45d01cb 100644
--- a/lib/chef/userable.rb
+++ b/lib/chef/userable.rb
@@ -18,7 +18,7 @@
# common methods of User and UserV1
class Chef
- class Userable
+ class BaseUser
def initialize
@name = ""
@@ -36,11 +36,11 @@ class Chef
end
def chef_root_rest_v0
- @chef_root_rest_v22 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "0" })
+ @chef_root_rest_v0 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "0" })
end
def chef_root_rest_v1
- @chef_root_rest_v22 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "1" })
+ @chef_root_rest_v1 ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "1" })
end
def name(arg = nil)