<commit_before>package master

import (
	"github.com/abbot/go-http-auth"
	"github.com/h2oai/steamY/master/az"
	"github.com/h2oai/steamY/master/data"
	"log"
	"net/http"
)

type DefaultAz struct {
	ds *data.Datastore
}

func newDefaultAz(ds *data.Datastore) *DefaultAz {
	return &DefaultAz{ds}
}

func (a *DefaultAz) Authenticate(username string) string {
	pz, err := a.ds.NewPrincipal(username)
	if err != nil {
		log.Printf("User %s read failed: %s\n", username, err)
		return ""
	}
	log.Println("User logged in:", username)
	return pz.Password()
}

func (a *DefaultAz) Identify(r *http.Request) (az.Principal, error) {
	username := r.Header.Get(auth.AuthUsernameHeader)
	log.Println("User identified:", username)
	return a.ds.NewPrincipal(username)
}<commit_msg>STEAM-151: no username/password should error out<commit_after>package master

import (
	"fmt"
	"log"
	"net/http"

	auth "github.com/abbot/go-http-auth"
	"github.com/h2oai/steamY/master/az"
	"github.com/h2oai/steamY/master/data"
)

type DefaultAz struct {
	ds *data.Datastore
}

func newDefaultAz(ds *data.Datastore) *DefaultAz {
	return &DefaultAz{ds}
}

func (a *DefaultAz) Authenticate(username string) string {
	pz, err := a.ds.NewPrincipal(username)
	if err != nil {
		log.Printf("User %s read failed: %s\n", username, err)
		return ""
	}

	if pz == nil {
		log.Printf("User %s does not exist\n", username)
		return ""
	}
	log.Println("User logged in:", username)
	return pz.Password()
}

func (a *DefaultAz) Identify(r *http.Request) (az.Principal, error) {
	username := r.Header.Get(auth.AuthUsernameHeader)
	log.Println("User identified:", username)
	pz, err := a.ds.NewPrincipal(username)
	if err != nil {
		return nil, err
	}

	if pz == nil {
		return nil, fmt.Errorf("User %s does not exist\n", username)
	}

	return pz, nil
}
{'fraction_non_alphanumeric': 0.1528627015008338, 'fraction_numerical': 0.0038910505836575876, 'mean_word_length': 4.357142857142857, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1141633', 'n_tokens_mistral': 713, 'n_tokens_neox': 693, 'n_words': 156}