defaults.cc
Go to the documentation of this file.
00001 // Copyright (c) 2017, The Regents of the University of California
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are met:
00006 // * Redistributions of source code must retain the above copyright
00007 //   notice, this list of conditions and the following disclaimer.
00008 // * Redistributions in binary form must reproduce the above copyright
00009 //   notice, this list of conditions and the following disclaimer in the
00010 //   documentation and/or other materials provided with the distribution.
00011 // * Neither the name of the University of California nor the
00012 //   names of its contributors may be used to endorse or promote products
00013 //   derived from this software without specific prior written permission.
00014 //
00015 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00016 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018 // ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF CALIFORNIA
00019 // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00020 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00021 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00023 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00024 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00025 // POSSIBILITY OF SUCH DAMAGE.
00026 
00027 #include "cogrob/cloud/basic/defaults.h"
00028 
00029 #include <stdlib.h>
00030 #include <unistd.h>
00031 
00032 #include <string>
00033 #include "third_party/gflags.h"
00034 
00035 #define AUTO_PLACEHOLDER "__auto__"
00036 
00037 DEFINE_string(grpc_roots, "/opt/cogrob/credentials/grpc_roots.pem",
00038     "gRPC trusted root certificate store path.");
00039 
00040 DEFINE_string(gcloud_cred, "/opt/cogrob/credentials/gcloud_credentials.json",
00041     "Google Cloud APIs credentials json path.");
00042 
00043 DEFINE_string(gcloud_project, AUTO_PLACEHOLDER,
00044     "Google Cloud Platform project name.");
00045 
00046 DEFINE_string(agent, AUTO_PLACEHOLDER, "The name of the robot.");
00047 
00048 namespace cogrob {
00049 namespace cloud {
00050 
00051 void PrepareGoogleCloudCredentials() {
00052   setenv("GRPC_DEFAULT_SSL_ROOTS_FILE_PATH", FLAGS_grpc_roots.c_str(), 0);
00053   setenv("GOOGLE_APPLICATION_CREDENTIALS", FLAGS_gcloud_cred.c_str(), 0);
00054 }
00055 
00056 std::string GetAgentName() {
00057   std::string result = FLAGS_agent;
00058   if (result == AUTO_PLACEHOLDER) {
00059     const int BUF_LEN = 1024;
00060     char hostname[BUF_LEN];
00061     hostname[BUF_LEN - 1] = '\0';
00062     gethostname(hostname, BUF_LEN - 1);
00063     result = hostname;
00064   }
00065   return result;
00066 }
00067 
00068 std::string GetGcloudProjectName() {
00069   std::string result = FLAGS_gcloud_project;
00070   if (result == AUTO_PLACEHOLDER) {
00071     std::string agent_name = GetAgentName();
00072     if (agent_name.find("fetch") == 0 || agent_name.find("freight") == 0 ||
00073         agent_name.find("hsr") == 0) {
00074       result = "cogrob-prod";
00075     } else {
00076       result = "cogrob-devel";
00077     }
00078   }
00079   return result;
00080 }
00081 
00082 }  // namespace cloud
00083 }  // namespace cogrob


gcloud_speech
Author(s):
autogenerated on Thu Jun 6 2019 17:58:03