Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def self.get_base_opts(user:, auth: nil)
opts = {}

opts[:options] = {}
opts[:options][:oapi_version] = user.rest_preferences[:oapi_version] ||
user.env.api_version
opts[:options][:api_version] = user.rest_preferences[:api_version] ||
user.env.api_version
opts[:options][:accept] = "application/json"
Expand Down Expand Up @@ -94,7 +92,6 @@ def self.normalize_header_list(_headers)
def self.delegate_rest_request(req, base_opts, req_opts)
## use special hash like class to track usage of supplied options
tracked_opts = UsageTrackingHash.new(base_opts.delete(:options).merge(req_opts))
tracked_opts[:oapi_version] # make sure this is marked accessed
tracked_opts[:api_version] # make sure this is marked accessed

case
Expand Down
4 changes: 2 additions & 2 deletions lib/rest_kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Rest
module Kubernetes
extend Helper

def self.populate(path, base_opts, opts)
populate_common("/api/<api_version>", path, base_opts, opts)
def self.populate(path, base_opts, opts, type)
populate_common("/apis/#{type}.k8s.io/<api_version>", path, base_opts, opts)
end

class << self
Expand Down
46 changes: 14 additions & 32 deletions lib/rest_openshift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Rest
module OpenShift
extend Helper

def self.populate(path, base_opts, opts)
populate_common("/oapi/<oapi_version>", path, base_opts, opts)
def self.populate(path, base_opts, opts, type)
populate_common("/apis/#{type}.openshift.io/<api_version>", path, base_opts, opts)
Comment thread
akostadinov marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using api_version here is not correct. In fact all these something.openshift.io APIs may use different API version. But since it is less broken than before, we can merge as is to get something working. We need more investigation to figure out what might be an approach that makes sense.

/lgtm

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by may use different API version? Shouldn't they all be using the same api version?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well initial assumpion was that there will be one global API version like 1, 2, 3. Now they have multiple something.k8s.io and somehting.openshift.io APIs and each of them can have a different independent API level. Having a single parameter for this will not work.

On the other hand it can be overridden for each call so maybe will work. As long as it works now, I'm fine.

end

class << self
Expand All @@ -32,27 +32,27 @@ def self.version(base_opts, opts)
end

def self.delete_oauthaccesstoken(base_opts, opts)
populate("/oauthaccesstokens/<token_to_delete>", base_opts, opts)
populate("/oauthaccesstokens/<token_to_delete>", base_opts, opts, "oauth")
return perform(**base_opts, method: "DELETE")
end

def self.list_projects(base_opts, opts)
populate("/projects", base_opts, opts)
populate("/projects", base_opts, opts, "project")
return perform(**base_opts, method: "GET")
end

def self.delete_project(base_opts, opts)
populate("/projects/<project_name>", base_opts, opts)
populate("/projects/<project_name>", base_opts, opts, "project")
return perform(**base_opts, method: "DELETE")
end

def self.get_project(base_opts, opts)
populate("/projects/<project_name>", base_opts, opts)
populate("/projects/<project_name>", base_opts, opts, "project")
return perform(**base_opts, method: "GET")
end

