defaults.cc
Go to the documentation of this file.
1 // Copyright (c) 2017, The Regents of the University of California
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of the University of California nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF CALIFORNIA
19 // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
26 
28 
29 #include <stdlib.h>
30 #include <unistd.h>
31 
32 #include <string>
33 #include "third_party/gflags.h"
34 
35 #define AUTO_PLACEHOLDER "__auto__"
36 
37 DEFINE_string(grpc_roots, "/opt/cogrob/credentials/grpc_roots.pem",
38  "gRPC trusted root certificate store path.");
39 
40 DEFINE_string(gcloud_cred, "/opt/cogrob/credentials/gcloud_credentials.json",
41  "Google Cloud APIs credentials json path.");
42 
43 DEFINE_string(gcloud_project, AUTO_PLACEHOLDER,
44  "Google Cloud Platform project name.");
45 
46 DEFINE_string(agent, AUTO_PLACEHOLDER, "The name of the robot.");
47 
48 namespace cogrob {
49 namespace cloud {
50 
52  setenv("GRPC_DEFAULT_SSL_ROOTS_FILE_PATH", FLAGS_grpc_roots.c_str(), 0);
53  setenv("GOOGLE_APPLICATION_CREDENTIALS", FLAGS_gcloud_cred.c_str(), 0);
54 }
55 
56 std::string GetAgentName() {
57  std::string result = FLAGS_agent;
58  if (result == AUTO_PLACEHOLDER) {
59  const int BUF_LEN = 1024;
60  char hostname[BUF_LEN];
61  hostname[BUF_LEN - 1] = '\0';
62  gethostname(hostname, BUF_LEN - 1);
63  result = hostname;
64  }
65  return result;
66 }
67 
68 std::string GetGcloudProjectName() {
69  std::string result = FLAGS_gcloud_project;
70  if (result == AUTO_PLACEHOLDER) {
71  std::string agent_name = GetAgentName();
72  if (agent_name.find("fetch") == 0 || agent_name.find("freight") == 0 ||
73  agent_name.find("hsr") == 0) {
74  result = "cogrob-prod";
75  } else {
76  result = "cogrob-devel";
77  }
78  }
79  return result;
80 }
81 
82 } // namespace cloud
83 } // namespace cogrob
std::string GetAgentName()
Definition: defaults.cc:56
std::string GetGcloudProjectName()
Definition: defaults.cc:68
DEFINE_string(grpc_roots,"/opt/cogrob/credentials/grpc_roots.pem","gRPC trusted root certificate store path.")
#define AUTO_PLACEHOLDER
Definition: defaults.cc:35
void PrepareGoogleCloudCredentials()
Definition: defaults.cc:51


gcloud_speech
Author(s):
autogenerated on Wed Jun 5 2019 21:24:06