<commit_before>// Package main implements a test client that starts a scan, wait until it finishes and exports its results to a csv file.
package main

import (
	"flag"
	"github.com/attwad/nessie"
	"io/ioutil"
	"log"
	"strings"
	"time"
)

var apiURL, username, password string

func init() {
	flag.StringVar(&apiURL, "api_url", "", "")
	flag.StringVar(&username, "username", "", "Username to login with, in production read that from a file, do not set from the command line or it will end up in your history.")
	flag.StringVar(&password, "password", "", "Password that matches the provided username, in production read that from a file, do not set from the command line or it will end up in your history.")
	flag.Parse()
}

func main() {
	nessus, err := nessie.NewInsecureNessus(apiURL)
	if err != nil {
		panic(err)
	}

	if err := nessus.Login(username, password); err != nil {
		log.Println(err)
		return
	}
	log.Println("Logged-in")

	var scanID int64 = 13
	// We only care about the last scan, so no use for the scan UUID here.
	if _, err = nessus.StartScan(scanID); err != nil {
		panic(err)
	}
	for {
		details, err := nessus.ScanDetails(scanID)
		if err != nil {
			panic(err)
		}
		if strings.ToLower(details.Info.Status) == "completed" {
			log.Println("Scan completed")
			break
		}
		log.Println("Scan is", details.Info.Status)
		time.Sleep(5 * time.Second)
	}

	exportID, err := nessus.ExportScan(scanID, nessie.ExportCSV)
	if err != nil {
		panic(err)
	}
	for {
		if finished, err := nessus.ExportFinished(scanID, exportID); err != nil {
			panic(err)
		} else if finished {
			log.Println("Scan export finished")
			break
		}
		log.Println("Scan export ongoing...")
		time.Sleep(5 * time.Second)
	}
	csv, err := nessus.DownloadExport(scanID, exportID)
	if err != nil {
		panic(err)
	}
	if err := ioutil.WriteFile("report.csv", csv, 0600); err != nil {
		panic(err)
	}

	defer nessus.Logout()
}<commit_msg>Moved the logout defer stmt where it belongs<commit_after>// Package main implements a test client that starts a scan, wait until it finishes and exports its results to a csv file.
package main

import (
	"flag"
	"github.com/attwad/nessie"
	"io/ioutil"
	"log"
	"strings"
	"time"
)

var apiURL, username, password string

func init() {
	flag.StringVar(&apiURL, "api_url", "", "")
	flag.StringVar(&username, "username", "", "Username to login with, in production read that from a file, do not set from the command line or it will end up in your history.")
	flag.StringVar(&password, "password", "", "Password that matches the provided username, in production read that from a file, do not set from the command line or it will end up in your history.")
	flag.Parse()
}

func main() {
	nessus, err := nessie.NewInsecureNessus(apiURL)
	if err != nil {
		panic(err)
	}

	if err := nessus.Login(username, password); err != nil {
		log.Println(err)
		return
	}
	log.Println("Logged-in")
	defer nessus.Logout()

	var scanID int64 = 13
	// We only care about the last scan, so no use for the scan UUID here.
	if _, err = nessus.StartScan(scanID); err != nil {
		panic(err)
	}
	for {
		details, err := nessus.ScanDetails(scanID)
		if err != nil {
			panic(err)
		}
		if strings.ToLower(details.Info.Status) == "completed" {
			log.Println("Scan completed")
			break
		}
		log.Println("Scan is", details.Info.Status)
		time.Sleep(5 * time.Second)
	}

	exportID, err := nessus.ExportScan(scanID, nessie.ExportCSV)
	if err != nil {
		panic(err)
	}
	for {
		if finished, err := nessus.ExportFinished(scanID, exportID); err != nil {
			panic(err)
		} else if finished {
			log.Println("Scan export finished")
			break
		}
		log.Println("Scan export ongoing...")
		time.Sleep(5 * time.Second)
	}
	csv, err := nessus.DownloadExport(scanID, exportID)
	if err != nil {
		panic(err)
	}
	if err := ioutil.WriteFile("report.csv", csv, 0600); err != nil {
		panic(err)
	}
}
{'fraction_non_alphanumeric': 0.13340227507755947, 'fraction_numerical': 0.005170630816959669, 'mean_word_length': 3.712545676004872, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4065201', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1353, 'n_words': 425}