<commit_before>package users

import (
    "github.com/gorilla/mux"
    "net/http"
    "log"
    "fmt"
    )

var (
    UNAUTHORIZED_MESSAGE = []byte("The API key provided either doesn't exist our records or is disabled.")
    )



// Runs an authorization check on the api before calling the function
func apiAuth(h http.HandlerFunc, superdeviceRequired bool) http.HandlerFunc {
    return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
        vars := mux.Vars(request)
        auth := vars["AuthKey"]
        device, err := ReadDeviceByApiKey(auth)

        // Check for devices that exist
        if device == nil || err != nil {
            writer.WriteHeader(http.StatusUnauthorized)
            writer.Write(UNAUTHORIZED_MESSAGE)

            if err != nil {
                log.Print(err)
            }

            return
        }

        // Check for superdevices.
        if superdeviceRequired && !device.isAdmin() {
            writer.WriteHeader(http.StatusUnauthorized)
            writer.Write(UNAUTHORIZED_MESSAGE)

            // TODO throttle/notify if too many weird requests.
            log.Printf("Denied superdevice request | device:%v", device)
            return

        }

        if ! device.isActive() {
            writer.WriteHeader(http.StatusUnauthorized)
            writer.Write(UNAUTHORIZED_MESSAGE)

            // TODO throttle/notify if too many weird requests.
            log.Printf("Denied inactive device request | device:%v", device)
            return
        }

        // TODO check for upload limits

        h.ServeHTTP(writer, request)
    })
}

type ReadUserResult struct {
    Users []CleanUser
    Unsanitized []User
}



func readUser(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func createUser(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func updateUser(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func deleteUser(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func readDevice(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func createDevice(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func updateDevice(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func deleteDevice(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func readStream(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func createStream(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func deleteStream(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}




// Creates a subrouter available to
func GetSubrouter(subroutePrefix *mux.Route) {

    //    r := mux.NewRouter()
<commit_msg>fixed userservice to properly add route information. added flag to override api key checks which will be useful during setup.<commit_after>package users

import (
    "github.com/gorilla/mux"
    "net/http"
    "log"
    "fmt"
    "flag"
    )

var (
    UNAUTHORIZED_MESSAGE = []byte("The API key provided either doesn't exist our records or is disabled.")
    ignoreBadApiKeys = flag.Bool("ignoreBadApiKeys", false, "Ignores bad api keys and processes all requests as superuser.")
)



// Runs an authorization check on the api before calling the function
func apiAuth(h http.HandlerFunc, superdeviceRequired bool) http.HandlerFunc {
    return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
        vars := mux.Vars(request)
        auth := vars["AuthKey"]
        device, err := ReadDeviceByApiKey(auth)


        // for development purposes
        if *ignoreBadApiKeys {
            h.ServeHTTP(writer, request)
            return
        }

        // Check for devices that exist
        if device == nil || err != nil {
            writer.WriteHeader(http.StatusUnauthorized)
            writer.Write(UNAUTHORIZED_MESSAGE)

            if err != nil {
                log.Print(err)
            }

            return
        }

        // Check for superdevices.
        if superdeviceRequired && !device.isAdmin() {
            writer.WriteHeader(http.StatusUnauthorized)
            writer.Write(UNAUTHORIZED_MESSAGE)

            // TODO throttle/notify if too many weird requests.
            log.Printf("Denied superdevice request | device:%v", device)
            return

        }

        if ! device.isActive() {
            writer.WriteHeader(http.StatusUnauthorized)
            writer.Write(UNAUTHORIZED_MESSAGE)

            // TODO throttle/notify if too many weird requests.
            log.Printf("Denied inactive device request | device:%v", device)
            return
        }

        // TODO check for upload limits

        h.ServeHTTP(writer, request)
    })
}

type ReadUserResult struct {
    Users []CleanUser
    Unsanitized []User
}



func readUser(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func createUser(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func updateUser(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func deleteUser(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func readDevice(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func createDevice(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func updateDevice(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func deleteDevice(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func readStream(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func createStream(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}


func deleteStream(writer http.ResponseWriter, request *http.Request) {
    //var result ReadUserResult

    // todo fill structs
    fmt.Fprintf(writer, "Hi there, I love %s!", request.URL.Path[1:])
}




// Creates a subrouter available to
func GetSubrouter(subroutePrefix *mux.Router) {

    //    r := mux.NewRouter()

{'fraction_non_alphanumeric': 0.11304757418747056, 'fraction_numerical': 0.0025906735751295338, 'mean_word_length': 2.7233669443226654, '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': '5429781', 'n_tokens_mistral': 2579, 'n_tokens_neox': 2490, 'n_words': 697}