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

Unified Diff: pkg/appengine/lib/src/api_impl/modules_impl.dart

Issue 804973002: Add appengine/gcloud/mustache dependencies. (Closed) Base URL: git@github.com:dart-lang/pub-dartlang-dart.git@master
Patch Set: Added AUTHORS/LICENSE/PATENTS files Created 6 years 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
Index: pkg/appengine/lib/src/api_impl/modules_impl.dart
diff --git a/pkg/appengine/lib/src/api_impl/modules_impl.dart b/pkg/appengine/lib/src/api_impl/modules_impl.dart
new file mode 100644
index 0000000000000000000000000000000000000000..bc8ed0e14c36e49b15b236ff7d1447a668614e32
--- /dev/null
+++ b/pkg/appengine/lib/src/api_impl/modules_impl.dart
@@ -0,0 +1,132 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library modules_impl;
+
+import 'dart:async';
+
+import 'package:appengine/api/modules.dart';
+
+import '../appengine_context.dart';
+
+import '../../api/errors.dart' as errors;
+import '../protobuf_api/modules_service.dart';
+import '../protobuf_api/rpc/rpc_service.dart';
+import '../protobuf_api/internal/modules_service.pb.dart' as pb;
+
+class ModulesRpcImpl extends ModulesService {
+ final ModulesServiceClientRPCStub _clientRPCStub;
+ final AppengineContext _appengineContext;
+
+ buildModulesException(RpcApplicationError error) {
+ var errorCode = pb.ModulesServiceError_ErrorCode.valueOf(error.code);
+ switch (errorCode) {
+ case pb.ModulesServiceError_ErrorCode.INVALID_MODULE:
+ return new errors.ApplicationError(
+ "Modules error: Invalid module.");
+ case pb.ModulesServiceError_ErrorCode.INVALID_VERSION:
+ return new errors.ApplicationError(
+ "Modules error: Invalid version.");
+ case pb.ModulesServiceError_ErrorCode.INVALID_INSTANCES:
+ return new errors.ApplicationError(
+ "Modules error: Invalid instance.");
+ case pb.ModulesServiceError_ErrorCode.TRANSIENT_ERROR:
+ return new errors.ApplicationError(
+ "Modules error: Transient error.");
+ case pb.ModulesServiceError_ErrorCode.UNEXPECTED_STATE:
+ return new errors.ApplicationError(
+ "Modules error: Unexpected state.");
+ default:
+ return error;
+ }
+ }
+
+ ModulesRpcImpl(RPCService rpcService,
+ AppengineContext this._appengineContext,
+ String ticket)
+ : _clientRPCStub = new ModulesServiceClientRPCStub(rpcService, ticket) {
+ }
+
+ String get currentModule {
+ return _appengineContext.module;
+ }
+
+ String get currentVersion {
+ return _appengineContext.version;
+ }
+
+ String get currentInstance {
+ return _appengineContext.instance;
+ }
+
+ Future<String> defaultVersion(String module) {
+ var request = new pb.GetDefaultVersionRequest();
+ request..module = module;
+ return _clientRPCStub.GetDefaultVersion(request)
+ .then((response) => response.version)
+ .catchError((RpcApplicationError error) {
+ throw buildModulesException(error);
+ }, test: (error) => error is RpcApplicationError);
+ }
+
+ Future<List<String>> modules() {
+ var request = new pb.GetModulesRequest();
+ return _clientRPCStub.GetModules(request)
+ .then((response) => response.module)
+ .catchError((RpcApplicationError error) {
+ throw buildModulesException(error);
+ }, test: (error) => error is RpcApplicationError);
+ }
+
+ Future<List<String>> versions(String module) {
+ var request = new pb.GetVersionsRequest();
+ request.module = module;
+ return _clientRPCStub.GetVersions(request)
+ .then((response) => response.version)
+ .catchError((RpcApplicationError error) {
+ throw buildModulesException(error);
+ }, test: (error) => error is RpcApplicationError);
+ }
+
+ Future<String> hostname([String module, String version, String instance]) {
+ // Maps double-wildcard domains hosted at appspot.com as Google is
+ // issuing certificates for SSL certificates for double-wildcard
+ // domains hosted at appspot.com (i.e. *.*.appspot.com).
+ //
+ // It performs mapping like this:
+ //
+ // project.appspot.com -> project.appspot.com
+ // version.project.appspot.com -> version-dot-project.appspot.com
+ // version.module.project.appspot.com ->
+ // version-dot-module-dot-project.appspot.com
+ String mapHostname(String hostname) {
+ const appSpotDotCom = '.appspot.com';
+ if (hostname.endsWith(appSpotDotCom)) {
+ var lastDotindex = hostname.length - appSpotDotCom.length;
+ if (hostname.indexOf('.') < lastDotindex) {
+ return hostname.substring(0, lastDotindex)
+ .split('.')
+ .join('-dot-')
+ + appSpotDotCom;
+ }
+ }
+ return hostname;
+ }
+ var request = new pb.GetHostnameRequest();
+ if (module != null) {
+ request.module = module;
+ }
+ if (version != null) {
+ request.version = version;
+ }
+ if (instance != null) {
+ request.instance = instance;
+ }
+ return _clientRPCStub.GetHostname(request)
+ .then((response) => mapHostname(response.hostname))
+ .catchError((RpcApplicationError error) {
+ throw buildModulesException(error);
+ }, test: (error) => error is RpcApplicationError);
+ }
+}
« no previous file with comments | « pkg/appengine/lib/src/api_impl/logging_impl.dart ('k') | pkg/appengine/lib/src/api_impl/raw_datastore_v3_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698