[cloud] Add a more lightweight version of Config.

It initializes ONLY core services (currently datastore and portion of 'info'
service used by the datastore). Logging, auth, request state, etc is untouched.

The existing Config seems to be pretty tangled up with Cloud Logging which we
do not want to use.

R=tandrii@chromium.org
BUG=959427

Change-Id: I90cae7beb2f8a5a7f1f5dfce48928b030afad546
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/gae/+/1669864
Commit-Queue: Vadim Shtayura <vadimsh@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/impl/cloud/context.go b/impl/cloud/context.go
index 3dba80c..c8f8ccb 100644
--- a/impl/cloud/context.go
+++ b/impl/cloud/context.go
@@ -232,11 +232,16 @@
 	}
 
 	// Setup and install the "info" service.
-	gi := serviceInstanceGlobalInfo{
-		Config:  cfg,
-		Request: req,
-	}
-	c = useInfo(c, &gi)
+	c = useInfo(c, &serviceInstanceGlobalInfo{
+		IsDev:              cfg.IsDev,
+		ProjectID:          cfg.ProjectID,
+		ServiceName:        cfg.ServiceName,
+		VersionName:        cfg.VersionName,
+		InstanceID:         cfg.InstanceID,
+		RequestID:          req.TraceID,
+		ServiceAccountName: cfg.ServiceAccountName,
+		ServiceProvider:    cfg.ServiceProvider,
+	})
 
 	// datastore service
 	if cfg.DS != nil {
diff --git a/impl/cloud/context_lite.go b/impl/cloud/context_lite.go
new file mode 100644
index 0000000..274e398
--- /dev/null
+++ b/impl/cloud/context_lite.go
@@ -0,0 +1,130 @@
+// Copyright 2019 The LUCI Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cloud
+
+import (
+	"cloud.google.com/go/datastore"
+	"github.com/bradfitz/gomemcache/memcache"
+	"golang.org/x/net/context"
+
+	"go.chromium.org/gae/impl/dummy"
+	ds "go.chromium.org/gae/service/datastore"
+	"go.chromium.org/gae/service/mail"
+	mc "go.chromium.org/gae/service/memcache"
+	"go.chromium.org/gae/service/module"
+	"go.chromium.org/gae/service/taskqueue"
+	"go.chromium.org/gae/service/user"
+)
+
+// ConfigLite can be used to configure a context to have supported Cloud
+// Services clients and ONLY them.
+//
+// Currently supports only datastore and its required dependencies.
+//
+// Unlike Config, it doesn't try to setup logging, intercept HTTP requests,
+// provide auth, etc.
+type ConfigLite struct {
+	// IsDev is true if this is a development execution.
+	IsDev bool
+
+	// ProjectID, if not empty, is the project ID returned by the "info" service.
+	//
+	// If empty, the service will treat requests for this field as not
+	// implemented.
+	ProjectID string
+
+	// ServiceName, if not empty, is the service (module) name returned by the
+	// "info" service.
+	//
+	// If empty, the service will treat requests for this field as not
+	// implemented.
+	ServiceName string
+
+	// VersionName, if not empty, is the version name returned by the "info"
+	// service.
+	//
+	// If empty, the service will treat requests for this field as not
+	// implemented.
+	VersionName string
+
+	// InstanceID, if not empty, is the instance ID returned by the "info"
+	// service.
+	//
+	// If empty, the service will treat requests for this field as not
+	// implemented.
+	InstanceID string
+
+	// RequestID, if not empty, is the request ID returned by the "info"
+	// service.
+	//
+	// If empty, the service will treat requests for this field as not
+	// implemented.
+	RequestID string
+
+	// ServiceAccountName, if not empty, is the service account name returned by
+	// the "info" service.
+	//
+	// If empty, the service will treat requests for this field as not
+	// implemented.
+	ServiceAccountName string
+
+	// DS is the Cloud Datastore client.
+	//
+	// If populated, the datastore service will be installed.
+	DS *datastore.Client
+
+	// MC is the memcache service client.
+	//
+	// If populated, the memcache service will be installed.
+	MC *memcache.Client
+}
+
+// Use configures the context with implementation of Cloud Services.
+//
+// Any services that are missing will have "impl/dummy" stubs installed. These
+// stubs will panic if called.
+func (cfg *ConfigLite) Use(c context.Context) context.Context {
+	// Dummy services that we don't support.
+	c = mail.Set(c, dummy.Mail())
+	c = module.Set(c, dummy.Module())
+	c = taskqueue.SetRaw(c, dummy.TaskQueue())
+	c = user.Set(c, dummy.User())
+
+	c = useInfo(c, &serviceInstanceGlobalInfo{
+		IsDev:              cfg.IsDev,
+		ProjectID:          cfg.ProjectID,
+		ServiceName:        cfg.ServiceName,
+		VersionName:        cfg.VersionName,
+		InstanceID:         cfg.InstanceID,
+		RequestID:          cfg.RequestID,
+		ServiceAccountName: cfg.ServiceAccountName,
+	})
+
+	if cfg.DS != nil {
+		cds := cloudDatastore{client: cfg.DS}
+		c = cds.use(c)
+	} else {
+		c = ds.SetRaw(c, dummy.Datastore())
+	}
+
+	if cfg.MC != nil {
+		mc := memcacheClient{client: cfg.MC}
+		c = mc.use(c)
+	} else {
+		c = mc.SetRaw(c, dummy.Memcache())
+	}
+
+	return c
+}
diff --git a/impl/cloud/info.go b/impl/cloud/info.go
index 2a95c0d..f6ebc8b 100644
--- a/impl/cloud/info.go
+++ b/impl/cloud/info.go
@@ -27,8 +27,14 @@
 // serviceInstanceGlobalInfo is the set of base, immutable info service values.
 // These are initialized when the service instance is instantiated.
 type serviceInstanceGlobalInfo struct {
-	*Config
-	*Request
+	IsDev              bool
+	ProjectID          string
+	ServiceName        string
+	VersionName        string
+	InstanceID         string
+	RequestID          string
+	ServiceAccountName string
+	ServiceProvider    ServiceProvider
 }
 
 // infoState is the state of the "service/info" service in the current Context.
@@ -90,14 +96,14 @@
 
 func (*infoService) Datacenter() string             { panic(ErrNotImplemented) }
 func (*infoService) DefaultVersionHostname() string { panic(ErrNotImplemented) }
-func (i *infoService) InstanceID() string           { return maybe(i.Config.InstanceID) }
+func (i *infoService) InstanceID() string           { return maybe(i.infoState.InstanceID) }
 func (*infoService) IsOverQuota(err error) bool     { return false }
 func (*infoService) IsTimeoutError(err error) bool  { return false }
 func (*infoService) ModuleHostname(module, version, instance string) (string, error) {
 	return "", ErrNotImplemented
 }
 func (i *infoService) ModuleName() string   { return maybe(i.ServiceName) }
-func (i *infoService) RequestID() string    { return maybe(i.TraceID) }
+func (i *infoService) RequestID() string    { return maybe(i.infoState.RequestID) }
 func (*infoService) ServerSoftware() string { panic(ErrNotImplemented) }
 func (i *infoService) VersionID() string    { return maybe(i.VersionName) }
 
diff --git a/impl/cloud/info_test.go b/impl/cloud/info_test.go
index 539c29d..36e6dae 100644
--- a/impl/cloud/info_test.go
+++ b/impl/cloud/info_test.go
@@ -34,18 +34,14 @@
 		const maxNamespaceLen = 100
 
 		gi := serviceInstanceGlobalInfo{
-			Config: &Config{
-				IsDev:              false,
-				ProjectID:          "project-id",
-				ServiceName:        "service-name",
-				VersionName:        "version-name",
-				InstanceID:         "instance-id",
-				ServiceAccountName: "service-account@example.com",
-				ServiceProvider:    nil,
-			},
-			Request: &Request{
-				TraceID: "trace",
-			},
+			IsDev:              false,
+			ProjectID:          "project-id",
+			ServiceName:        "service-name",
+			VersionName:        "version-name",
+			InstanceID:         "instance-id",
+			ServiceAccountName: "service-account@example.com",
+			ServiceProvider:    nil,
+			RequestID:          "trace",
 		}
 		c := useInfo(context.Background(), &gi)