Skip to content

Commit

Permalink
Merge branch 'dev' into fix/k8s-port
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgorana authored Feb 15, 2024
2 parents 8ea74a2 + b0c3640 commit 003f32f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 74 deletions.
40 changes: 2 additions & 38 deletions .github/workflows/cd-syft-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,10 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v3

- name: Install Azure CLI
run: |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
az version
- name: Login to Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS_GITHUB_CI }}

- name: Login to Azure Container Registry
uses: azure/docker-login@v1
uses: docker/login-action@v3
with:
login-server: ${{ secrets.ACR_SERVER }}
registry: ${{ secrets.ACR_SERVER }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}

Expand Down Expand Up @@ -178,29 +168,3 @@ jobs:
add: "."
push: "origin main"
cwd: "./infrastructure/"

- name: Cleanup Azure Container Registry
run: |
ACR_REGISTRY_NAME=${{ secrets.ACR_REGISTRY_NAME }}
echo ">> Fetching repo list.."
REPO_LIST=$(az acr repository list -n $ACR_REGISTRY_NAME -o tsv)
KEEP_PREV_VERSIONS=5
TAIL_FROM_LINE=$(($KEEP_PREV_VERSIONS + 1))
for repo in $REPO_LIST
do
echo "Cleaning up '$repo'"
az acr repository show-tags --name $ACR_REGISTRY_NAME --repository $repo --orderby time_desc --output tsv \
| grep dev- \
| tail -n +$TAIL_FROM_LINE \
| xargs -r -I% az acr repository untag --name $ACR_REGISTRY_NAME --image $repo:%
done
- name: Logout and cleanup Azure account
if: always()
run: |
az logout
az cache purge
az account clear
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ repos:
- id: mypy
name: "mypy: syft"
always_run: true
files: "^packages/syft/src/syft/serde|^packages/syft/src/syft/util/env.py|^packages/syft/src/syft/util/logger.py|^packages/syft/src/syft/util/markdown.py|^packages/syft/src/syft/util/notebook_ui/notebook_addons.py|^packages/syft/src/syft/service/warnings.py|^packages/syft/src/syft/service/dataset|^packages/syft/src/syft/service/worker"
files: "^packages/syft/src/syft/serde|^packages/syft/src/syft/util/env.py|^packages/syft/src/syft/util/logger.py|^packages/syft/src/syft/util/markdown.py|^packages/syft/src/syft/util/notebook_ui/notebook_addons.py|^packages/syft/src/syft/service/warnings.py|^packages/syft/src/syft/service/dataset|^packages/syft/src/syft/service/worker|^packages/syft/src/syft/service/user"
#files: "^packages/syft/src/syft/serde"
args: [
"--follow-imports=skip",
Expand Down
2 changes: 1 addition & 1 deletion packages/syft/src/syft/service/user/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class Roles(Enum):
UPLOADER = "Uploader"
EDITOR = "Editor"

def __str__(self):
def __str__(self) -> str:
return f"{self.value}"
32 changes: 16 additions & 16 deletions packages/syft/src/syft/service/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ class UserCreateV1(UserUpdateV1):

email: EmailStr
name: str
role: Optional[ServiceRole] = None
role: Optional[ServiceRole] = None # type: ignore[assignment]
password: str
password_verify: Optional[str] = None
password_verify: Optional[str] = None # type: ignore[assignment]
verify_key: Optional[SyftVerifyKey]
institution: Optional[str]
website: Optional[str]
institution: Optional[str] # type: ignore[assignment]
website: Optional[str] # type: ignore[assignment]
created_by: Optional[SyftSigningKey]


Expand All @@ -188,12 +188,12 @@ class UserCreate(UserUpdate):

email: EmailStr
name: str
role: Optional[ServiceRole] = None # make sure role cant be set without uid
role: Optional[ServiceRole] = None # type: ignore[assignment]
password: str
password_verify: Optional[str] = None
password_verify: Optional[str] = None # type: ignore[assignment]
verify_key: Optional[SyftVerifyKey]
institution: Optional[str]
website: Optional[str]
institution: Optional[str] # type: ignore[assignment]
website: Optional[str] # type: ignore[assignment]
created_by: Optional[SyftSigningKey]
mock_execution_permission: bool = False

Expand Down Expand Up @@ -399,40 +399,40 @@ def user_to_user_verify() -> List[Callable]:


@migrate(UserV1, User)
def upgrade_user_v1_to_v2():
def upgrade_user_v1_to_v2() -> List[Callable]:
return [make_set_default(key="mock_execution_permission", value=False)]


@migrate(User, UserV1)
def downgrade_user_v2_to_v1():
def downgrade_user_v2_to_v1() -> List[Callable]:
return [drop(["mock_execution_permission"])]


@migrate(UserUpdateV1, UserUpdate)
def upgrade_user_update_v1_to_v2():
def upgrade_user_update_v1_to_v2() -> List[Callable]:
return [make_set_default(key="mock_execution_permission", value=False)]


@migrate(UserUpdate, UserUpdateV1)
def downgrade_user_update_v2_to_v1():
def downgrade_user_update_v2_to_v1() -> List[Callable]:
return [drop(["mock_execution_permission"])]


@migrate(UserCreateV1, UserCreate)
def upgrade_user_create_v1_to_v2():
def upgrade_user_create_v1_to_v2() -> List[Callable]:
return [make_set_default(key="mock_execution_permission", value=False)]


@migrate(UserCreate, UserCreateV1)
def downgrade_user_create_v2_to_v1():
def downgrade_user_create_v2_to_v1() -> List[Callable]:
return [drop(["mock_execution_permission"])]


@migrate(UserViewV1, UserView)
def upgrade_user_view_v1_to_v2():
def upgrade_user_view_v1_to_v2() -> List[Callable]:
return [make_set_default(key="mock_execution_permission", value=False)]


@migrate(UserView, UserViewV1)
def downgrade_user_view_v2_to_v1():
def downgrade_user_view_v2_to_v1() -> List[Callable]:
return [drop(["mock_execution_permission"])]
19 changes: 11 additions & 8 deletions packages/syft/src/syft/service/user/user_roles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# stdlib
from enum import Enum
from typing import Any
from typing import Dict
from typing import List
from typing import Tuple
from typing import Union
Expand Down Expand Up @@ -42,13 +43,13 @@ def roles_descending(cls) -> List[Tuple[int, Self]]:
tuples.append((x.value, x))
return sorted(tuples, reverse=True)

@staticmethod
def roles_for_level(level: Union[int, Self]) -> List[Self]:
@classmethod
def roles_for_level(cls, level: Union[int, Self]) -> List[Self]:
if isinstance(level, ServiceRole):
level = level.value
roles = []
level_float = float(level)
service_roles = ServiceRole.roles_descending()
service_roles = cls.roles_descending()
for role in service_roles:
role_num = role[0]
if role_num == 0:
Expand All @@ -59,7 +60,7 @@ def roles_for_level(level: Union[int, Self]) -> List[Self]:
level_float = level_float % role_num
return roles

def capabilities(self):
def capabilities(self) -> List[ServiceRoleCapability]:
return ROLE_TO_CAPABILITIES[self]

def __add__(self, other: Any) -> int:
Expand Down Expand Up @@ -90,19 +91,21 @@ def __lt__(self, other: Self) -> bool:
+ ServiceRole.ADMIN
)

