Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: logdog/appengine/coordinator/service.go

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package coordinator 5 package coordinator
6 6
7 import ( 7 import (
8 "sync" 8 "sync"
9 "sync/atomic" 9 "sync/atomic"
10 "time" 10 "time"
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 func (si *googleStorage) Close() { 501 func (si *googleStorage) Close() {
502 if err := si.gs.Close(); err != nil { 502 if err := si.gs.Close(); err != nil {
503 log.WithError(err).Warningf(si.ctx, "Failed to close Google Stor age client.") 503 log.WithError(err).Warningf(si.ctx, "Failed to close Google Stor age client.")
504 } 504 }
505 si.Storage.Close() 505 si.Storage.Close()
506 } 506 }
507 507
508 func (si *googleStorage) GetSignedURLs(c context.Context, req *URLSigningRequest ) (*URLSigningResponse, error) { 508 func (si *googleStorage) GetSignedURLs(c context.Context, req *URLSigningRequest ) (*URLSigningResponse, error) {
509 info, err := si.svc.signer.ServiceInfo(c) 509 info, err := si.svc.signer.ServiceInfo(c)
510 if err != nil { 510 if err != nil {
511 » » return nil, errors.Annotate(err).InternalReason("failed to get s ervice info").Err() 511 » » return nil, errors.Annotate(err, "").InternalReason("failed to g et service info").Err()
512 } 512 }
513 513
514 lifetime := req.Lifetime 514 lifetime := req.Lifetime
515 switch { 515 switch {
516 case lifetime < 0: 516 case lifetime < 0:
517 » » return nil, errors.Reason("invalid signed URL lifetime: %(lifeti me)s").D("lifetime", lifetime).Err() 517 » » return nil, errors.Reason("invalid signed URL lifetime: %s", lif etime).Err()
518 518
519 case lifetime > maxSignedURLLifetime: 519 case lifetime > maxSignedURLLifetime:
520 lifetime = maxSignedURLLifetime 520 lifetime = maxSignedURLLifetime
521 } 521 }
522 522
523 // Get our signing options. 523 // Get our signing options.
524 resp := URLSigningResponse{ 524 resp := URLSigningResponse{
525 Expiration: clock.Now(c).Add(lifetime), 525 Expiration: clock.Now(c).Add(lifetime),
526 } 526 }
527 opts := gcst.SignedURLOptions{ 527 opts := gcst.SignedURLOptions{
528 GoogleAccessID: info.ServiceAccountName, 528 GoogleAccessID: info.ServiceAccountName,
529 SignBytes: func(b []byte) ([]byte, error) { 529 SignBytes: func(b []byte) ([]byte, error) {
530 _, signedBytes, err := si.svc.signer.SignBytes(c, b) 530 _, signedBytes, err := si.svc.signer.SignBytes(c, b)
531 return signedBytes, err 531 return signedBytes, err
532 }, 532 },
533 Method: "GET", 533 Method: "GET",
534 Expires: resp.Expiration, 534 Expires: resp.Expiration,
535 } 535 }
536 536
537 doSign := func(path gs.Path) (string, error) { 537 doSign := func(path gs.Path) (string, error) {
538 url, err := gcst.SignedURL(path.Bucket(), path.Filename(), &opts ) 538 url, err := gcst.SignedURL(path.Bucket(), path.Filename(), &opts )
539 if err != nil { 539 if err != nil {
540 » » » return "", errors.Annotate(err).InternalReason("failed t o sign URL"). 540 » » » return "", errors.Annotate(err, "").InternalReason(
541 » » » » D("bucket", path.Bucket()).D("filename", path.Fi lename).Err() 541 » » » » "failed to sign URL: bucket(%s)/filename(%s)", p ath.Bucket(), path.Filename).Err()
542 } 542 }
543 return url, nil 543 return url, nil
544 } 544 }
545 545
546 // Sign stream URL. 546 // Sign stream URL.
547 if req.Stream { 547 if req.Stream {
548 if resp.Stream, err = doSign(si.stream); err != nil { 548 if resp.Stream, err = doSign(si.stream); err != nil {
549 » » » return nil, errors.Annotate(err).InternalReason("failed to sign stream URL").Err() 549 » » » return nil, errors.Annotate(err, "").InternalReason("fai led to sign stream URL").Err()
550 } 550 }
551 } 551 }
552 552
553 // Sign index URL. 553 // Sign index URL.
554 if req.Index { 554 if req.Index {
555 if resp.Index, err = doSign(si.index); err != nil { 555 if resp.Index, err = doSign(si.index); err != nil {
556 » » » return nil, errors.Annotate(err).InternalReason("failed to sign index URL").Err() 556 » » » return nil, errors.Annotate(err, "").InternalReason("fai led to sign index URL").Err()
557 } 557 }
558 } 558 }
559 559
560 return &resp, nil 560 return &resp, nil
561 } 561 }
OLDNEW
« no previous file with comments | « logdog/appengine/coordinator/endpoints/logs/get.go ('k') | logdog/client/butler/output/logdog/output.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698