Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 }
00083 }