# coding: utf-8

"""
    Kubernetes

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: release-1.29
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json


from typing import Optional
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr
from .v1_capabilities import V1Capabilities
from .v1_se_linux_options import V1SELinuxOptions
from .v1_seccomp_profile import V1SeccompProfile
from .v1_windows_security_context_options import V1WindowsSecurityContextOptions

class V1SecurityContext(BaseModel):
    """
    SecurityContext holds security configuration that will be applied to a container. Some fields are present in both SecurityContext and PodSecurityContext.  When both are set, the values in SecurityContext take precedence.  # noqa: E501
    """
    allow_privilege_escalation: Optional[StrictBool] = Field(None, alias="allowPrivilegeEscalation", description="AllowPrivilegeEscalation controls whether a process can gain more privileges than its parent process. This bool directly controls if the no_new_privs flag will be set on the container process. AllowPrivilegeEscalation is true always when the container is: 1) run as Privileged 2) has CAP_SYS_ADMIN Note that this field cannot be set when spec.os.name is windows.")
    capabilities: Optional[V1Capabilities] = None
    privileged: Optional[StrictBool] = Field(None, description="Run container in privileged mode. Processes in privileged containers are essentially equivalent to root on the host. Defaults to false. Note that this field cannot be set when spec.os.name is windows.")
    proc_mount: Optional[StrictStr] = Field(None, alias="procMount", description="procMount denotes the type of proc mount to use for the containers. The default is DefaultProcMount which uses the container runtime defaults for readonly paths and masked paths. This requires the ProcMountType feature flag to be enabled. Note that this field cannot be set when spec.os.name is windows.")
    read_only_root_filesystem: Optional[StrictBool] = Field(None, alias="readOnlyRootFilesystem", description="Whether this container has a read-only root filesystem. Default is false. Note that this field cannot be set when spec.os.name is windows.")
    run_as_group: Optional[StrictInt] = Field(None, alias="runAsGroup", description="The GID to run the entrypoint of the container process. Uses runtime default if unset. May also be set in PodSecurityContext.  If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. Note that this field cannot be set when spec.os.name is windows.")
    run_as_non_root: Optional[StrictBool] = Field(None, alias="runAsNonRoot", description="Indicates that the container must run as a non-root user. If true, the Kubelet will validate the image at runtime to ensure that it does not run as UID 0 (root) and fail to start the container if it does. If unset or false, no such validation will be performed. May also be set in PodSecurityContext.  If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence.")
    run_as_user: Optional[StrictInt] = Field(None, alias="runAsUser", description="The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified. May also be set in PodSecurityContext.  If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. Note that this field cannot be set when spec.os.name is windows.")
    se_linux_options: Optional[V1SELinuxOptions] = Field(None, alias="seLinuxOptions")
    seccomp_profile: Optional[V1SeccompProfile] = Field(None, alias="seccompProfile")
    windows_options: Optional[V1WindowsSecurityContextOptions] = Field(None, alias="windowsOptions")
    __properties = ["allowPrivilegeEscalation", "capabilities", "privileged", "procMount", "readOnlyRootFilesystem", "runAsGroup", "runAsNonRoot", "runAsUser", "seLinuxOptions", "seccompProfile", "windowsOptions"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> V1SecurityContext:
        """Create an instance of V1SecurityContext from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of capabilities
        if self.capabilities:
            _dict['capabilities'] = self.capabilities.to_dict()
        # override the default output from pydantic by calling `to_dict()` of se_linux_options
        if self.se_linux_options:
            _dict['seLinuxOptions'] = self.se_linux_options.to_dict()
        # override the default output from pydantic by calling `to_dict()` of seccomp_profile
        if self.seccomp_profile:
            _dict['seccompProfile'] = self.seccomp_profile.to_dict()
        # override the default output from pydantic by calling `to_dict()` of windows_options
        if self.windows_options:
            _dict['windowsOptions'] = self.windows_options.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> V1SecurityContext:
        """Create an instance of V1SecurityContext from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return V1SecurityContext.parse_obj(obj)

        _obj = V1SecurityContext.parse_obj({
            "allow_privilege_escalation": obj.get("allowPrivilegeEscalation"),
            "capabilities": V1Capabilities.from_dict(obj.get("capabilities")) if obj.get("capabilities") is not None else None,
            "privileged": obj.get("privileged"),
            "proc_mount": obj.get("procMount"),
            "read_only_root_filesystem": obj.get("readOnlyRootFilesystem"),
            "run_as_group": obj.get("runAsGroup"),
            "run_as_non_root": obj.get("runAsNonRoot"),
            "run_as_user": obj.get("runAsUser"),
            "se_linux_options": V1SELinuxOptions.from_dict(obj.get("seLinuxOptions")) if obj.get("seLinuxOptions") is not None else None,
            "seccomp_profile": V1SeccompProfile.from_dict(obj.get("seccompProfile")) if obj.get("seccompProfile") is not None else None,
            "windows_options": V1WindowsSecurityContextOptions.from_dict(obj.get("windowsOptions")) if obj.get("windowsOptions") is not None else None
        })
        return _obj


