Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User/noharper/release 4.1.0 #109

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4f2287b
Service Principal locked down by default and deploying user added.
nharper32 Nov 2, 2021
bebc2f5
Fixing call to client.
nharper32 Nov 2, 2021
f6eb239
Adding multiple users.
nharper32 Nov 2, 2021
aa710cf
Retrieving SP id.
nharper32 Nov 2, 2021
31dcd1d
Refactorin gcall.
nharper32 Nov 2, 2021
259ddca
Getting closer.
nharper32 Nov 2, 2021
eb84d0b
Can retrieve object_id from create
nharper32 Nov 3, 2021
dd727f6
New retrieve sp functionality.
nharper285 Nov 3, 2021
59ece5d
mypy fixes.
nharper285 Nov 3, 2021
aa93fc9
Separating functionality into new function.
nharper285 Nov 3, 2021
f483460
mypy errors.
nharper32 Nov 3, 2021
d0fbae8
Merge branch 'main' into user/noharper/guest-access-sp
nharper285 Nov 3, 2021
f92f642
Logic for updating appRoleAssignemntRequired param.
nharper32 Nov 4, 2021
b735365
Changing to patch.
nharper32 Nov 4, 2021
10beca1
Updating to Patch.
nharper32 Nov 4, 2021
d3c9906
Fixing bug.
nharper32 Nov 4, 2021
3edb282
Fixing bad assignment.
nharper32 Nov 4, 2021
9cd5c22
Responding to comments.
nharper32 Nov 4, 2021
f1e87f8
Merge branch 'main' into user/noharper/guest-access-sp
nharper285 Nov 4, 2021
a7d9647
Removing functionality for updating setting.
nharper32 Nov 4, 2021
e589355
Merge branch 'user/noharper/guest-access-sp' of https://github.com/nh…
nharper32 Nov 4, 2021
6257a32
Update src/deployment/deploy.py
nharper285 Nov 4, 2021
f1a85c1
UPdating error message.
nharper32 Nov 4, 2021
257423e
Merge conflict.
nharper32 Nov 4, 2021
420973c
Retriggering?
nharper285 Nov 5, 2021
477ab61
Merge branch 'nharper285-user/noharper/guest-access-sp'
nharper285 Nov 5, 2021
b82923d
Merge branch 'main' of https://github.com/microsoft/onefuzz into micr…
nharper285 Nov 5, 2021
3ca4689
Merge branch 'microsoft-main'
nharper285 Nov 5, 2021
f4deda1
Trying to emulate new file structure.
nharper285 Nov 5, 2021
f968539
Updating merge conflicts.
nharper285 Nov 5, 2021
741091a
Merge branch 'nharper285-user/noharper/guest-access-sp-3'
nharper285 Nov 5, 2021
b89ff6c
Merge branch 'microsoft:main' into main
nharper285 Nov 15, 2021
40123e9
Merge branch 'main' of https://github.com/nharper285/onefuzz
nharper32 Dec 3, 2021
155fe03
Merge branch 'main' of https://github.com/nharper285/onefuzz
nharper32 Dec 6, 2021
91fe5ec
Creating test PR.
nharper32 Dec 6, 2021
2f8af9d
Trying to fix deploy.
nharper32 Dec 7, 2021
ec0b46d
formmatting deploy.
nharper285 Dec 7, 2021
509dc31
Updating
nharper285 Dec 7, 2021
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
2 changes: 1 addition & 1 deletion CURRENT_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0
4.1.0
74 changes: 66 additions & 8 deletions src/deployment/deploylib/set_admins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,74 @@
# Licensed under the MIT License.

import argparse
import json
import logging
from typing import List, Optional
from uuid import UUID

from azure.common.client_factory import get_client_from_cli_profile
from azure.cosmosdb.table.tableservice import TableService
from azure.mgmt.storage import StorageManagementClient

