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

Unified Diff: scheduler/appengine/task/buildbucket/buildbucket.go

Issue 2991213003: scheduler: Make 'https://' optional in 'server' config field. (Closed)
Patch Set: Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | scheduler/appengine/task/buildbucket/buildbucket_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scheduler/appengine/task/buildbucket/buildbucket.go
diff --git a/scheduler/appengine/task/buildbucket/buildbucket.go b/scheduler/appengine/task/buildbucket/buildbucket.go
index 5d875739625ecf8f9e90a37d3f50271da07f537a..9f456df0f559fb8dba350bb7a347d33216586c39 100644
--- a/scheduler/appengine/task/buildbucket/buildbucket.go
+++ b/scheduler/appengine/task/buildbucket/buildbucket.go
@@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"net/url"
+ "strings"
"time"
"github.com/golang/protobuf/proto"
@@ -61,6 +62,13 @@ func (m TaskManager) Traits() task.Traits {
}
}
+func normalizeServerURL(s string) string {
+ if strings.HasPrefix(s, "https://") || strings.HasPrefix(s, "http://") {
+ return s
+ }
+ return "https://" + s
+}
+
// ValidateProtoMessage is part of Manager interface.
func (m TaskManager) ValidateProtoMessage(msg proto.Message) error {
cfg, ok := msg.(*messages.BuildbucketTask)
@@ -75,7 +83,7 @@ func (m TaskManager) ValidateProtoMessage(msg proto.Message) error {
if cfg.Server == "" {
return fmt.Errorf("field 'server' is required")
}
- u, err := url.Parse(cfg.Server)
+ u, err := url.Parse(normalizeServerURL(cfg.Server))
if err != nil {
return fmt.Errorf("invalid URL %q: %s", cfg.Server, err)
}
@@ -164,8 +172,9 @@ func (m TaskManager) LaunchTask(c context.Context, ctl task.Controller) error {
// Make sure Buildbucket can publish PubSub messages, grab token that would
// identify this invocation when receiving PubSub notifications.
- ctl.DebugLog("Preparing PubSub topic for %q", cfg.Server)
- topic, authToken, err := ctl.PrepareTopic(c, cfg.Server)
+ serverURL := normalizeServerURL(cfg.Server)
+ ctl.DebugLog("Preparing PubSub topic for %q", serverURL)
+ topic, authToken, err := ctl.PrepareTopic(c, serverURL)
if err != nil {
ctl.DebugLog("Failed to prepare PubSub topic - %s", err)
return err
@@ -284,7 +293,7 @@ func (m TaskManager) createBuildbucketService(c context.Context, ctl task.Contro
return nil, err
}
cfg := ctl.Task().(*messages.BuildbucketTask)
- service.BasePath = cfg.Server + "/_ah/api/buildbucket/v1/"
+ service.BasePath = normalizeServerURL(cfg.Server) + "/_ah/api/buildbucket/v1/"
return service, nil
}
« no previous file with comments | « no previous file | scheduler/appengine/task/buildbucket/buildbucket_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698