Edits history of script submission #11469 for ' Get control-implementations from the open source ISMS tool verinice.veo (verinice.veo)'

  • python3
    import requests
    import json
    
    
    class TokenParams:
        def __init__(self, host, username, password, client_id, realm):
            self.host = host
            self.username = username
            self.password = password
            self.client_id = client_id
            self.realm = realm
    
    
    class TokenResponse:
        def __init__(self, access_token=None, **kwargs):
            self.access_token = access_token
            self.__dict__.update(kwargs)
    
    
    def get_access_token(params: TokenParams) -> str:
        url = f"https://{params.host}/auth/realms/{params.realm}/protocol/openid-connect/token"
    
        data = {
            "grant_type": "password",
            "username": params.username,
            "password": params.password,
            "client_id": params.client_id,
        }
    
        headers = {
            "Accept": "application/json",
            "Content-Type": "application/x-www-form-urlencoded",
            "cache-control": "no-cache",
        }
    
        response = requests.post(url, data=data, headers=headers)
    
        if response.status_code != 200:
            raise Exception(f"HTTP error! status: {response.status_code}")
    
        data = response.json()
        token_response = TokenResponse(**data)
        token = token_response.access_token
        if not token:
            raise Exception("Could not get access token")
        return token
    
    
    def main(
        domain_id="c4503929-0737-4875-8b46-dfbea2512b3f",
        user="sandboxuser",
        passw=None,
        oidc_client="veo-sandbox",
        controls_json: str = "",
        realm: str = "verinice-sandbox",
        api_host: str = "api.sandbox.verinice.com",
    ):
        token = get_access_token(
            TokenParams(
                host="auth.verinice.com",
                username=user,
                password=passw,
                client_id=oidc_client,
                realm=realm,
            )
        )
    
        controls = controls_json.get("items", [])
        print(controls)
    
        results = []
        for control in controls:
            control_id = control["id"]
            print(control_id)
            res = requests.get(
                f"https://{api_host}/veo/domains/{domain_id}/controls/{control_id}/control-implementations",
                headers={
                    "Content-Type": "application/json",
                    "Authorization": f"Bearer {token}",
                },
            )
            data = res.json()
            results.append(data)
    
        return results
    

    Submitted by alexander koderman64 451 days ago