from deploylib.configuration import (
InstanceConfigClient,
update_admins,
update_allowed_aad_tenants,
)
storage_client_logger = logging.getLogger("azure.cosmosdb.table.common.storageclient")
TABLE_NAME = "InstanceConfig"


## Disable logging from storageclient. This module displays an error message
## when a resource is not found even if the exception is raised and handled internally.
## This happen when a table does not exist. An error message is displayed but the exception is
## handled by the library.
def disable_storage_client_logging() -> None:
if storage_client_logger:
storage_client_logger.disabled = True


def enable_storage_client_logging() -> None:
if storage_client_logger:
storage_client_logger.disabled = False


def create_if_missing(table_service: TableService) -> None:
try:
disable_storage_client_logging()

if not table_service.exists(TABLE_NAME):
table_service.create_table(TABLE_NAME)
finally:
enable_storage_client_logging()


def update_allowed_aad_tenants(
table_service: TableService, resource_group: str, tenants: List[UUID]
) -> None:
create_if_missing(table_service)
as_str = [str(x) for x in tenants]
table_service.insert_or_merge_entity(
TABLE_NAME,
{
"PartitionKey": resource_group,
"RowKey": resource_group,
"allowed_aad_tenants": json.dumps(as_str),
},
)


def update_admins(
table_service: TableService, resource_group: str, admins: List[UUID]
) -> None:
create_if_missing(table_service)
admins_as_str: Optional[List[str]] = None
if admins:
admins_as_str = [str(x) for x in admins]

table_service.insert_or_merge_entity(
TABLE_NAME,
{
"PartitionKey": resource_group,
"RowKey": resource_group,
"admins": json.dumps(admins_as_str),
},
)


def main() -> None:
Expand All @@ -33,11 +90,12 @@ def main() -> None:
table_service = TableService(
account_name=args.storage_account, account_key=storage_keys.keys[0].value
)
config_client = InstanceConfigClient(table_service, args.resource_group)
if args.admins:
update_admins(config_client, args.admins)
update_admins(table_service, args.resource_group, args.admins)
if args.allowed_aad_tenants:
update_allowed_aad_tenants(config_client, args.allowed_aad_tenants)
update_allowed_aad_tenants(
table_service, args.resource_group, args.allowed_aad_tenants
)


if __name__ == "__main__":
Expand Down
12 changes: 6 additions & 6 deletions src/utils/check-pr/check-pr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Expand Down Expand Up @@ -188,9 +188,9 @@ def merge(self) -> None:
def deploy(self, filename: str) -> None:
print(f"deploying {filename} to {self.instance}")
venv = "deploy-venv"
subprocess.check_call(f"python -mvenv {venv}", shell=True)
subprocess.check_call(f"python3 -mvenv {venv}", shell=True)
pip = venv_path(venv, "pip")
py = venv_path(venv, "python")
py = venv_path(venv, "python3")
config = os.path.join(os.getcwd(), "config.json")
commands = [
("extracting release-artifacts", f"unzip -qq {filename}"),
Expand All @@ -212,8 +212,8 @@ def deploy(self, filename: str) -> None:

def test(self, filename: str) -> None:
venv = "test-venv"
subprocess.check_call(f"python -mvenv {venv}", shell=True)
py = venv_path(venv, "python")
subprocess.check_call(f"python3 -mvenv {venv}", shell=True)
py = venv_path(venv, "python3")
test_dir = "integration-test-artifacts"
script = "integration-test.py"
endpoint = f"https://{self.instance}.azurewebsites.net"
Expand All @@ -223,7 +223,7 @@ def test(self, filename: str) -> None:
"extracting integration-test-artifacts",
f"unzip -qq {filename} -d {test_dir}",
),
("test venv", f"python -mvenv {venv}"),
("test venv", f"python3 -mvenv {venv}"),
("installing wheel", f"./{venv}/bin/pip install -q wheel"),
("installing sdk", f"./{venv}/bin/pip install -q sdk/*.whl"),
(
Expand Down