Add set config for "apigeesync_apid_instance_id"
diff --git a/README.md b/README.md index dc5ce38..bfd1612 100644 --- a/README.md +++ b/README.md
@@ -12,6 +12,12 @@ | apigeesync_consumer_key | string. required. | | apigeesync_consumer_secret | string. required. | +This plugin also populates a configuration item for dependant plugins that may need it: + +| name | description | +|------------------------------|--------------------------| +| apigeesync_apid_instance_id | string | + ### Event Generated * Selector: "ApigeeSync" @@ -33,10 +39,6 @@ 7. Release old DB version 8. Start processing change events -ToDo: ApigeeSync currently only receives a new snapshot during startup, so step #4 only happens once. However, it - will eventually receive snapshots over time and the sub-steps should be followed at that time. Plugins - depending on ApigeeSync for data should assume that it can happen at any time and follow the heuristic below. - #### ApigeeSync-dependent plugins 1. Initialization 1. Until receiving first Snapshot message, ApigeeSync-dependent APIs must either:
diff --git a/init.go b/init.go index ff19bed..7eda269 100644 --- a/init.go +++ b/init.go
@@ -18,6 +18,9 @@ configSnapshotProtocol = "apigeesync_snapshot_proto" configName = "apigeesync_instance_name" ApigeeSyncEventSelector = "ApigeeSync" + + // special value - set by ApigeeSync, not taken from configuration + configApidInstanceID = "apigeesync_apid_instance_id" ) var ( @@ -85,19 +88,24 @@ // set up default database db, err := data.DB() if err != nil { - log.Panicf("Unable to access DB: %v", err) + return pluginData, fmt.Errorf("Unable to access DB: %v", err) } err = initDB(db) if err != nil { - log.Panicf("Unable to initialize DB: %v", err) + return pluginData, fmt.Errorf("Unable to access DB: %v", err) } setDB(db) apidInfo, err = getApidInstanceInfo() if err != nil { - log.Panicf("Unable to get apid instance info: %v", err) + return pluginData, fmt.Errorf("Unable to get apid instance info: %v", err) } + if config.IsSet(configApidInstanceID) { + log.Warnf("ApigeeSync plugin overriding %s.", configApidInstanceID) + } + config.Set(configApidInstanceID, apidInfo.InstanceID) + log.Debug("end init") return pluginData, nil
diff --git a/init_test.go b/init_test.go index 6ff98c2..505502c 100644 --- a/init_test.go +++ b/init_test.go
@@ -9,10 +9,11 @@ Context("Apid Instance display name", func() { - It("should be hostname by defauls", func() { + It("should be hostname by default", func() { initDefaults() Expect(apidInfo.InstanceName).To(Equal("testhost")) }) + It("accept display name from config", func() { config.Set(configName, "aa01") initDefaults() @@ -22,4 +23,10 @@ }) }) + + It("should put apigeesync_apid_instance_id value in config", func() { + instanceID := config.GetString(configApidInstanceID) + Expect(instanceID).NotTo(BeEmpty()) + Expect(instanceID).To(Equal(apidInfo.InstanceID)) + }) })