Checks if current user can access docker
550008
def check_permissions():
    
    if (
        not grp.getgrnam('docker').gr_gid in os.getgroups()
        and not os.geteuid() == 0
    ):
        exitStr = """
        User doesn't have permission to use docker.
        You can do either of the following,
        1. Add user to the 'docker' group (preferred)
        2. Run command as superuser using either 'sudo' or 'su -c'
        """
        exit(exitStr)
662970
def get_container_ip(container_id_or_name):
    """"""
    command = [
        'docker',
        'inspect',
        '-f',
        '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}',
        container_id_or_name,
    ]

    return run_command(command, capture='out', check=True).stdout.strip()
441100
def dockerPredicate(e):
    
    if not isinstance(e, subprocess.CalledProcessError):
        return False
    if e.returncode == 125:
        return True
523561
def check_auth(self):
        """"""
        # access permissions
        if self.auth is not None:
            return self.auth(self.request)

        return self.public_readble, self.public_writable
249978
def is_installed(self, name: str) -> bool:
        
        assert name is not None
        try:
            self.__docker.images.get(name)
            return True
        except docker.errors.ImageNotFound:
            return False
443721
def check_authorization
        unless current_user
          render nothing: true, status: :unauthorized
          return false
        end
        if params[:organization_id] && !parent_organization
          render nothing: true, status: :forbidden
          return false
        end
        true
      end
1313119
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_download_files(obj, user)
583660
def _connect_docker(spec):
    
    return {
        'method': 'docker',
        'kwargs': {
            'username': spec.remote_user(),
            'container': spec.remote_addr(),
            'python_path': spec.python_path(),
            'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
            'remote_name': get_remote_name(spec),
        }
    }
711902
def CheckIfUserIsAdmin(self, username):
    """"""

    user_obj = data_store.REL_DB.ReadGRRUser(username)
    if user_obj.user_type != user_obj.UserType.USER_TYPE_ADMIN:
      raise access_control.UnauthorizedAccess("User %s is not an admin." %
                                              username)
528608
def has_read_permission(self, request, path):
        
        user = request.user
        if not user.is_authenticated():
            return False
        elif user.is_superuser:
            return True
        elif user.is_staff:
            return True
        else:
            return False
38578
def has_image(self, image_name):
        

        try:
            self.docker_client.images.get(image_name)
            return True
        except docker.errors.ImageNotFound:
            return False
675954
def read_login(collector, image, **kwargs):
    """"""
    docker_api = collector.configuration["harpoon"].docker_api
    collector.configuration["authentication"].login(docker_api, image, is_pushing=False, global_docker=True)
110052
def allowed_to_preview(user):
    
    if (
        user.is_authenticated and
        user.is_active and
        user.is_staff
    ):
        return True
    return False
369059
def can_view(self, user):
        """"""
        return user.is_admin or user in self.users \
            or self.project.class_ in user.admin_for
926398
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_access_moderation_queue(user)
16099
def has_image(self, name: str) -> bool:
        
        path = "docker/images/{}".format(name)
        r = self.__api.head(path)
        if r.status_code == 204:
            return True
        elif r.status_code == 404:
            return False
        self.__api.handle_erroneous_response(r)
380942
def get_current_user():
    
    if pwd is None:
        return getpass.getuser()
    else:
        try:
            return pwd.getpwuid(os.getuid())[0]
        except KeyError as error:
            LOGGER.error('Could not get logged-in user: %s', error)