mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-16 20:08:09 +00:00
Add linting to deployment tools (#332)
This commit is contained in:
@ -9,7 +9,7 @@ import time
|
||||
import urllib.parse
|
||||
from datetime import datetime, timedelta
|
||||
from enum import Enum
|
||||
from typing import Dict, List, NamedTuple, Optional, Tuple
|
||||
from typing import Any, Dict, List, NamedTuple, Optional, Tuple
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
import requests
|
||||
@ -30,7 +30,7 @@ logger = logging.getLogger("deploy")
|
||||
|
||||
|
||||
class GraphQueryError(Exception):
|
||||
def __init__(self, message, status_code):
|
||||
def __init__(self, message: str, status_code: int) -> None:
|
||||
super(GraphQueryError, self).__init__(message)
|
||||
self.status_code = status_code
|
||||
|
||||
@ -40,7 +40,7 @@ def query_microsoft_graph(
|
||||
resource: str,
|
||||
params: Optional[Dict] = None,
|
||||
body: Optional[Dict] = None,
|
||||
):
|
||||
) -> Any:
|
||||
profile = get_cli_profile()
|
||||
(token_type, access_token, _), _, _ = profile.get_raw_token(
|
||||
resource="https://graph.microsoft.com"
|
||||
@ -139,7 +139,7 @@ def create_application_credential(application_name: str) -> str:
|
||||
|
||||
app: Application = apps[0]
|
||||
|
||||
(key, password) = add_application_password(app.object_id)
|
||||
(_, password) = add_application_password(app.object_id)
|
||||
return str(password)
|
||||
|
||||
|
||||
@ -210,7 +210,7 @@ def create_application_registration(
|
||||
return registered_app
|
||||
|
||||
|
||||
def add_application_password(app_object_id: UUID) -> Optional[Tuple[str, str]]:
|
||||
def add_application_password(app_object_id: UUID) -> Tuple[str, str]:
|
||||
key = uuid4()
|
||||
password_request = {
|
||||
"passwordCredential": {
|
||||
@ -232,10 +232,10 @@ def add_application_password(app_object_id: UUID) -> Optional[Tuple[str, str]]:
|
||||
return (str(key), password["secretText"])
|
||||
except GraphQueryError as err:
|
||||
logger.warning("creating password failed : %s" % err)
|
||||
None
|
||||
raise err
|
||||
|
||||
|
||||
def get_application(app_id: UUID) -> Optional[Dict]:
|
||||
def get_application(app_id: UUID) -> Optional[Any]:
|
||||
apps: Dict = query_microsoft_graph(
|
||||
method="GET",
|
||||
resource="applications",
|
||||
@ -251,7 +251,7 @@ def authorize_application(
|
||||
registration_app_id: UUID,
|
||||
onefuzz_app_id: UUID,
|
||||
permissions: List[str] = ["user_impersonation"],
|
||||
):
|
||||
) -> None:
|
||||
onefuzz_app = get_application(onefuzz_app_id)
|
||||
if onefuzz_app is None:
|
||||
logger.error("Application '%s' not found" % onefuzz_app_id)
|
||||
@ -290,7 +290,7 @@ def authorize_application(
|
||||
|
||||
def create_and_display_registration(
|
||||
onefuzz_instance_name: str, registration_name: str, approle: OnefuzzAppRole
|
||||
):
|
||||
) -> None:
|
||||
logger.info("Updating application registration")
|
||||
application_info = register_application(
|
||||
registration_name=registration_name,
|
||||
@ -303,7 +303,7 @@ def create_and_display_registration(
|
||||
logger.info("client_secret: %s" % application_info.client_secret)
|
||||
|
||||
|
||||
def update_pool_registration(onefuzz_instance_name: str):
|
||||
def update_pool_registration(onefuzz_instance_name: str) -> None:
|
||||
create_and_display_registration(
|
||||
onefuzz_instance_name,
|
||||
"%s_pool" % onefuzz_instance_name,
|
||||
@ -311,7 +311,7 @@ def update_pool_registration(onefuzz_instance_name: str):
|
||||
)
|
||||
|
||||
|
||||
def assign_scaleset_role(onefuzz_instance_name: str, scaleset_name: str):
|
||||
def assign_scaleset_role(onefuzz_instance_name: str, scaleset_name: str) -> None:
|
||||
""" Allows the nodes in the scaleset to access the service by assigning their managed identity to the ManagedNode Role """
|
||||
|
||||
onefuzz_service_appId = query_microsoft_graph(
|
||||
@ -380,7 +380,7 @@ def assign_scaleset_role(onefuzz_instance_name: str, scaleset_name: str):
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
formatter = argparse.ArgumentDefaultsHelpFormatter
|
||||
|
||||
parent_parser = argparse.ArgumentParser(add_help=False)
|
||||
|
Reference in New Issue
Block a user