id int64 0 458k | file_name stringlengths 4 119 | file_path stringlengths 14 227 | content stringlengths 24 9.96M | size int64 24 9.96M | language stringclasses 1
value | extension stringclasses 14
values | total_lines int64 1 219k | avg_line_length float64 2.52 4.63M | max_line_length int64 5 9.91M | alphanum_fraction float64 0 1 | repo_name stringlengths 7 101 | repo_stars int64 100 139k | repo_forks int64 0 26.4k | repo_open_issues int64 0 2.27k | repo_license stringclasses 12
values | repo_extraction_date stringclasses 433
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
24,200 | sharing_tasks.py | truenas_middleware/src/middlewared/middlewared/alert/source/sharing_tasks.py | from middlewared.alert.base import AlertClass, AlertCategory, AlertLevel, Alert, OneShotAlertClass
class ShareLockedAlertClass(AlertClass, OneShotAlertClass):
deleted_automatically = False
level = AlertLevel.WARNING
category = AlertCategory.SHARING
title = 'Share Is Unavailable Because It Uses A Locke... | 1,221 | Python | .py | 21 | 52.571429 | 98 | 0.730705 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,201 | origin.py | truenas_middleware/src/middlewared/middlewared/utils/origin.py | from dataclasses import dataclass
from socket import AF_INET, AF_INET6, AF_UNIX, SO_PEERCRED, SOL_SOCKET
from struct import calcsize, unpack
from pyroute2 import DiagSocket
__all__ = ('ConnectionOrigin',)
HA_HEARTBEAT_IPS = ('169.254.10.1', '169.254.10.2')
UIDS_TO_CHECK = (33, 0)
@dataclass(slots=True, frozen=True... | 5,159 | Python | .py | 118 | 34.59322 | 102 | 0.598289 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,202 | db.py | truenas_middleware/src/middlewared/middlewared/utils/db.py | import sqlite3
FREENAS_DATABASE = '/data/freenas-v1.db'
FREENAS_DATABASE_MODE = 0o600
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
def query_config_table(table, database_path=None, prefix=None):
return query_table(table, ... | 1,270 | Python | .py | 40 | 24.025 | 77 | 0.604423 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,203 | profile.py | truenas_middleware/src/middlewared/middlewared/utils/profile.py | import asyncio
import cProfile
import io
import pstats
from pstats import SortKey
def profile_wrap(func):
if asyncio.iscoroutinefunction(func):
async def wrapper(*args, **kwargs):
pr = cProfile.Profile()
pr.enable()
rv = await func(*args, **kwargs)
pr.disabl... | 841 | Python | .py | 25 | 24.72 | 83 | 0.568796 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,204 | license.py | truenas_middleware/src/middlewared/middlewared/utils/license.py | LICENSE_ADDHW_MAPPING = {
1: "E16",
2: "E24",
3: "E60",
4: "ES60",
5: "ES12",
6: "ES24",
7: "ES24F",
8: "ES60S",
9: "ES102",
10: "ES102G2",
11: "ES60G2",
12: "ES24N",
13: "ES60G3",
}
| 235 | Python | .py | 15 | 11.2 | 25 | 0.436364 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,205 | security_descriptor.py | truenas_middleware/src/middlewared/middlewared/utils/security_descriptor.py | # Utilites related to SMB security descriptors
#
# These are primarily used for manipulating the SMB share ACL, which
# is stored in samba's share_info.tdb file as a packed security descriptor
# In principle, this code can also be used to decode SDDL strings and to
# parse security descriptors from remote servers.
#
# ... | 2,875 | Python | .py | 66 | 37.363636 | 87 | 0.680287 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,206 | time_utils.py | truenas_middleware/src/middlewared/middlewared/utils/time_utils.py | from datetime import datetime, UTC
def utc_now(naive=True):
"""Wrapper for `datetime.now(UTC)`. Exclude timezone if `naive=True`."""
dt = datetime.now(UTC)
return dt.replace(tzinfo=None) if naive else dt
| 218 | Python | .py | 5 | 39.8 | 76 | 0.71564 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,207 | pci.py | truenas_middleware/src/middlewared/middlewared/utils/pci.py | import contextlib
import os
# get capability classes for relevant pci devices from
# https://github.com/pciutils/pciutils/blob/3d2d69cbc55016c4850ab7333de8e3884ec9d498/lib/header.h#L1429
SENSITIVE_PCI_DEVICE_TYPES = {
'0x0604': 'PCI Bridge',
'0x0601': 'ISA Bridge',
'0x0500': 'RAM memory',
'0x0c05': 'S... | 541 | Python | .py | 15 | 31.8 | 103 | 0.700576 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,208 | io.py | truenas_middleware/src/middlewared/middlewared/utils/io.py | # NOTE: tests are provided in src/middlewared/middlewared/pytest/unit/utils/test_write_if_changed.py
# Any updates to this file should have corresponding updates to tests
import fcntl
import os
import enum
import stat
from tempfile import NamedTemporaryFile
ID_MAX = 2 ** 32 - 2
class FileChanges(enum.IntFlag):
... | 4,854 | Python | .py | 105 | 37.352381 | 113 | 0.633659 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,209 | limits.py | truenas_middleware/src/middlewared/middlewared/utils/limits.py | # This file provides constants and methods related to general middleware limits.
# Currently tests are provided in ./src/middlewared/middlewared/pytest/unit/utils/test_limits.py
import enum
from aiohttp.http_websocket import WSCloseCode
from truenas_api_client import json as ejson
# WARNING: below methods must _not... | 2,868 | Python | .py | 58 | 43.034483 | 96 | 0.730631 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,210 | prctl.py | truenas_middleware/src/middlewared/middlewared/utils/prctl.py | import contextlib
import ctypes
import enum
import signal
__all__ = ['set_name', 'set_pdeath_sig']
class Prctl(enum.IntEnum):
# from linux/prctl.h
SET_PDEATHSIG = 1
SET_NAME = 15
@contextlib.contextmanager
def load_libc():
libc = None
try:
libc = ctypes.CDLL('libc.so.6')
yield l... | 806 | Python | .py | 28 | 23.928571 | 81 | 0.664491 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,211 | lock.py | truenas_middleware/src/middlewared/middlewared/utils/lock.py | import asyncio
class SoftHardSemaphoreLimit(Exception):
pass
class SoftHardSemaphore(object):
def __init__(self, softlimit, hardlimit):
self.softlimit = softlimit
self.hardlimit = hardlimit
self.softsemaphore = asyncio.Semaphore(value=softlimit)
self.counter = 0
async ... | 625 | Python | .py | 17 | 29.411765 | 63 | 0.671667 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,212 | path.py | truenas_middleware/src/middlewared/middlewared/utils/path.py | # -*- coding=utf-8 -*-
import errno
import enum
import fcntl
import logging
import os
import stat
from contextlib import contextmanager
from pathlib import Path
logger = logging.getLogger(__name__)
__all__ = ["pathref_open", "pathref_reopen", "is_child", "is_child_realpath", "path_location", "strip_location_prefix"]... | 4,703 | Python | .py | 122 | 32.188525 | 119 | 0.654109 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,213 | size.py | truenas_middleware/src/middlewared/middlewared/utils/size.py | import humanfriendly
MB = 1048576
def format_size(size):
return humanfriendly.format_size(size, binary=True)
| 116 | Python | .py | 4 | 26.25 | 55 | 0.807339 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,214 | cron.py | truenas_middleware/src/middlewared/middlewared/utils/cron.py | # -*- coding=utf-8 -*-
import re
from croniter import croniter
CRON_FIELDS = ["minute", "hour", "dom", "month", "dow"]
def croniter_for_schedule(schedule, *args, **kwargs):
cron_expression = ''
for field in CRON_FIELDS:
value = schedule.get(field) or '*'
if '/' in value and not re.match(r'^(... | 526 | Python | .py | 12 | 38.333333 | 82 | 0.602362 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,215 | disk_stats.py | truenas_middleware/src/middlewared/middlewared/utils/disk_stats.py | import contextlib
import logging
import os
from .disks import get_disk_names, get_disks_with_identifiers
logger = logging.getLogger(__name__)
def get_disk_stats(disk_identifier_mapping: dict | None = None) -> dict[str, dict]:
disk_identifier_mapping = disk_identifier_mapping or get_disks_with_identifiers()
... | 1,977 | Python | .py | 39 | 36 | 115 | 0.540975 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,216 | plugins.py | truenas_middleware/src/middlewared/middlewared/utils/plugins.py | import functools
import importlib
import inspect
import itertools
import logging
import os
import sys
from middlewared.schema import Schemas
logger = logging.getLogger(__name__)
def load_modules(directory, base=None, depth=0):
directory = os.path.normpath(directory)
if base is None:
middlewared_root... | 5,165 | Python | .py | 114 | 34.298246 | 117 | 0.585293 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,217 | itertools.py | truenas_middleware/src/middlewared/middlewared/utils/itertools.py | import itertools
def grouper(iterable, n, *, incomplete='fill', fillvalue=None):
"Collect data into non-overlapping fixed-length chunks or blocks"
# grouper('ABCDEFG', 3, fillvalue='x') --> ABC DEF Gxx
# grouper('ABCDEFG', 3, incomplete='strict') --> ABC DEF ValueError
# grouper('ABCDEFG', 3, incomple... | 1,417 | Python | .py | 35 | 34.457143 | 74 | 0.661572 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,218 | interface.py | truenas_middleware/src/middlewared/middlewared/utils/interface.py | import contextlib
import os
import time
IFACE_LINK_STATE_MAX_WAIT: int = 60
RTF_GATEWAY: int = 0x0002
RTF_UP: int = 0x0001
def get_default_interface() -> str | None:
with contextlib.suppress(FileNotFoundError):
with open('/proc/net/route', 'r') as f:
for entry in filter(lambda i: len(i) == 1... | 1,286 | Python | .py | 29 | 36.344828 | 91 | 0.639647 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,219 | serial.py | truenas_middleware/src/middlewared/middlewared/utils/serial.py | import re
import os
import glob
import subprocess
RE_PORT_UART = re.compile(r'at\s*(\w*).*is a\s*(\w+)')
def serial_port_choices():
devices = []
for tty in map(lambda t: os.path.basename(t), glob.glob('/dev/ttyS*')):
serial_dev = {
'name': None,
'location': None,
'... | 1,590 | Python | .py | 44 | 26.772727 | 109 | 0.550715 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,220 | user_context.py | truenas_middleware/src/middlewared/middlewared/utils/user_context.py | import concurrent.futures
import functools
import logging
import os
import subprocess
from typing import Any, Callable, Optional
logger = logging.getLogger(__name__)
__all__ = ["run_command_with_user_context", "run_with_user_context", "set_user_context"]
def set_user_context(user_details: dict) -> None:
if os.... | 2,753 | Python | .py | 61 | 38.606557 | 127 | 0.648072 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,221 | tdb.py | truenas_middleware/src/middlewared/middlewared/utils/tdb.py | import os
import tdb
import enum
import json
from base64 import b64encode, b64decode
from collections import defaultdict, namedtuple
from collections.abc import Iterable
from contextlib import contextmanager
from dataclasses import dataclass
from middlewared.plugins.system_dataset.utils import SYSDATASET_PATH
from mid... | 10,621 | Python | .py | 291 | 26.594502 | 100 | 0.582708 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,222 | git.py | truenas_middleware/src/middlewared/middlewared/utils/git.py | import subprocess
import shutil
import textwrap
import typing
from middlewared.service import CallError
def clone_repository(
repository_uri: str, destination: str, branch: typing.Optional[str] = None, depth: typing.Optional[int] = None
) -> None:
shutil.rmtree(destination, ignore_errors=True)
args = []
... | 1,827 | Python | .py | 40 | 39.225 | 114 | 0.654474 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,223 | cgroups.py | truenas_middleware/src/middlewared/middlewared/utils/cgroups.py | # -*- coding=utf-8 -*-
def move_to_root_cgroups(pid):
with open(f"/proc/{pid}/cgroup") as f:
for line in f.readlines():
_, _, value = line.strip().split(":")
if value == "/system.slice/middlewared.service":
with open("/sys/fs/cgroup/cgroup.procs", "w") as f2:
... | 380 | Python | .py | 9 | 30.888889 | 68 | 0.497297 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,224 | vendor.py | truenas_middleware/src/middlewared/middlewared/utils/vendor.py | from enum import StrEnum
class Vendors(StrEnum):
"""The set of possible vendor names in /data/.vendor"""
TRUENAS_SCALE = "TrueNAS Scale"
HEXOS = "HexOS"
| 167 | Python | .py | 5 | 29.6 | 59 | 0.70625 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,225 | sid.py | truenas_middleware/src/middlewared/middlewared/utils/sid.py | import enum
from secrets import randbits
from middlewared.plugins.idmap_.idmap_constants import BASE_SYNTHETIC_DATASTORE_ID, IDType
DOM_SID_PREFIX = 'S-1-5-21-'
DOM_SID_SUBAUTHS = 3
MAX_VALUE_SUBAUTH = 2 ** 32
BASE_RID_USER = 20000
BASE_RID_GROUP = 200000
class DomainRid(enum.IntEnum):
""" Defined in MS-DTYP S... | 4,047 | Python | .py | 114 | 29.631579 | 90 | 0.650692 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,226 | auth.py | truenas_middleware/src/middlewared/middlewared/utils/auth.py | import enum
from dataclasses import dataclass
LEGACY_API_KEY_USERNAME = 'LEGACY_API_KEY'
MAX_OTP_ATTEMPTS = 3
class AuthMech(enum.StrEnum):
API_KEY_PLAIN = 'API_KEY_PLAIN'
PASSWORD_PLAIN = 'PASSWORD_PLAIN'
TOKEN_PLAIN = 'TOKEN_PLAIN'
OTP_TOKEN = 'OTP_TOKEN'
class AuthResp(enum.StrEnum):
SUCCESS... | 3,092 | Python | .py | 74 | 38.702703 | 97 | 0.773 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,227 | zfs.py | truenas_middleware/src/middlewared/middlewared/utils/zfs.py | import os
def query_imported_fast_impl(name_filters=None):
# the equivalent of running `zpool list -H -o guid,name` from cli
# name_filters will be a list of pool names
out = dict()
name_filters = name_filters or []
with os.scandir('/proc/spl/kstat/zfs') as it:
for entry in filter(lambda e... | 1,081 | Python | .py | 28 | 31.892857 | 94 | 0.635407 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,228 | __init__.py | truenas_middleware/src/middlewared/middlewared/utils/__init__.py | import asyncio
import errno
import functools
import logging
import operator
import re
import subprocess
import time
import json
from collections import namedtuple
from dataclasses import dataclass
from datetime import datetime
from middlewared.service_exception import MatchNotFound
from .lang import undefined
from .pr... | 19,453 | Python | .py | 525 | 26.607619 | 121 | 0.558273 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,229 | mdns.py | truenas_middleware/src/middlewared/middlewared/utils/mdns.py | # NOTE: tests are provided in src/middlewared/middlewared/pytest/unit/utils/test_mdns.py
# Any updates to this file should have corresponding updates to tests
import enum
import socket
import xml.etree.ElementTree as xml
from io import StringIO
from . import filter_list
AVAHI_SERVICE_PATH = '/etc/avahi/services'
SV... | 5,973 | Python | .py | 149 | 32.194631 | 100 | 0.635782 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,230 | gpu.py | truenas_middleware/src/middlewared/middlewared/utils/gpu.py | import collections
import os
import re
import subprocess
from typing import TextIO
import pyudev
from middlewared.service_exception import CallError
from .iommu import get_iommu_groups_info
from .pci import SENSITIVE_PCI_DEVICE_TYPES
RE_PCI_ADDR = re.compile(r'(?P<domain>.*):(?P<bus>.*):(?P<slot>.*)\.')
def parse... | 5,419 | Python | .py | 116 | 36.086207 | 113 | 0.581091 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,231 | shutil.py | truenas_middleware/src/middlewared/middlewared/utils/shutil.py | # -*- coding=utf-8 -*-
import subprocess
__all__ = ["rmtree_one_filesystem"]
def rmtree_one_filesystem(path):
try:
subprocess.run(['rm', '--one-file-system', '-rf', path], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
encoding="utf-8", errors="ignore", check=True)
except subp... | 393 | Python | .py | 9 | 37.111111 | 112 | 0.645669 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,232 | functools_.py | truenas_middleware/src/middlewared/middlewared/utils/functools_.py | import asyncio
import copy
import functools
from middlewared.utils.lang import undefined
def cache(func):
value = undefined
if asyncio.iscoroutinefunction(func):
@functools.wraps(func)
async def wrapped(self):
nonlocal value
if value == undefined:
val... | 610 | Python | .py | 21 | 20.380952 | 44 | 0.613793 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,233 | scsi_generic.py | truenas_middleware/src/middlewared/middlewared/utils/scsi_generic.py | import ctypes
import fcntl
import os
# SG_IO ioctl command constant
SG_IO = 0x2285
# SCSI sense buffer size constant
SG_MAX_SENSE = 32
# Other necessary constants
SG_DXFER_FROM_DEV = -3
SG_DXFER_NONE = 0
SG_FLAG_DIRECT_IO = 1
SG_INFO_OK = 0
# SCSI Enclosure Services command
SES_RECEIVE_DIAGNOSTIC = 0x1C
SES_ENCLOSU... | 3,660 | Python | .py | 94 | 32.574468 | 119 | 0.614777 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,234 | contextlib.py | truenas_middleware/src/middlewared/middlewared/utils/contextlib.py | # -*- coding=utf-8 -*-
import contextlib
import logging
logger = logging.getLogger(__name__)
__all__ = ["asyncnullcontext"]
@contextlib.asynccontextmanager
async def asyncnullcontext(enter_result=None):
yield enter_result
| 230 | Python | .py | 8 | 26.75 | 46 | 0.770642 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,235 | disk_temperatures.py | truenas_middleware/src/middlewared/middlewared/utils/disk_temperatures.py | from dataclasses import dataclass
from typing import Dict, Optional
from middlewared.utils.db import query_table
DISKS_TO_IGNORE: tuple = ('sr', 'md', 'dm-', 'loop', 'zd')
NVME_TYPE: str = 'nvme'
HDD_TYPE: str = 'hdd'
@dataclass
class Disk:
id: str
identifier: str
name: str
serial: str | None = Non... | 1,470 | Python | .py | 36 | 34.583333 | 86 | 0.643209 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,236 | iommu.py | truenas_middleware/src/middlewared/middlewared/utils/iommu.py | import collections
import contextlib
import os.path
import pathlib
import re
from .pci import get_pci_device_class, SENSITIVE_PCI_DEVICE_TYPES
RE_DEVICE_NAME = re.compile(r'(\w+):(\w+):(\w+).(\w+)')
def get_iommu_groups_info(get_critical_info: bool = False) -> dict[str, dict]:
addresses = collections.defaultdi... | 1,377 | Python | .py | 33 | 30.939394 | 108 | 0.553478 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,237 | type.py | truenas_middleware/src/middlewared/middlewared/utils/type.py | def copy_function_metadata(f, nf):
nf.__name__ = f.__name__
nf.__doc__ = f.__doc__
# Copy private attrs to new function so decorators can work on top of it
# e.g. _pass_app
for i in dir(f):
if i.startswith('__'):
continue
if i.startswith('_'):
setattr(nf, i, g... | 549 | Python | .py | 14 | 31.214286 | 110 | 0.543925 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,238 | socket.py | truenas_middleware/src/middlewared/middlewared/utils/socket.py | import socket
def is_socket_available(socket_path: str) -> bool:
"""Check if a Unix socket is available."""
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
s.connect(socket_path)
return True
except (socket.error, FileNotFoundError):
return False
finally:
... | 330 | Python | .py | 11 | 24.090909 | 57 | 0.656151 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,239 | debug.py | truenas_middleware/src/middlewared/middlewared/utils/debug.py | import inspect
import linecache
import sys
import traceback
import types
def get_frame_details(frame, logger):
if not isinstance(frame, types.FrameType):
return {}
cur_frame = {
'filename': frame.f_code.co_filename,
'lineno': frame.f_lineno,
'method': frame.f_code.co_name,
... | 1,743 | Python | .py | 51 | 26.411765 | 87 | 0.622394 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,240 | allowlist.py | truenas_middleware/src/middlewared/middlewared/utils/allowlist.py | import fnmatch
import re
from middlewared.api.current import HttpVerb
ALLOW_LIST_FULL_ADMIN = {'method': '*', 'resource': '*'}
class Allowlist:
def __init__(self, allowlist: list[dict]):
self.exact: dict[HttpVerb, set[str]] = {}
self.full_admin = ALLOW_LIST_FULL_ADMIN in allowlist
self.p... | 1,259 | Python | .py | 27 | 36.888889 | 100 | 0.624183 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,241 | privilege.py | truenas_middleware/src/middlewared/middlewared/utils/privilege.py | import enum
from middlewared.auth import TrueNasNodeSessionManagerCredentials
from middlewared.role import ROLES
class LocalAdminGroups(enum.IntEnum):
BUILTIN_ADMINISTRATORS = 544
def privilege_has_webui_access(privilege: dict) -> bool:
"""
This method determines whether the specified privilege is suffi... | 3,238 | Python | .py | 80 | 34.9 | 92 | 0.721547 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,242 | shell.py | truenas_middleware/src/middlewared/middlewared/utils/shell.py | # -*- coding=utf-8 -*-
import shlex
def join_commandline(args):
return " ".join(map(shlex.quote, args))
| 110 | Python | .py | 4 | 25 | 43 | 0.673077 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,243 | user_api_key.py | truenas_middleware/src/middlewared/middlewared/utils/user_api_key.py | import os
from base64 import b64encode
from dataclasses import dataclass
from struct import pack
from uuid import uuid4
from .tdb import (
TDBDataType,
TDBHandle,
TDBOptions,
TDBPathType,
)
PAM_TDB_DIR = '/var/run/pam_tdb'
PAM_TDB_FILE = os.path.join(PAM_TDB_DIR, 'pam_tdb.tdb')
PAM_TDB_DIR_MODE = 0o7... | 3,224 | Python | .py | 86 | 32.081395 | 80 | 0.690132 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,244 | threading.py | truenas_middleware/src/middlewared/middlewared/utils/threading.py | from concurrent.futures import Executor, Future, ThreadPoolExecutor
from itertools import count
import logging
import os
import threading
from .prctl import set_name
logger = logging.getLogger(__name__)
counter = count(1)
__all__ = ["set_thread_name", "start_daemon_thread", "IoThreadPoolExecutor", "io_thread_pool_exe... | 1,628 | Python | .py | 40 | 34.525 | 115 | 0.664971 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,245 | rootfs.py | truenas_middleware/src/middlewared/middlewared/utils/rootfs.py | from dataclasses import dataclass
import contextlib
from functools import cached_property
import json
import os
import subprocess
from middlewared.utils.filesystem import stat_x
from middlewared.utils.mount import getmntinfo
@dataclass
class ReadonlyState:
initial: bool
current: bool
@dataclass
class Datas... | 3,873 | Python | .py | 99 | 28.69697 | 107 | 0.571086 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,246 | os.py | truenas_middleware/src/middlewared/middlewared/utils/os.py | import logging
import os
import resource
logger = logging.getLogger(__name__)
__all__ = ['close_fds']
def close_fds(low_fd, max_fd=None):
if max_fd is None:
max_fd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
# Avoid infinity as thats not practical
if max_fd == resource.RLIM_INFINITY:... | 382 | Python | .py | 12 | 26.75 | 62 | 0.665753 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,247 | mount.py | truenas_middleware/src/middlewared/middlewared/utils/mount.py | import os
import logging
logger = logging.getLogger(__name__)
__all__ = ["getmntinfo", "getmnttree"]
def __mntent_dict(line):
mnt_id, parent_id, maj_min, root, mp, opts, extra = line.split(" ", 6)
fstype, mnt_src, super_opts = extra.split(' - ')[1].split()
major, minor = maj_min.split(':')
devid = ... | 4,254 | Python | .py | 103 | 33.660194 | 86 | 0.614692 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,248 | syslog.py | truenas_middleware/src/middlewared/middlewared/utils/syslog.py | import os
import syslog
import uuid
from middlewared.utils.time_utils import utc_now
def syslog_message(message):
data = f'<{syslog.LOG_USER | syslog.LOG_INFO}>'
data += f'{utc_now().strftime("%b %d %H:%M:%S")} '
data += 'TNAUDIT_MIDDLEWARE: '
data += message
data = data.encode('ascii', 'igno... | 342 | Python | .py | 11 | 27.181818 | 54 | 0.668731 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,249 | mako.py | truenas_middleware/src/middlewared/middlewared/utils/mako.py | # -*- coding=utf-8 -*-
import logging
import os
from mako.lookup import TemplateLookup
logger = logging.getLogger(__name__)
__all__ = ["get_template"]
lookup = TemplateLookup(
directories=[os.path.dirname(os.path.dirname(__file__))],
module_directory="/run/mako",
imports=["from middlewared.utils.mako_fi... | 423 | Python | .py | 13 | 29.846154 | 81 | 0.730198 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,250 | audit.py | truenas_middleware/src/middlewared/middlewared/utils/audit.py | from middlewared.auth import (
TokenSessionManagerCredentials,
TrueNasNodeSessionManagerCredentials
)
# Special values start with dot to ensure they cannot collide with local usernames
# created via APIs
API_KEY_PREFIX = '.API_KEY:'
NODE_SESSION = '.TRUENAS_NODE'
UNAUTHENTICATED = '.UNAUTHENTICATED'
UNKNOWN_SE... | 856 | Python | .py | 22 | 34.5 | 82 | 0.762999 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,251 | string.py | truenas_middleware/src/middlewared/middlewared/utils/string.py | def make_sentence(s):
if not s:
return s
if any(s.endswith(c) for c in (".", "!", "?")):
return s
return f"{s}."
| 143 | Python | .py | 6 | 17.833333 | 51 | 0.481481 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,252 | crypto.py | truenas_middleware/src/middlewared/middlewared/utils/crypto.py | from base64 import b64encode
from hashlib import pbkdf2_hmac
from secrets import choice, compare_digest, token_urlsafe, token_hex
from string import ascii_letters, digits, punctuation
from cryptit import cryptit
from samba.crypto import md4_hash_blob
def generate_string(string_size=8, punctuation_chars=False, extra... | 2,890 | Python | .py | 68 | 37.705882 | 93 | 0.716476 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,253 | mako_filters.py | truenas_middleware/src/middlewared/middlewared/utils/mako_filters.py | import json as _json
import textwrap
from markdown import markdown as _markdown
from markdown.extensions.codehilite import CodeHiliteExtension
from markdown.extensions.tables import TableExtension
def indent(value):
return textwrap.indent(value, " " * 8)
def json(value):
return _json.dumps(value, indent=Tr... | 522 | Python | .py | 14 | 31.214286 | 76 | 0.728543 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,254 | cpu.py | truenas_middleware/src/middlewared/middlewared/utils/cpu.py | import functools
import psutil
import re
from collections import defaultdict
AMD_PREFER_TDIE = (
# https://github.com/torvalds/linux/blob/master/drivers/hwmon/k10temp.c#L121
# static const struct tctl_offset tctl_offset_table[] = {
'AMD Ryzen 5 1600X',
'AMD Ryzen 7 1700X',
'AMD Ryzen 7 1800X',
... | 2,888 | Python | .py | 70 | 34.585714 | 103 | 0.623529 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,255 | disks.py | truenas_middleware/src/middlewared/middlewared/utils/disks.py | import os
import re
import pyudev
DISKS_TO_IGNORE = ('sr', 'md', 'dm-', 'loop', 'zd')
RE_IS_PART = re.compile(r'p\d{1,3}$')
# sda, vda, nvme0n1 but not sda1/vda1/nvme0n1p1
VALID_WHOLE_DISK = re.compile(r'^sd[a-z]+$|^vd[a-z]+$|^nvme\d+n\d+$')
def safe_retrieval(prop, key, default, as_int=False):
value = prop.ge... | 4,510 | Python | .py | 104 | 34.038462 | 117 | 0.594434 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,256 | asyncio_.py | truenas_middleware/src/middlewared/middlewared/utils/asyncio_.py | import asyncio
async def asyncio_map(func, arguments, limit=None, *, semaphore=None):
if limit is not None and semaphore is not None:
raise ValueError("`limit` and `semaphore` can not be specified simultaneously")
if limit is not None or semaphore is not None:
if semaphore is None:
... | 590 | Python | .py | 13 | 37.153846 | 87 | 0.674256 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,257 | procfs.py | truenas_middleware/src/middlewared/middlewared/utils/network_/procfs.py | from codecs import decode
from dataclasses import dataclass
from socket import inet_ntop, AF_INET, AF_INET6
from struct import pack, unpack
__all__ = ('read_proc_net',)
@dataclass(slots=True, frozen=True)
class InetInfoEntry:
local_ip: str
local_port: int
remote_ip: str
remote_port: int
protocol:... | 2,528 | Python | .py | 67 | 29.880597 | 92 | 0.602449 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,258 | attrs.py | truenas_middleware/src/middlewared/middlewared/utils/filesystem/attrs.py | # Get and set ZFS file attributes
#
# ZFS supports various file-level attributes that are not accessible
# through normal linux filesystem APIs (for example DOS-related attributes).
#
# These utility functions allow getting and setting them
#
# NOTE: tests for parsers are in src/middlewared/middlewared/pytest/unit/util... | 5,122 | Python | .py | 138 | 31.586957 | 102 | 0.690828 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,259 | constants.py | truenas_middleware/src/middlewared/middlewared/utils/filesystem/constants.py | import enum
AT_FDCWD = -100 # special fd value meaning current working directory
class FileType(enum.Enum):
DIRECTORY = enum.auto()
FILE = enum.auto()
SYMLINK = enum.auto()
OTHER = enum.auto()
class ZFSCTL(enum.IntEnum):
# from include/os/linux/zfs/sys/zfs_ctldir.h in ZFS repo
INO_ROOT = 0... | 375 | Python | .py | 11 | 30.090909 | 69 | 0.724234 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,260 | utils.py | truenas_middleware/src/middlewared/middlewared/utils/filesystem/utils.py | # This file provides various utilities that don't fit cleanly
# into specific categories of filesystem areas.
#
# timespec_convert_float() has test coverage via stat_x util tests
# timespec_convert_int() has test coverage via copytree util tests
# path_in_ctldir() has test coverage via api tests for filesystem.stat
# a... | 1,682 | Python | .py | 42 | 34.785714 | 70 | 0.704113 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,261 | copy.py | truenas_middleware/src/middlewared/middlewared/utils/filesystem/copy.py | # Various utilities related to copying / cloning files and file tree
# test coverage provided by pytest/unit/utils/test_copytree.py
import enum
import os
from dataclasses import dataclass
from errno import EXDEV
from middlewared.job import Job
from os import open as posix_open
from os import (
close,
copy_fil... | 20,873 | Python | .py | 513 | 30.775828 | 104 | 0.616153 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,262 | stat_x.py | truenas_middleware/src/middlewared/middlewared/utils/filesystem/stat_x.py | # This utility provides a basic wrapper for statx(2).
#
# We need statx(2) for gathering birth time, mount id, and
# file attributes for the middleware filesystem plugin
#
# NOTE: tests for these utils are in src/middlewared/middlewared/pytest/unit/utils/test_statx.py
import os
import ctypes
import stat as statlib
fro... | 5,766 | Python | .py | 163 | 29.03681 | 96 | 0.638474 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,263 | directory.py | truenas_middleware/src/middlewared/middlewared/utils/filesystem/directory.py | # This provides a middleware backend oriented directory generator that
# is primarily consumed by filesystem.listdir, but may be used in other
# places. It is primarily a thin wrapper around os.scandir, but also
# provides statx output and other optional file information in the
# returned dictionaries.
#
# NOTE: tests ... | 10,665 | Python | .py | 254 | 32.846457 | 100 | 0.615466 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,264 | acl.py | truenas_middleware/src/middlewared/middlewared/utils/filesystem/acl.py | import enum
class ACLXattr(enum.Enum):
POSIX_ACCESS = "system.posix_acl_access"
POSIX_DEFAULT = "system.posix_acl_default"
ZFS_NATIVE = "system.nfs4_acl_xdr"
ACL_XATTRS = set([xat.value for xat in ACLXattr])
# ACCESS_ACL_XATTRS is set of ACLs that control access to the file itself.
ACCESS_ACL_XATTRS = ... | 736 | Python | .py | 16 | 42.0625 | 81 | 0.737728 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,265 | crud.py | truenas_middleware/src/middlewared/middlewared/utils/service/crud.py | __all__ = ['real_crud_method']
def real_crud_method(method):
if method.__name__ in ['create', 'update', 'delete'] and hasattr(method, '__self__'):
child_method = getattr(method.__self__, f'do_{method.__name__}', None)
if child_method is not None:
return child_method
| 301 | Python | .py | 6 | 43.5 | 89 | 0.600683 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,266 | __init__.py | truenas_middleware/src/middlewared/middlewared/utils/service/__init__.py | # -*- coding=utf-8 -*-
import logging
logger = logging.getLogger(__name__)
__all__ = []
| 90 | Python | .py | 4 | 21 | 36 | 0.619048 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,267 | call.py | truenas_middleware/src/middlewared/middlewared/utils/service/call.py | # -*- coding=utf-8 -*-
import errno
import logging
from middlewared.service_exception import CallError
logger = logging.getLogger(__name__)
__all__ = ["MethodNotFoundError", "ServiceCallMixin"]
class MethodNotFoundError(CallError):
def __init__(self, method_name, service):
super().__init__(f'Method {me... | 958 | Python | .py | 23 | 34.434783 | 97 | 0.670996 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,268 | task_state.py | truenas_middleware/src/middlewared/middlewared/utils/service/task_state.py | from middlewared.service import private
class TaskStateMixin:
task_state_methods = NotImplemented
@private
async def get_task_state_context(self):
jobs = {}
for j in await self.middleware.call(
"core.get_jobs",
[("OR", [("method", "=", method) for method in self.ta... | 1,690 | Python | .py | 39 | 30.384615 | 106 | 0.533211 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,269 | pwd.py | truenas_middleware/src/middlewared/middlewared/utils/nss/pwd.py | import ctypes
import errno
from collections import namedtuple
from .nss_common import get_nss_func, NssError, NssModule, NssOperation, NssReturnCode
PASSWD_INIT_BUFLEN = 1024
class Passwd(ctypes.Structure):
_fields_ = [
("pw_name", ctypes.c_char_p),
("pw_passwd", ctypes.c_char_p),
("pw_u... | 10,119 | Python | .py | 263 | 29.391635 | 93 | 0.593187 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,270 | nss_common.py | truenas_middleware/src/middlewared/middlewared/utils/nss/nss_common.py | import enum
import ctypes
import os
NSS_MODULES_DIR = '/usr/lib/x86_64-linux-gnu'
FILES_NSS_PATH = os.path.join(NSS_MODULES_DIR, 'libnss_files.so.2')
SSS_NSS_PATH = os.path.join(NSS_MODULES_DIR, 'libnss_sss.so.2')
WINBIND_NSS_PATH = os.path.join(NSS_MODULES_DIR, 'libnss_winbind.so.2')
class NssReturnCode(enum.IntEnu... | 1,737 | Python | .py | 48 | 31.0625 | 97 | 0.660896 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,271 | grp.py | truenas_middleware/src/middlewared/middlewared/utils/nss/grp.py | import ctypes
import errno
from collections import namedtuple
from .nss_common import get_nss_func, NssError, NssModule, NssOperation, NssReturnCode
GROUP_INIT_BUFLEN = 1024
class Group(ctypes.Structure):
_fields_ = [
("gr_name", ctypes.c_char_p),
("gr_passwd", ctypes.c_char_p),
("gr_gid... | 9,883 | Python | .py | 257 | 29.2607 | 86 | 0.592581 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,272 | cache.py | truenas_middleware/src/middlewared/middlewared/utils/rate_limit/cache.py | from asyncio import sleep
from dataclasses import dataclass
from random import uniform
from time import monotonic
from typing import TypedDict
from middlewared.utils.origin import ConnectionOrigin
__all__ = ['RateLimitCache']
@dataclass(frozen=True)
class RateLimitConfig:
"""The maximum number of calls per uniq... | 4,041 | Python | .py | 87 | 38.310345 | 95 | 0.650648 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,273 | ipa.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/ipa.py | import os
from configparser import RawConfigParser
from io import StringIO
from tempfile import NamedTemporaryFile
from .ipa_constants import IPAPath
def generate_ipa_default_config(
host: str,
basedn: str,
domain: str,
realm: str,
server: str
) -> bytes:
"""
Return bytes of freeipa confi... | 2,137 | Python | .py | 65 | 27.630769 | 77 | 0.674611 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,274 | constants.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/constants.py | import enum
class DSStatus(enum.Enum):
DISABLED = enum.auto()
FAULTED = enum.auto()
LEAVING = enum.auto()
JOINING = enum.auto()
HEALTHY = enum.auto()
class DSType(enum.Enum):
AD = 'ACTIVEDIRECTORY'
IPA = 'IPA'
LDAP = 'LDAP'
@property
def etc_files(self):
match self:
... | 1,281 | Python | .py | 43 | 23.418605 | 71 | 0.587899 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,275 | ldap_utils.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/ldap_utils.py | from urllib.parse import urlparse
def hostnames_to_uris(hostname_list: list, use_ldaps: bool) -> list:
scheme = 'ldaps' if use_ldaps else 'ldap'
out = []
for host in set(hostname_list):
parsed = urlparse(f'{scheme}://{host}')
try:
port = parsed.port
host = parsed.h... | 515 | Python | .py | 15 | 26 | 68 | 0.582996 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,276 | krb5.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/krb5.py | # This is a collection of utilities related to kerberos tickets
# and keytabs.
#
# Tests that do not require access to an actual KDC are provided
# in src/middlewared/middlewared/pytest/unit/utils/test_krb5.py
#
# Tests that require access to a KDC are provided as part of API
# test suite.
import errno
import gssapi
i... | 12,912 | Python | .py | 355 | 28.388732 | 89 | 0.601491 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,277 | ad_constants.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/ad_constants.py | import enum
MAX_SERVER_TIME_OFFSET = 180
MAX_KERBEROS_START_TRIES = 60
DEFAULT_SITE_NAME = 'Default-First-Site-Name'
MACHINE_ACCOUNT_KT_NAME = 'AD_MACHINE_ACCOUNT'
class ADUserAccountControl(enum.IntFlag):
"""
see MS-ADTS section 2.2.16
This is currently used to parse machine account UAC flags
In t... | 3,244 | Python | .py | 65 | 43.461538 | 111 | 0.705845 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,278 | krb5_constants.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/krb5_constants.py | import enum
from middlewared.utils import MIDDLEWARE_RUN_DIR
KRB_TKT_CHECK_INTERVAL = 1800
PERSISTENT_KEYRING_PREFIX = 'KEYRING:persistent:'
class KRB_Keytab(enum.Enum):
SYSTEM = '/etc/krb5.keytab'
class krb5ccache(enum.Enum):
SYSTEM = f'{PERSISTENT_KEYRING_PREFIX}0'
TEMP = f'{MIDDLEWARE_RUN_DIR}/krb5... | 3,427 | Python | .py | 84 | 35.892857 | 77 | 0.66145 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,279 | ipa_constants.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/ipa_constants.py | import enum
from dataclasses import dataclass
class IpaConfigName(enum.StrEnum):
""" Names for IPA-related entries we create in our databases """
IPA_CACERT = 'IPA_DOMAIN_CACERT'
IPA_HOST_KEYTAB = 'IPA_MACHINE_ACCOUNT'
IPA_SMB_KEYTAB = 'IPA_SMB_KEYTAB'
IPA_NFS_KEYTAB = 'IPA_NFS_KEYTAB'
class IPA... | 955 | Python | .py | 30 | 27.166667 | 68 | 0.67541 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,280 | health.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/health.py | import enum
from .constants import DSStatus, DSType
from threading import Lock
class KRB5HealthCheckFailReason(enum.IntEnum):
KRB5_NO_CONFIG = enum.auto()
KRB5_CONFIG_PERM = enum.auto()
KRB5_NO_CCACHE = enum.auto()
KRB5_CCACHE_PERM = enum.auto()
KRB5_NO_KEYTAB = enum.auto()
KRB5_KEYTAB_PERM =... | 3,180 | Python | .py | 84 | 31.22619 | 91 | 0.67189 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,281 | ipactl_constants.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/ipactl_constants.py | # Shared constants between ipa_ctl script and middleware utils
import enum
class IpaOperation(enum.Enum):
JOIN = enum.auto()
LEAVE = enum.auto()
SET_NFS_PRINCIPAL = enum.auto()
DEL_NFS_PRINCIPAL = enum.auto()
SET_SMB_PRINCIPAL = enum.auto()
DEL_SMB_PRINCIPAL = enum.auto()
SMB_DOMAIN_INFO ... | 533 | Python | .py | 19 | 23.631579 | 62 | 0.671906 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,282 | ad.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/ad.py | import errno
import json
import subprocess
from .ad_constants import (
ADUserAccountControl,
ADEncryptionTypes
)
from middlewared.plugins.smb_.constants import SMBCmd
from middlewared.service_exception import CallError
def _normalize_dict(dict_in) -> None:
"""
normalizes dictionary keys to be lower-c... | 3,720 | Python | .py | 103 | 28.728155 | 116 | 0.631315 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,283 | krb5_error.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/krb5_error.py | from enum import IntEnum
class KRB5ErrCode(IntEnum):
KRB5KDC_ERR_NONE = 0 # No error
KRB5KDC_ERR_NAME_EXP = 1 # Client's entry in database has expired
KRB5KDC_ERR_SERVICE_EXP = 2 # Server's entry in database has expired
KRB5KDC_ERR_BAD_PVNO = 3 # Requested protocol version not supported
KRB5KD... | 12,352 | Python | .py | 188 | 60.329787 | 116 | 0.726271 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,284 | krb5_conf.py | truenas_middleware/src/middlewared/middlewared/utils/directoryservices/krb5_conf.py | # This is a collection of utilities related to kerberos tickets
# and keytabs.
#
# Tests that do not require access to an actual KDC are provided
# in src/middlewared/middlewared/pytest/unit/utils/test_krb5.py
#
# Tests that require access to a KDC are provided as part of API
# test suite.
import logging
import os
fr... | 12,608 | Python | .py | 302 | 31.980132 | 105 | 0.603025 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,285 | 0003_iscsi_vendor.py | truenas_middleware/src/middlewared/middlewared/migration/0003_iscsi_vendor.py | async def migrate(middleware):
extents = await middleware.call(
'iscsi.extent.query', [['vendor', '=', None]], {'select': ['id', 'vendor']}
)
for extent in extents:
await middleware.call(
'datastore.update',
'services.iscsitargetextent',
extent['id'], {
... | 478 | Python | .py | 14 | 25.071429 | 83 | 0.557235 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,286 | 0002_shell_linux.py | truenas_middleware/src/middlewared/middlewared/migration/0002_shell_linux.py | import os
nologin = "/usr/sbin/nologin"
def is_valid_shell(shell):
return os.path.exists(shell) and os.access(shell, os.X_OK)
def migrate(middleware):
updated = False
for user in middleware.call_sync("datastore.query", "account.bsdusers", [], {"prefix": "bsdusr_"}):
if not user["shell"] or is_v... | 976 | Python | .py | 22 | 35.727273 | 114 | 0.593023 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,287 | 0006_system_cert.py | truenas_middleware/src/middlewared/middlewared/migration/0006_system_cert.py | async def migrate(middleware):
# This is required because earlier middleware was running considering openssl security level to be 1
# but with moving to debian, the default now is 2 which enforces security standards. It means that potentially
# user might have configured cert for system which might not comp... | 772 | Python | .py | 11 | 64.454545 | 114 | 0.749014 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,288 | 0008_default_keymap.py | truenas_middleware/src/middlewared/middlewared/migration/0008_default_keymap.py | async def migrate(middleware):
config = await middleware.call('system.general.config')
if config['kbdmap'] not in await middleware.call('system.general.kbdmap_choices'):
await middleware.call(
'datastore.update',
'system.settings',
config['id'],
{'stg_kbdm... | 404 | Python | .py | 10 | 31.4 | 86 | 0.619289 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,289 | 0009_system_global_id.py | truenas_middleware/src/middlewared/middlewared/migration/0009_system_global_id.py | import uuid
async def migrate(middleware):
await middleware.call(
'datastore.insert',
'system.globalid', {
'system_uuid': str(uuid.uuid4())
}
)
| 190 | Python | .py | 8 | 17 | 44 | 0.583333 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,290 | 0010_nvram_attr_vms.py | truenas_middleware/src/middlewared/middlewared/migration/0010_nvram_attr_vms.py | import os
import shutil
from middlewared.plugins.vm.utils import SYSTEM_NVRAM_FOLDER_PATH, get_vm_nvram_file_name
DEFAULT_NVRAM_FOLDER_PATH = '/var/lib/libvirt/qemu/nvram'
LIBVIRT_QEMU_UID = 64055
LIBVIRT_QEMU_GID = 64055
def migrate(middleware):
os.makedirs(SYSTEM_NVRAM_FOLDER_PATH, exist_ok=True)
os.chow... | 1,427 | Python | .py | 29 | 42.931034 | 118 | 0.683225 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,291 | 0005_tunables_linux.py | truenas_middleware/src/middlewared/middlewared/migration/0005_tunables_linux.py | async def migrate(middleware):
await middleware.call(
'datastore.delete',
'system.tunable', [
['id', 'in', [d['id'] for d in await middleware.call('tunable.query', [['type', 'in', ['RC', 'LOADER']]])]]
]
)
| 250 | Python | .py | 7 | 28.428571 | 119 | 0.534979 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,292 | 0004_ntp_default_servers_linux.py | truenas_middleware/src/middlewared/middlewared/migration/0004_ntp_default_servers_linux.py | async def migrate(middleware):
servers = await middleware.call(
'datastore.query', 'system.ntpserver', [['ntp_address', 'in', [f'{i}.freebsd.pool.ntp.org' for i in range(3)]]]
)
for server in servers:
await middleware.call(
'datastore.update',
'system.ntpserver',
... | 524 | Python | .py | 14 | 28.357143 | 119 | 0.569745 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,293 | 0011_catalog_community_train.py | truenas_middleware/src/middlewared/middlewared/migration/0011_catalog_community_train.py | from middlewared.plugins.catalog.utils import COMMUNITY_TRAIN, OFFICIAL_LABEL
async def migrate(middleware):
config = await middleware.call('catalog.config')
if COMMUNITY_TRAIN not in config['preferred_trains']:
await middleware.call(
'datastore.update', 'services.catalog', OFFICIAL_LABEL,... | 497 | Python | .py | 10 | 41.7 | 83 | 0.68866 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,294 | 0001_cloudsync_sftp_private_key_file.py | truenas_middleware/src/middlewared/middlewared/migration/0001_cloudsync_sftp_private_key_file.py | # -*- coding=utf-8 -*-
import os
def migrate(middleware):
for credential in middleware.call_sync("cloudsync.credentials.query", [["provider", "=", "SFTP"]]):
if "key_file" in credential["attributes"] and os.path.exists(credential["attributes"]["key_file"]):
middleware.logger.info("Migrating SF... | 1,606 | Python | .py | 28 | 39.5 | 113 | 0.514631 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,295 | rdma.py | truenas_middleware/src/middlewared/middlewared/api/v25_04_0/rdma.py | from middlewared.api.base import BaseModel, single_argument_result
from typing import Literal
__all__ = [
"RdmaLinkConfigArgs", "RdmaLinkConfigResult",
"RdmaCardConfigArgs", "RdmaCardConfigResult",
"RdmaCapableServicesArgs", "RdmaCapableServicesResult"
]
class RdmaLinkConfigArgs(BaseModel):
all: bool... | 799 | Python | .py | 26 | 27 | 66 | 0.788918 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,296 | acme_protocol.py | truenas_middleware/src/middlewared/middlewared/api/v25_04_0/acme_protocol.py | from pydantic import Field, Secret
from middlewared.api.base import BaseModel, Excluded, excluded_field, single_argument_args, ForUpdateMetaclass
__all__ = [
'ACMERegistrationCreateArgs', 'ACMERegistrationCreateResult', 'DNSAuthenticatorUpdateArgs',
'DNSAuthenticatorUpdateResult', 'DNSAuthenticatorCreateArgs... | 2,484 | Python | .py | 62 | 35.951613 | 110 | 0.777404 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,297 | user.py | truenas_middleware/src/middlewared/middlewared/api/v25_04_0/user.py | from typing import Literal
from annotated_types import Ge, Le
from pydantic import EmailStr, Field, Secret
from typing_extensions import Annotated
from middlewared.api.base import (BaseModel, Excluded, excluded_field, ForUpdateMetaclass, LocalUsername, RemoteUsername,
LocalUID, LongS... | 7,708 | Python | .py | 196 | 33.892857 | 121 | 0.728178 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,298 | alertservice.py | truenas_middleware/src/middlewared/middlewared/api/v25_04_0/alertservice.py | from middlewared.api.base import BaseModel, NonEmptyString
__all__ = [
'AlertServiceEntry', 'AlertServiceCreateArgs', 'AlertServiceUpdateArgs', 'AlertServiceDeleteArgs',
'AlertServiceTestArgs', 'AlertServiceCreateResult', 'AlertServiceUpdateResult', 'AlertServiceDeleteResult',
'AlertServiceTestResult',
]
... | 1,218 | Python | .py | 34 | 31.823529 | 111 | 0.772021 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |
24,299 | iscsi_auth.py | truenas_middleware/src/middlewared/middlewared/api/v25_04_0/iscsi_auth.py | from typing import Literal
from pydantic import Secret
from middlewared.api.base import BaseModel, Excluded, excluded_field, ForUpdateMetaclass
__all__ = [
"IscsiAuthEntry",
"IscsiAuthCreateArgs",
"IscsiAuthCreateResult",
"IscsiAuthUpdateArgs",
"IscsiAuthUpdateResult",
"IscsiAuthDeleteArgs",
... | 1,065 | Python | .py | 36 | 25.555556 | 88 | 0.776786 | truenas/middleware | 2,277 | 481 | 13 | LGPL-3.0 | 9/5/2024, 5:13:34 PM (Europe/Amsterdam) |