DATA_SCIENTIST_ROLE_LEVEL = ServiceRole.roles_for_level(
DATA_SCIENTIST_ROLE_LEVEL: List[ServiceRole] = ServiceRole.roles_for_level(
ServiceRole.DATA_SCIENTIST + ServiceRole.DATA_OWNER + ServiceRole.ADMIN
)

ONLY_DATA_SCIENTIST_ROLE_LEVEL = ServiceRole.roles_for_level(ServiceRole.DATA_SCIENTIST)
ONLY_DATA_SCIENTIST_ROLE_LEVEL: List[ServiceRole] = ServiceRole.roles_for_level(
ServiceRole.DATA_SCIENTIST
)

DATA_OWNER_ROLE_LEVEL = ServiceRole.roles_for_level(
DATA_OWNER_ROLE_LEVEL: List[ServiceRole] = ServiceRole.roles_for_level(
ServiceRole.DATA_OWNER + ServiceRole.ADMIN
)

ADMIN_ROLE_LEVEL = ServiceRole.roles_for_level(ServiceRole.ADMIN)

ROLE_TO_CAPABILITIES = {
ROLE_TO_CAPABILITIES: Dict[ServiceRole, List[ServiceRoleCapability]] = {
ServiceRole.NONE: [],
ServiceRole.GUEST: [
ServiceRoleCapability.CAN_MAKE_DATA_REQUESTS,
Expand Down
16 changes: 10 additions & 6 deletions packages/syft/src/syft/service/user/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ def get_all(
for i in range(0, len(results), page_size)
]
# Return the proper slice using chunk_index
results = results[page_index]
results = UserViewPage(users=results, total=total)
if page_index is not None:
results = results[page_index]
results = UserViewPage(users=results, total=total)

return results

# 🟡 TODO: No user exists will happen when result.ok() is empty list
Expand Down Expand Up @@ -180,9 +182,9 @@ def search(
]

# Return the proper slice using page_index
results = results[page_index]

results = UserViewPage(users=results, total=total)
if page_index is not None:
results = results[page_index]
results = UserViewPage(users=results, total=total)

return results

Expand Down Expand Up @@ -317,7 +319,9 @@ def update(

return user.to(UserView)

def get_target_object(self, credentials: SyftVerifyKey, uid: UID):
def get_target_object(
self, credentials: SyftVerifyKey, uid: UID
) -> Union[User, SyftError]:
user_result = self.stash.get_by_uid(credentials=credentials, uid=uid)
if user_result.is_err():
return SyftError(message=str(user_result.err()))
Expand Down
8 changes: 4 additions & 4 deletions packages/syft/src/syft/service/user/user_stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def set(
ignore_duplicates=ignore_duplicates,
)

def admin_verify_key(self):
def admin_verify_key(self) -> Result[Optional[SyftVerifyKey], str]:
return Ok(self.partition.root_verify_key)

def admin_user(self):
def admin_user(self) -> Result[Optional[User], str]:
return self.get_by_role(
credentials=self.admin_verify_key().ok(), role=ServiceRole.ADMIN
)
Expand Down Expand Up @@ -110,7 +110,7 @@ def get_by_verify_key(
return self.query_one(credentials=credentials, qks=qks)

def delete_by_uid(
self, credentials: SyftVerifyKey, uid: UID, has_permission=False
self, credentials: SyftVerifyKey, uid: UID, has_permission: bool = False
) -> Result[SyftSuccess, str]:
qk = UIDPartitionKey.with_obj(uid)
result = super().delete(
Expand All @@ -121,7 +121,7 @@ def delete_by_uid(
return result

def update(
self, credentials: SyftVerifyKey, user: User, has_permission=False
self, credentials: SyftVerifyKey, user: User, has_permission: bool = False
) -> Result[User, str]:
res = self.check_type(user, self.object_type)
# we dont use and_then logic here as it is hard because of the order of the arguments
Expand Down

0 comments on commit 003f32f

Please sign in to comment.