Ejemplo n.º 1
0
Archivo: akc.go Proyecto: coduno/tools
func query() (key *AuthorizedKey, username string, err error) {
	ctx, err := connect()
	if err != nil {
		return
	}

	rawFingerprint, err := decodeFingerprint(fingerprint)
	if err != nil {
		return
	}

	key = new(AuthorizedKey)

	it := datastore.NewQuery(keyKind).Filter("Fingerprint =", rawFingerprint).Limit(1).Run(ctx)

	_, err = it.Next(key)
	if err != nil {
		return
	}

	var coder Coder
	err = datastore.Get(ctx, key.Coder, &coder)
	if err != nil {
		return
	}

	username = coder.Nickname
	return
}
Ejemplo n.º 2
0
func ExampleGet() {
	ctx := Example_auth()

	type Article struct {
		Title       string
		Description string
		Body        string `datastore:",noindex"`
		Author      *datastore.Key
		PublishedAt time.Time
	}
	key := datastore.NewKey(ctx, "Article", "articled1", 0, nil)
	article := &Article{}
	if err := datastore.Get(ctx, key, article); err != nil {
		log.Fatal(err)
	}
}
Ejemplo n.º 3
0
// FromAccessToken tries do identify a Passenger by the access token he gave us.
// It will look up the AccessToken and consequently the corresponding User.
func FromAccessToken(ctx context.Context, accessToken []byte) (p *Passenger, err error) {
	p.AccessTokenKey, err = model.NewQueryForAccessToken().
		Filter("Value=", accessToken).
		Limit(1).
		Run(ctx).
		Next(p.AccessToken)

	if err != nil {
		return
	}
	if p.UserKey = p.AccessTokenKey.Parent(); p.UserKey == nil {
		return
	}
	err = datastore.Get(ctx, p.UserKey, p.User)
	return
}
Ejemplo n.º 4
0
func startHandler(w http.ResponseWriter, req *http.Request) {
	cors(w, req)
	encodedKey := req.URL.Path[1:]

	// TODO(victorbalan): Remove this after we can connect with the engine to localhost.
	// Untill then leave it so we can get entity keys to query for.
	// q := datastore.NewQuery(model.ChallengeKind).Filter("Runner =", "outputtest")
	// var challenges []model.Challenge
	// t, _ := q.GetAll(ctx, &challenges)
	// fmt.Println(t[0])
	// fmt.Println(t[0].Encode())
	// return
	// cKey = t[0].Encode()

	key, err := datastore.DecodeKey(encodedKey)

	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	var challenge model.Challenge
	err = datastore.Get(NewContext(), key, &challenge)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	f := flag.NewFlagSet("challengeFlags", flag.ContinueOnError)
	tests := f.String("tests", "", "Defines the tests path")
	// TODO(victorbalan): Enable the image flage when we will use it
	// image := f.String("image", "", "Defines a custom image")

	flags := strings.Split(challenge.Flags, " ")
	if len(flags) > 0 {
		if err := f.Parse(flags); err != nil {
			fmt.Printf(err.Error())
		}
	}

	var rh runner.RunHandler
	switch challenge.Runner {
	case "simple":
		rh = runner.SimpleRunHandler{}
	case "javut":
		rh = runner.JavaUnitTestHandler{}
	case "outputtest":
		if *tests == "" {
			http.Error(w, "There is no test path provided", http.StatusInternalServerError)
			return
		}
		rh = runner.OutputTestHandler{TestFilePath: *tests}
	default:
		http.Error(w, "Runner not available.", http.StatusInternalServerError)
		return
	}

	config := rh.Handle(w, req)

	// TODO(flowlo): Find out whether Handle completed successfully
	// to check.
	res, err := config.Run()

	if err != nil {
		http.Error(w, "docker: "+err.Error(), http.StatusInternalServerError)
	}

	rh.Respond(w, req, res)
}