Edits history of script submission #11468 for ' Searches for an element - in this case "incident" - in the verinice.veo open source ISMS tool. (verinice.veo)'

  • bun
    //native
    //you can add proxy support using //proxy http(s)://host:port
    
    // native scripts are bun scripts that are executed on native workers and can be parallelized
    // only fetch is allowed, but imports will work as long as they also use only fetch and the standard lib
    
    //import * as wmill from "windmill-client"
    
    interface TokenParams {
      host: string;
      username: string;
      password: string;
      clientId: string;
      realm: string;
    }
    
    interface TokenResponse {
      access_token?: string;
      [key: string]: any;
    }
    
    async function getAccessToken({ host, username, password, clientId, realm }: TokenParams): Promise<string> {
      const url = `https://${host}/auth/realms/${realm}/protocol/openid-connect/token`;
    
      const params = new URLSearchParams({
        grant_type: 'password',
        username,
        password,
        client_id: clientId,
      });
    
      const response = await fetch(url, {
        method: 'POST',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/x-www-form-urlencoded',
          'cache-control': 'no-cache',
        },
        body: params,
      });
    
      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
      }
    
      const data: TokenResponse = await response.json();
      const token = data.access_token;
      if (!token) {
        throw new Error('Could not get access token');
      }
      return token;
    }
    
    export async function main(domain_id: string = "c4503929-0737-4875-8b46-dfbea2512b3f",
      user: string = "sandboxuser",
      pass: string,
      oidc_client: string = "veo-sandbox",
      unit_id: string = "3d47b7d7-29f9-42fb-9414-0010b5e4ae23",
      abbreviation: string,
      subtype: string = "INC_SecurityIncident",
      realm: string = "verinice-sandbox",
      api_host: string = "api.sandbox.verinice.com"
    ) {
    
      const token = await getAccessToken({
        host: "auth.verinice.com",
        username: user,
        password: pass,
        clientId: oidc_client,
        realm: realm
      });
    
      const res = await fetch(`https://${api_host}/veo/domains/${domain_id}/incidents?size=200&unit=${unit_id}&subType=${subtype}&abbreviation=${abbreviation}`, {
        headers: {
          "Content-Type": "application/json",
          "Authorization": "Bearer " + token
        },
      });
      return res.json();
    }
    

    Submitted by alexander koderman64 451 days ago