# frozen_string_literal: true # #Kubernetes # # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # # The version of the OpenAPI document: unversioned # # Generated by: https://openapi-generator.tech # OpenAPI Generator version: 6.5.0-SNAPSHOT # require 'date' require 'time' module Zilla # MutatingWebhook describes an admission webhook and the resources and operations it applies to. class IoK8sApiAdmissionregistrationV1MutatingWebhook # AdmissionReviewVersions is an ordered list of preferred `AdmissionReview` versions the Webhook expects. API server will try to use first version in the list which it supports. If none of the versions specified in this list supported by API server, validation will fail for this object. If a persisted webhook configuration specifies allowed versions and does not include any versions known to the API Server, calls to the webhook will fail and be subject to the failure policy. attr_accessor :admission_review_versions attr_accessor :client_config, :namespace_selector, :object_selector # FailurePolicy defines how unrecognized errors from the admission endpoint are handled - allowed values are Ignore or Fail. Defaults to Fail. attr_accessor :failure_policy # matchPolicy defines how the \"rules\" list is used to match incoming requests. Allowed values are \"Exact\" or \"Equivalent\". - Exact: match a request only if it exactly matches a specified rule. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, but \"rules\" only included `apiGroups:[\"apps\"], apiVersions:[\"v1\"], resources: [\"deployments\"]`, a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the webhook. - Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, and \"rules\" only included `apiGroups:[\"apps\"], apiVersions:[\"v1\"], resources: [\"deployments\"]`, a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the webhook. Defaults to \"Equivalent\" attr_accessor :match_policy # The name of the admission webhook. Name should be fully qualified, e.g., imagepolicy.kubernetes.io, where \"imagepolicy\" is the name of the webhook, and kubernetes.io is the name of the organization. Required. attr_accessor :name # reinvocationPolicy indicates whether this webhook should be called multiple times as part of a single admission evaluation. Allowed values are \"Never\" and \"IfNeeded\". Never: the webhook will not be called more than once in a single admission evaluation. IfNeeded: the webhook will be called at least one additional time as part of the admission evaluation if the object being admitted is modified by other admission plugins after the initial webhook call. Webhooks that specify this option *must* be idempotent, able to process objects they previously admitted. Note: * the number of additional invocations is not guaranteed to be exactly one. * if additional invocations result in further modifications to the object, webhooks are not guaranteed to be invoked again. * webhooks that use this option may be reordered to minimize the number of additional invocations. * to validate an object after all mutations are guaranteed complete, use a validating admission webhook instead. Defaults to \"Never\". attr_accessor :reinvocation_policy # Rules describes what operations on what resources/subresources the webhook cares about. The webhook cares about an operation if it matches _any_ Rule. However, in order to prevent ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks from putting the cluster in a state which cannot be recovered from without completely disabling the plugin, ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks are never called on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects. attr_accessor :rules # SideEffects states whether this webhook has side effects. Acceptable values are: None, NoneOnDryRun (webhooks created via v1beta1 may also specify Some or Unknown). Webhooks with side effects MUST implement a reconciliation system, since a request may be rejected by a future step in the admission chain and the side effects therefore need to be undone. Requests with the dryRun attribute will be auto-rejected if they match a webhook with sideEffects == Unknown or Some. attr_accessor :side_effects # TimeoutSeconds specifies the timeout for this webhook. After the timeout passes, the webhook call will be ignored or the API call will fail based on the failure policy. The timeout value must be between 1 and 30 seconds. Default to 10 seconds. attr_accessor :timeout_seconds # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { admission_review_versions: :admissionReviewVersions, client_config: :clientConfig, failure_policy: :failurePolicy, match_policy: :matchPolicy, name: :name, namespace_selector: :namespaceSelector, object_selector: :objectSelector, reinvocation_policy: :reinvocationPolicy, rules: :rules, side_effects: :sideEffects, timeout_seconds: :timeoutSeconds } end # Returns all the JSON keys this model knows about def self.acceptable_attributes attribute_map.values end # Attribute type mapping. def self.openapi_types { admission_review_versions: :'Array', client_config: :IoK8sApiAdmissionregistrationV1WebhookClientConfig, failure_policy: :String, match_policy: :String, name: :String, namespace_selector: :IoK8sApimachineryPkgApisMetaV1LabelSelector, object_selector: :IoK8sApimachineryPkgApisMetaV1LabelSelector, reinvocation_policy: :String, rules: :'Array', side_effects: :String, timeout_seconds: :Integer } end # List of attributes with nullable: true def self.openapi_nullable Set.new([]) end # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) unless attributes.is_a?(Hash) raise ArgumentError, 'The input argument (attributes) must be a hash in `Zilla::IoK8sApiAdmissionregistrationV1MutatingWebhook` initialize method' end # check to see if the attribute exists and convert string to symbol for hash key attributes = attributes.each_with_object({}) do |(k, v), h| unless self.class.attribute_map.key?(k.to_sym) raise ArgumentError, "`#{k}` is not a valid attribute in `Zilla::IoK8sApiAdmissionregistrationV1MutatingWebhook`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect end h[k.to_sym] = v end if attributes.key?(:admission_review_versions) && (value = attributes[:admission_review_versions]).is_a?(Array) self.admission_review_versions = value end self.client_config = attributes[:client_config] if attributes.key?(:client_config) self.failure_policy = attributes[:failure_policy] if attributes.key?(:failure_policy) self.match_policy = attributes[:match_policy] if attributes.key?(:match_policy) self.name = attributes[:name] if attributes.key?(:name) self.namespace_selector = attributes[:namespace_selector] if attributes.key?(:namespace_selector) self.object_selector = attributes[:object_selector] if attributes.key?(:object_selector) self.reinvocation_policy = attributes[:reinvocation_policy] if attributes.key?(:reinvocation_policy) if attributes.key?(:rules) && (value = attributes[:rules]).is_a?(Array) self.rules = value end self.side_effects = attributes[:side_effects] if attributes.key?(:side_effects) return unless attributes.key?(:timeout_seconds) self.timeout_seconds = attributes[:timeout_seconds] end # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properties with the reasons def list_invalid_properties invalid_properties = [] if @admission_review_versions.nil? invalid_properties.push('invalid value for "admission_review_versions", admission_review_versions cannot be nil.') end invalid_properties.push('invalid value for "client_config", client_config cannot be nil.') if @client_config.nil? invalid_properties.push('invalid value for "name", name cannot be nil.') if @name.nil? invalid_properties.push('invalid value for "side_effects", side_effects cannot be nil.') if @side_effects.nil? invalid_properties end # Check to see if the all the properties in the model are valid # @return true if the model is valid def valid? return false if @admission_review_versions.nil? return false if @client_config.nil? return false if @name.nil? return false if @side_effects.nil? true end # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(other) return true if equal?(other) self.class == other.class && admission_review_versions == other.admission_review_versions && client_config == other.client_config && failure_policy == other.failure_policy && match_policy == other.match_policy && name == other.name && namespace_selector == other.namespace_selector && object_selector == other.object_selector && reinvocation_policy == other.reinvocation_policy && rules == other.rules && side_effects == other.side_effects && timeout_seconds == other.timeout_seconds end # @see the `==` method # @param [Object] Object to be compared def eql?(other) self == other end # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash [admission_review_versions, client_config, failure_policy, match_policy, name, namespace_selector, object_selector, reinvocation_policy, rules, side_effects, timeout_seconds].hash end # Builds the object from hash # @param [Hash] attributes Model attributes in the form of hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) new.build_from_hash(attributes) end # Builds the object from hash # @param [Hash] attributes Model attributes in the form of hash # @return [Object] Returns the model itself def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) self.class.openapi_types.each_pair do |key, type| if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) send("#{key}=", nil) elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not if attributes[self.class.attribute_map[key]].is_a?(Array) send("#{key}=", attributes[self.class.attribute_map[key]].map do |v| _deserialize(::Regexp.last_match(1), v) end) end elsif !attributes[self.class.attribute_map[key]].nil? send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) end end self end # Deserializes the data based on type # @param string type Data type # @param string value Value to be deserialized # @return [Object] Deserialized data def _deserialize(type, value) case type.to_sym when :Time Time.parse(value) when :Date Date.parse(value) when :String value.to_s when :Integer value.to_i when :Float value.to_f when :Boolean if value.to_s =~ /\A(true|t|yes|y|1)\z/i true else false end when :Object # generic object (usually a Hash), return directly value when /\AArray<(?.+)>\z/ inner_type = Regexp.last_match[:inner_type] value.map { |v| _deserialize(inner_type, v) } when /\AHash<(?.+?), (?.+)>\z/ k_type = Regexp.last_match[:k_type] v_type = Regexp.last_match[:v_type] {}.tap do |hash| value.each do |k, v| hash[_deserialize(k_type, k)] = _deserialize(v_type, v) end end else # model # models (e.g. Pet) or oneOf klass = Zilla.const_get(type) klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) end end # Returns the string representation of the object # @return [String] String presentation of the object def to_s to_hash.to_s end # to_body is an alias to to_hash (backward compatibility) # @return [Hash] Returns the object in the form of hash def to_body to_hash end # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash hash = {} self.class.attribute_map.each_pair do |attr, param| value = send(attr) if value.nil? is_nullable = self.class.openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end hash[param] = _to_hash(value) end hash end # Outputs non-array value in the form of hash # For object, use to_hash. Otherwise, just return the value # @param [Object] value Any valid value # @return [Hash] Returns the value in the form of hash def _to_hash(value) if value.is_a?(Array) value.compact.map { |v| _to_hash(v) } elsif value.is_a?(Hash) {}.tap do |hash| value.each { |k, v| hash[k] = _to_hash(v) } end elsif value.respond_to? :to_hash value.to_hash else value end end end end