Added a few checks to rip-gen.go
@@ -36,12 +36,16 @@ const (
var serviceNames = []string{"MessageGatewayService"}
-var desiredAccessibilityAttribute = []string{"PUBLICLY_ANNOUNCED"}
-var avoidedAccessibilityAttribute = []string{"ISOLATED", "RETAIL", "TEST"}
+var desiredAccessibilityAttributes = []string{"PUBLICLY_ANNOUNCED"}
+var avoidedAccessibilityAttributes = []string{"RETAIL", "TEST"}
+var secretAccessibilityAttributes = []string{"ISOLATED"}
var ripConfigJsonFilePath = filepath.Join("agent", "rip", "rip_static_config.json")
var ripUtilFilePath = filepath.Join("agent", "rip", "riputil.go")
+// As of 03/22/21
+var expectedNumOfEndpoints = 27
+
// rip-gen is a simple program that generates the riputil file,
// riputil file contains information about services endpoints.
func main() {
@@ -58,8 +62,9 @@ func main() {
func generateEndpoints(serviceName string, ripConfig AutoGeneratedRipConfigSchema) {
var mapEntries []string
for i, region := range ripConfig.Regions {
- if allStringsInSlice(desiredAccessibilityAttribute, region.AccessibilityAttributes) &&
- !anyStringInSlice(avoidedAccessibilityAttribute, region.AccessibilityAttributes) {
+ if (allStringsInSlice(desiredAccessibilityAttributes, region.AccessibilityAttributes) ||
+ allStringsInSlice(secretAccessibilityAttributes, region.AccessibilityAttributes)) &&
+ !anyStringInSlice(avoidedAccessibilityAttributes, region.AccessibilityAttributes) {
for _, service := range ripConfig.Regions[i].Services {
if service.Name == serviceName && service.Status == serviceStatus {
mapEntries = append(mapEntries, "\""+region.RegionName+"\" :\t\""+service.Endpoint+"\",\n")
@@ -67,6 +72,10 @@ func generateEndpoints(serviceName string, ripConfig AutoGeneratedRipConfigSchem
}
}
}
+ if len(mapEntries) < expectedNumOfEndpoints {
+ fmt.Printf("Error: Expected at least %d endpoints, got %d\n", expectedNumOfEndpoints, len(mapEntries))
+ os.Exit(1)
+ }
sort.Strings(mapEntries)
var newContent bytes.Buffer
@@ -82,13 +91,24 @@ func generateEndpoints(serviceName string, ripConfig AutoGeneratedRipConfigSchem
func replaceFileContents(newContent string, serviceName string) (err error) {
if oldContent, err := ioutil.ReadFile(ripUtilFilePath); err == nil {
parts := strings.Split(string(oldContent), startMarkerPrefix+serviceName)
+ if len(parts) != 2 {
+ fmt.Printf("Error: Cannot generate rip endpoint map code. It is possible that the %s file was manually edited.\n", ripUtilFilePath)
+ os.Exit(1)
+ }
oldContentPart1 := parts[0]
moreParts := strings.Split(string(parts[1]), endMarkerPrefix+serviceName)
+ if len(moreParts) != 2 {
+ fmt.Printf("Error: Cannot generate rip endpoint map code. It is possible that the %s file was manually edited.\n", ripUtilFilePath)
+ os.Exit(1)
+ }
oldContentPart2 := moreParts[1]
fileNewContent := oldContentPart1 + startMarkerPrefix + serviceName + "\n" + newContent + endMarkerPrefix + serviceName + oldContentPart2
if newContentFormatted, err := format.Source([]byte(fileNewContent)); err == nil {
err = ioutil.WriteFile(ripUtilFilePath, newContentFormatted, 0644)
}
+ } else {
+ fmt.Printf("Error: cannot open file %s", ripUtilFilePath)
+ os.Exit(1)
}
return
}
