<commit_before>package lib

import (
	"fmt"
	"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
	"github.com/aws/aws-sdk-go/aws/defaults"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/iam"
	"net/http"
	"os"
	"strings"
)

// Lookup the MFA devices configured for the calling user's IAM account
func LookupMfa(sess *session.Session) ([]*iam.MFADevice, error) {
	s := iam.New(sess)

	res, err := s.ListMFADevices(&iam.ListMFADevicesInput{})
	if err != nil {
		return nil, err
	}

	return res.MFADevices, nil
}

// Print prompt to enter MFA code and gather input
func PromptForMfa() string {
	var mfaCode string
	fmt.Print("Enter MFA Code: ")
	fmt.Scanln(&mfaCode)
	return mfaCode
}

// Return the location of the AWS SDK config file.  Use the value of
// the AWS_CONFIG_FILE environment variable, if available, otherwise
// use the SDK default location
func AwsConfigFile() string {
	c := defaults.SharedConfigFilename()
	e, ok := os.LookupEnv("AWS_CONFIG_FILE")
	if ok && len(e) > 0 {
		c = e
	}
	return c
}

func AwsSession(profile string) *session.Session {
	// Doing this kills the ability to use env vars, which may mess
	// with the -M option, requiring the ~/.aws/credentials file
	// Unset AWS credential env vars
	//env := []string{
	//	"AWS_ACCESS_KEY_ID", "AWS_ACCESS_KEY",
	//	"AWS_SECRET_ACCESS_KEY", "AWS_SECRET_KEY",
	//	"AWS_SESSION_TOKEN", "AWS_SECURITY_TOKEN",
	//}
	//for _, e := range env {
	//	os.Unsetenv(e)
	//}

	opts := session.Options{
		SharedConfigState:       session.SharedConfigEnable,
		AssumeRoleTokenProvider: stscreds.StdinTokenProvider,
	}

	if len(profile) > 0 {
		opts.Profile = profile
	}

	return session.Must(session.NewSessionWithOptions(opts))
}

func VersionCheck(version string) error {
	u := "https://github.com/mmmorris1975/aws-runas/releases/latest"
	r, err := http.NewRequest(http.MethodHead, u, http.NoBody)
	if err != nil {
		return err
	}

	// Get in the weeds so we don't follow redirects
	res, err := http.DefaultTransport.RoundTrip(r)
	if err != nil {
		return err
	}
	defer res.Body.Close()

	if res.StatusCode == http.StatusFound {
		url, err := res.Location()
		if err != nil {
			return err
		}

		p := strings.Trim(url.Path, `/`)
		f := strings.Split(p, `/`)
		v := f[len(f)-1]

		if v != version {
			fmt.Printf("New version of aws-runas available: %s\nDownload available at: %s", v, u)
		}
	}

	return fmt.Errorf("Version check failed, bad HTTP Status: %d", res.StatusCode)
}<commit_msg>add missing return statement in VersionCheck()<commit_after>package lib

import (
	"fmt"
	"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
	"github.com/aws/aws-sdk-go/aws/defaults"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/iam"
	"net/http"
	"os"
	"strings"
)

// Lookup the MFA devices configured for the calling user's IAM account
func LookupMfa(sess *session.Session) ([]*iam.MFADevice, error) {
	s := iam.New(sess)

	res, err := s.ListMFADevices(&iam.ListMFADevicesInput{})
	if err != nil {
		return nil, err
	}

	return res.MFADevices, nil
}

// Print prompt to enter MFA code and gather input
func PromptForMfa() string {
	var mfaCode string
	fmt.Print("Enter MFA Code: ")
	fmt.Scanln(&mfaCode)
	return mfaCode
}

// Return the location of the AWS SDK config file.  Use the value of
// the AWS_CONFIG_FILE environment variable, if available, otherwise
// use the SDK default location
func AwsConfigFile() string {
	c := defaults.SharedConfigFilename()
	e, ok := os.LookupEnv("AWS_CONFIG_FILE")
	if ok && len(e) > 0 {
		c = e
	}
	return c
}

func AwsSession(profile string) *session.Session {
	// Doing this kills the ability to use env vars, which may mess
	// with the -M option, requiring the ~/.aws/credentials file
	// Unset AWS credential env vars
	//env := []string{
	//	"AWS_ACCESS_KEY_ID", "AWS_ACCESS_KEY",
	//	"AWS_SECRET_ACCESS_KEY", "AWS_SECRET_KEY",
	//	"AWS_SESSION_TOKEN", "AWS_SECURITY_TOKEN",
	//}
	//for _, e := range env {
	//	os.Unsetenv(e)
	//}

	opts := session.Options{
		SharedConfigState:       session.SharedConfigEnable,
		AssumeRoleTokenProvider: stscreds.StdinTokenProvider,
	}

	if len(profile) > 0 {
		opts.Profile = profile
	}

	return session.Must(session.NewSessionWithOptions(opts))
}

func VersionCheck(version string) error {
	u := "https://github.com/mmmorris1975/aws-runas/releases/latest"
	r, err := http.NewRequest(http.MethodHead, u, http.NoBody)
	if err != nil {
		return err
	}

	// Get in the weeds so we don't follow redirects
	res, err := http.DefaultTransport.RoundTrip(r)
	if err != nil {
		return err
	}
	defer res.Body.Close()

	if res.StatusCode == http.StatusFound {
		url, err := res.Location()
		if err != nil {
			return err
		}

		p := strings.Trim(url.Path, `/`)
		f := strings.Split(p, `/`)
		v := f[len(f)-1]

		if v != version {
			fmt.Printf("New version of aws-runas available: %s\nDownload available at: %s\n", v, u)
		}
		return nil
	}

	return fmt.Errorf("Version check failed, bad HTTP Status: %d", res.StatusCode)
}
{'fraction_non_alphanumeric': 0.13963244107071515, 'fraction_numerical': 0.002796644027167399, 'mean_word_length': 3.6663560111835976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '5953785', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1840, 'n_words': 473}