diff --git a/src/Makefile b/src/Makefile index a76dc4b..fc47037 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,6 +3,11 @@ TOPDIR = $(realpath ..) CPPFLAGS = -Iinclude -I/usr/include/json-c FLAGS = -fPIC -Wall -g + +ifneq ($(CUSTOM_METADATA_ENDPOINT),) +FLAGS += -DCUSTOM_METADATA_ENDPOINT=$(CUSTOM_METADATA_ENDPOINT) +endif + CFLAGS = $(FLAGS) -Wstrict-prototypes CXXFLAGS = $(FLAGS) diff --git a/src/include/oslogin_utils.h b/src/include/oslogin_utils.h index 4a24ecf..ac4bca5 100644 --- a/src/include/oslogin_utils.h +++ b/src/include/oslogin_utils.h @@ -49,8 +49,15 @@ using std::vector; namespace oslogin_utils { // Metadata server URL. +#ifdef CUSTOM_METADATA_ENDPOINT +#define Q(x) #x +#define QUOTE(x) Q(x) +static const char kMetadataServerUrl[] = + "http://" QUOTE(CUSTOM_METADATA_ENDPOINT) "/computeMetadata/v1/oslogin/"; +#else static const char kMetadataServerUrl[] = "http://169.254.169.254/computeMetadata/v1/oslogin/"; +#endif /* CUSTOM_METADATA_ENDPOINT */ // BufferManager encapsulates and manages a buffer and length. This class is not // thread safe.