def self.get_user(base_opts, opts)
populate("/users/<username>", base_opts, opts)
populate("/users/<username>", base_opts, opts, "user")
return perform(**base_opts, method: "GET") { |res|
res[:props][:name] = res[:parsed]["metadata"]["name"]
res[:props][:uid] = res[:parsed]["metadata"]["uid"]
Expand All @@ -63,24 +63,22 @@ def self.get_user(base_opts, opts)
def self.create_project_request(base_opts, opts)
base_opts[:payload] = {}
# see https://bugzilla.redhat.com/show_bug.cgi?id=1244889 for apiVersion
base_opts[:payload][:apiVersion] = opts[:oapi_version]
base_opts[:payload]["displayName"] = opts[:display_name] if opts[:display_name]
base_opts[:payload]["description"] = opts[:description] if opts[:description]
# base_opts[:payload][:kind] = "ProjectRequest"
base_opts[:payload][:metadata] = {name: opts[:project_name]}

populate("/projectrequests", base_opts, opts)
populate("/projectrequests", base_opts, opts, "project")
return Http.request(**base_opts, method: "POST")
end

def self.post_local_resource_access_reviews(base_opts, opts)
base_opts[:payload] = {}
base_opts[:payload][:apiVersion] = opts[:oapi_version]
base_opts[:payload][:kind] = "LocalResourceAccessReview"
base_opts[:payload][:verb] = opts[:verb]
base_opts[:payload][:resource] = opts[:resource]
project_name = opts[:project_name]
populate("/namespaces/<project_name>/localresourceaccessreviews", base_opts, opts)
populate("/namespaces/<project_name>/localresourceaccessreviews", base_opts, opts, "authorization")
return perform(**base_opts, method: "POST")
end

Expand All @@ -92,7 +90,7 @@ def self.create_oauth_access_token(base_opts, opts)
base_opts[:payload][:scopes] = opts[:scopes] if opts[:scopes]


populate("/oauthaccesstokens", base_opts, opts)
populate("/oauthaccesstokens", base_opts, opts, "oauth")
return perform(**base_opts, method: "POST") { |res|
# res[:props][:name] = res[:parsed]["metadata"]["name"]
# res[:props][:uid] = res[:parsed]["metadata"]["uid"]
Expand All @@ -110,42 +108,26 @@ def self.rollback_deploy(base_opts, opts)

project_name = opts[:project_name]

populate("/namespaces/<project_name>/deploymentconfigrollbacks", base_opts, opts)
populate("/namespaces/<project_name>/deploymentconfigrollbacks", base_opts, opts, "apps")
return Http.request(**base_opts, method: "POST")
end

def self.get_subresources_oapi(base_opts, opts)
populate("/namespaces/<project_name>/<resource_type>/<resource_name>/status", base_opts, opts)
return Http.request(**base_opts, method: "GET")
end

def self.post_role_oapi(base_opts, opts)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pruan-rht any replacement for this method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stuartchuan, for 4.0, oapi has been removed, that's why I took out this method

base_opts[:payload] = {}
base_opts[:payload]["kind"] = opts[:kind]
base_opts[:payload]["apiVersion"] = opts[:api_version]
base_opts[:payload]["verb"] = opts[:verb]
base_opts[:payload]["resource"] = opts[:resource]
base_opts[:payload]["user"] = opts[:user]

populate("/namespaces/<project_name>/<role>", base_opts, opts)
return Http.request(**base_opts, method: "POST")
end

def self.post_pod_security_policy_self_subject_reviews(base_opts, opts)
base_opts[:payload] = File.read(expand_path(opts[:payload_file]))
populate("/namespaces/<project_name>/podsecuritypolicyselfsubjectreviews", base_opts, opts)
populate("/namespaces/<project_name>/podsecuritypolicyselfsubjectreviews", base_opts, opts, "security")
return perform(**base_opts, method: "POST")
end

def self.post_pod_security_policy_subject_reviews(base_opts, opts)
base_opts[:payload] = File.read(expand_path(opts[:payload_file]))
populate("/namespaces/<project_name>/podsecuritypolicysubjectreviews", base_opts, opts)
populate("/namespaces/<project_name>/podsecuritypolicysubjectreviews", base_opts, opts, "security")
return perform(**base_opts, method: "POST")
end

def self.post_pod_security_policy_reviews(base_opts, opts)
base_opts[:payload] = File.read(expand_path(opts[:payload_file]))
populate("/namespaces/<project_name>/podsecuritypolicyreviews", base_opts, opts)
populate("/namespaces/<project_name>/podsecuritypolicyreviews", base_opts, opts, "security")
return perform(**base_opts, method: "POST")
end

Expand Down