Skip to content
Draft
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
Empty file added labgrid/remote/auth/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions labgrid/remote/auth/capability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from enum import StrEnum, auto


class Capability(StrEnum):
client_stream = auto()
exporter_stream = auto()
add_place = auto()
delete_place = auto()
get_places = auto()
add_place_alias = auto()
delete_place_alias = auto()
set_place_tags = auto()
set_place_comment = auto()
add_place_match = auto()
delete_place_match = auto()
acquire_place = auto()
release_place_owned = auto()
release_place_any = auto()
allow_place_owned = auto()
allow_place_any = auto()
create_reservation = auto()
cancel_reservation_owned = auto()
cancel_reservation_any = auto()
poll_reservation = auto()
get_reservations = auto()
17 changes: 17 additions & 0 deletions labgrid/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
# TODO: drop if Python >= 3.11 guaranteed
from exceptiongroup import ExceptionGroup # pylint: disable=redefined-builtin

from labgrid.remote.grpc.interceptor.client import (
IdentityClientStreamStreamInterceptor,
IdentityClientUnaryUnaryInterceptor,
)

from .common import (
ResourceEntry,
ResourceMatch,
Expand Down Expand Up @@ -120,9 +125,19 @@ def __attrs_post_init__(self):
("grpc.http2.max_pings_without_data", 0), # no limit
]

identity = {
"username": self.getuser(),
"hostname": self.gethostname(),
"user_agent": f"labgrid-client {labgrid_version()}",
}
interceptors = [
IdentityClientUnaryUnaryInterceptor(**identity),
IdentityClientStreamStreamInterceptor(**identity),
]
self.channel = grpc.aio.insecure_channel(
target=self.address,
options=channel_options,
interceptors=interceptors,
)
self.stub = labgrid_coordinator_pb2_grpc.CoordinatorStub(self.channel)

Expand Down Expand Up @@ -1581,6 +1596,8 @@ async def create_reservation(self):
print("Waiting for allocation...")
await self._wait_reservation(res.token, verbose=False)

return res.token

async def cancel_reservation(self):
token: str = self.args.token

Expand Down
17 changes: 17 additions & 0 deletions labgrid/remote/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import logging
from datetime import datetime
from fnmatch import fnmatchcase
from typing import Optional
import warnings

import attr

Expand Down Expand Up @@ -481,6 +483,21 @@ def from_pb2(cls, pb2: labgrid_coordinator_pb2.Reservation):
)


def get_metadata_single_value_by_key(metadata, key: str) -> Optional[str]:
"""Look up a single value by key in a metadata sequence of (key, value) pairs."""
values = [v for k, v in metadata or () if k == key]

if not values:
return None

if len(values) > 1:
warnings.warn(
"Multiple metadata KV pairs with the same key. The value of the first matching KV pair will be returned."
)

return values[0]


async def queue_as_aiter(q):
try:
while True:
Expand Down
Loading