func authorizeByAPIToken(req *wcg.Request) { tokenString := req.Header(request.APITokenHeader) if !lib.IsOnGAE() && !lib.IsProduction() && tokenString == string(request.APITestUser.Token) { req.User = request.APITestUser return } if !wcg.IsUUID(tokenString) { // Do not access APIToken entity if it's not a valid UUID. return } _, ent, err := entities.APIToken.Get().Key(tokenString).Cache(true).One(req) if err == nil { req.User = &request.APITokenUser{ent.(*models.APIToken)} return } }
func (email *EmailNotification) Deliver(req *wcg.Request) error { sender := configs.GetValue(req, "notifications.sender") if sender == "" { return fmt.Errorf("notifications.sender is empty.") } msg := &mail.Message{ Sender: sender, To: email.To, Subject: email.Subject, Body: email.Body, } if !lib.IsProduction() { msg.Subject = fmt.Sprintf("[Non-Prod]%s", msg.Subject) } if err := gae.SendMail(req, msg); err != nil { return err } if lib.IsOnLocalGAE() { req.Logger.Debugf("Email Content:\n%s", email.Body) } return nil }
func _syncArtistProfiles(req *wcg.Request) ([]*datastore.Key, []*hplink.Artist, error) { req.Logger.Infof("Importing the artist list") sourceList, err := crawlers.NewHelloProject(urlfetch.NewHTTPClient(req)).Run() if err != nil { return nil, nil, err } if len(sourceList) == 0 { return nil, nil, errSyncNoArtistInfo } keys := make([]string, len(sourceList)) for i, source := range sourceList { keys[i] = source.Key } dskeys, _list := entities.Artist.GetMulti().Keys(keys...).UseDefaultIfNil(true).MustList(req) list := _list.([]*hplink.Artist) for i, source := range sourceList { list[i].Index = source.Index list[i].Key = source.Key list[i].Name = source.Name list[i].Thumbnail = models.Image{ URL: source.ImageURL, } } if lib.IsProduction() { if cacher, err := cacheutil.NewImageCacher(req, entities.ImageCache); err == nil { for i, source := range sourceList { cache, err := cacher.Cache(source.ImageURL) if err != nil { req.Logger.Warnf("Image cache failed: %v", err) } else { list[i].Thumbnail = *cache.ToImage() } } } } entities.Artist.PutMulti().DatastoreKeys(dskeys...).Cache(ckAllArtits).MustUpdate(req, list) return dskeys, list, nil }