forked from edulinq/autograder-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
928 additions
and
928 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,91 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/alecthomas/kong" | ||
|
||
"github.com/edulinq/autograder/internal/api" | ||
"github.com/edulinq/autograder/internal/common" | ||
"github.com/edulinq/autograder/internal/config" | ||
"github.com/edulinq/autograder/internal/db" | ||
"github.com/edulinq/autograder/internal/log" | ||
"github.com/edulinq/autograder/internal/model" | ||
pcourses "github.com/edulinq/autograder/internal/procedures/courses" | ||
"github.com/edulinq/autograder/internal/util" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/alecthomas/kong" | ||
|
||
"github.com/edulinq/autograder/internal/api" | ||
"github.com/edulinq/autograder/internal/common" | ||
"github.com/edulinq/autograder/internal/config" | ||
"github.com/edulinq/autograder/internal/db" | ||
"github.com/edulinq/autograder/internal/log" | ||
"github.com/edulinq/autograder/internal/model" | ||
pcourses "github.com/edulinq/autograder/internal/procedures/courses" | ||
"github.com/edulinq/autograder/internal/util" | ||
) | ||
|
||
var args struct { | ||
config.ConfigArgs | ||
config.ConfigArgs | ||
} | ||
|
||
func main() { | ||
kong.Parse(&args) | ||
err := config.HandleConfigArgs(args.ConfigArgs) | ||
if err != nil { | ||
log.Fatal("Could not load config options.", err) | ||
} | ||
|
||
err = common.CreatePIDFile() | ||
if err != nil { | ||
log.Fatal("Could not create PID file.", err) | ||
} | ||
|
||
defer func() { | ||
err := common.RemovePIDFile() | ||
if err != nil { | ||
log.Fatal("Could not remove PID file.", err) | ||
} | ||
}() | ||
|
||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
go func() { | ||
<-sigs | ||
err := common.RemovePIDFile() | ||
if err != nil { | ||
log.Error("Could not remove PID file.", err) | ||
} | ||
os.Exit(1) | ||
}() | ||
|
||
log.Info("Autograder Version", log.NewAttr("version", util.GetAutograderFullVersion())) | ||
|
||
workingDir, err := os.Getwd() | ||
if err != nil { | ||
log.Fatal("Could not get working directory.", err) | ||
} | ||
|
||
db.MustOpen() | ||
defer db.MustClose() | ||
|
||
log.Info("Running server with working directory.", log.NewAttr("dir", workingDir)) | ||
|
||
_, err = db.AddCourses() | ||
if err != nil { | ||
log.Fatal("Could not load courses.", err) | ||
} | ||
|
||
courses := db.MustGetCourses() | ||
log.Info("Loaded course(s).", log.NewAttr("count", len(courses))) | ||
|
||
// Startup courses (in the background). | ||
for _, course := range courses { | ||
log.Info("Loaded course.", course) | ||
go func(course *model.Course) { | ||
pcourses.UpdateCourse(course, true) | ||
}(course) | ||
} | ||
|
||
// Cleanup any temp dirs. | ||
defer util.RemoveRecordedTempDirs() | ||
|
||
err = api.StartServer() | ||
if err != nil { | ||
log.Fatal("Server was stopped.", err) | ||
} | ||
|
||
log.Info("Server closed.") | ||
kong.Parse(&args) | ||
err := config.HandleConfigArgs(args.ConfigArgs) | ||
if err != nil { | ||
log.Fatal("Could not load config options.", err) | ||
} | ||
|
||
err = common.CreatePIDFile() | ||
if err != nil { | ||
log.Fatal("Could not create PID file.", err) | ||
} | ||
|
||
defer func() { | ||
err := common.RemovePIDFile() | ||
if err != nil { | ||
log.Fatal("Could not remove PID file.", err) | ||
} | ||
}() | ||
|
||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
go func() { | ||
<-sigs | ||
err := common.RemovePIDFile() | ||
if err != nil { | ||
log.Error("Could not remove PID file.", err) | ||
} | ||
os.Exit(1) | ||
}() | ||
|
||
log.Info("Autograder Version", log.NewAttr("version", util.GetAutograderFullVersion())) | ||
|
||
workingDir, err := os.Getwd() | ||
if err != nil { | ||
log.Fatal("Could not get working directory.", err) | ||
} | ||
|
||
db.MustOpen() | ||
defer db.MustClose() | ||
|
||
log.Info("Running server with working directory.", log.NewAttr("dir", workingDir)) | ||
|
||
_, err = db.AddCourses() | ||
if err != nil { | ||
log.Fatal("Could not load courses.", err) | ||
} | ||
|
||
courses := db.MustGetCourses() | ||
log.Info("Loaded course(s).", log.NewAttr("count", len(courses))) | ||
|
||
// Startup courses (in the background). | ||
for _, course := range courses { | ||
log.Info("Loaded course.", course) | ||
go func(course *model.Course) { | ||
pcourses.UpdateCourse(course, true) | ||
}(course) | ||
} | ||
|
||
// Cleanup any temp dirs. | ||
defer util.RemoveRecordedTempDirs() | ||
|
||
err = api.StartServer() | ||
if err != nil { | ||
log.Fatal("Server was stopped.", err) | ||
} | ||
|
||
log.Info("Server closed.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
package core | ||
|
||
import ( | ||
"github.com/edulinq/autograder/internal/config" | ||
"github.com/edulinq/autograder/internal/db" | ||
"github.com/edulinq/autograder/internal/log" | ||
"github.com/edulinq/autograder/internal/model" | ||
"github.com/edulinq/autograder/internal/config" | ||
"github.com/edulinq/autograder/internal/db" | ||
"github.com/edulinq/autograder/internal/log" | ||
"github.com/edulinq/autograder/internal/model" | ||
) | ||
|
||
// Return a user only in the case that the authentication is successful. | ||
// If any error is retuturned, then the request should end and the response sent based on the error. | ||
// This assumes basic validation has already been done on the request. | ||
func (this *APIRequestUserContext) Auth() (*model.ServerUser, *APIError) { | ||
user, err := db.GetServerUser(this.UserEmail, true) | ||
if err != nil { | ||
return nil, NewAuthBadRequestError("-012", this, "Cannot Get User").Err(err) | ||
} | ||
user, err := db.GetServerUser(this.UserEmail, true) | ||
if err != nil { | ||
return nil, NewAuthBadRequestError("-012", this, "Cannot Get User").Err(err) | ||
} | ||
|
||
if user == nil { | ||
return nil, NewAuthBadRequestError("-013", this, "Unknown User") | ||
} | ||
if user == nil { | ||
return nil, NewAuthBadRequestError("-013", this, "Unknown User") | ||
} | ||
|
||
if config.NO_AUTH.Get() { | ||
log.Debug("Authentication Disabled.", log.NewUserAttr(this.UserEmail)) | ||
return user, nil | ||
} | ||
if config.NO_AUTH.Get() { | ||
log.Debug("Authentication Disabled.", log.NewUserAttr(this.UserEmail)) | ||
return user, nil | ||
} | ||
|
||
auth, err := user.Auth(this.UserPass) | ||
if err != nil { | ||
return nil, NewBareInternalError("-037", this.Endpoint, "User auth failed.").Err(err) | ||
} | ||
auth, err := user.Auth(this.UserPass) | ||
if err != nil { | ||
return nil, NewBareInternalError("-037", this.Endpoint, "User auth failed.").Err(err) | ||
} | ||
|
||
if !auth { | ||
return nil, NewAuthBadRequestError("-014", this, "Bad Password") | ||
} | ||
if !auth { | ||
return nil, NewAuthBadRequestError("-014", this, "Bad Password") | ||
} | ||
|
||
return user, nil | ||
return user, nil | ||
} |
Oops, something went wrong.