diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.go index 20c7ba292d..8e6450286a 100644 --- a/internal/orchestrator/orchestrator.go +++ b/internal/orchestrator/orchestrator.go @@ -324,13 +324,28 @@ func (or *orchestrator) initPlugins(ctx context.Context) (err error) { for i := 0; i < tokensConfig.ArraySize(); i++ { prefix := tokensConfig.ArrayEntry(i) name := prefix.GetString(tokens.TokensConfigName) - connector := prefix.GetString(tokens.TokensConfigConnector) - if name == "" || connector == "" { + pluginName := prefix.GetString(tokens.TokensConfigPlugin) + if name == "" { return i18n.NewError(ctx, i18n.MsgMissingTokensPluginConfig) } + if pluginName == "" { + // Migration path for old config key + // TODO: eventually make this fatal + pluginName = prefix.GetString(tokens.TokensConfigConnector) + if pluginName == "" { + return i18n.NewError(ctx, i18n.MsgMissingTokensPluginConfig) + } + log.L(ctx).Warnf("Your tokens config uses the deprecated 'connector' key - please change to 'plugin' instead") + } + if pluginName == "https" { + // Migration path for old plugin name + // TODO: eventually make this fatal + log.L(ctx).Warnf("Your tokens config uses the old plugin name 'https' - this plugin has been renamed to 'fftokens'") + pluginName = "fftokens" + } - log.L(ctx).Infof("Loading tokens plugin name=%s connector=%s", name, connector) - plugin, err := tifactory.GetPlugin(ctx, connector) + log.L(ctx).Infof("Loading tokens plugin name=%s plugin=%s", name, pluginName) + plugin, err := tifactory.GetPlugin(ctx, pluginName) if plugin != nil { err = plugin.Init(ctx, name, prefix, &or.bc) } diff --git a/internal/tokens/https/config.go b/internal/tokens/fftokens/config.go similarity index 91% rename from internal/tokens/https/config.go rename to internal/tokens/fftokens/config.go index bef6d815d3..68f53e1aa5 100644 --- a/internal/tokens/https/config.go +++ b/internal/tokens/fftokens/config.go @@ -14,13 +14,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -package https +package fftokens import ( "github.com/hyperledger/firefly/internal/config" "github.com/hyperledger/firefly/internal/wsclient" ) -func (h *HTTPS) InitPrefix(prefix config.PrefixArray) { +func (h *FFTokens) InitPrefix(prefix config.PrefixArray) { wsclient.InitPrefix(prefix) } diff --git a/internal/tokens/https/https.go b/internal/tokens/fftokens/fftokens.go similarity index 89% rename from internal/tokens/https/https.go rename to internal/tokens/fftokens/fftokens.go index 070137f8f6..3ae268cb06 100644 --- a/internal/tokens/https/https.go +++ b/internal/tokens/fftokens/fftokens.go @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package https +package fftokens import ( "context" @@ -30,7 +30,7 @@ import ( "github.com/hyperledger/firefly/pkg/tokens" ) -type HTTPS struct { +type FFTokens struct { ctx context.Context capabilities *tokens.Capabilities callbacks tokens.Callbacks @@ -65,18 +65,17 @@ type createPoolData struct { TransactionID *fftypes.UUID `json:"transactionId"` } -func (h *HTTPS) Name() string { - return "https" +func (h *FFTokens) Name() string { + return "fftokens" } -func (h *HTTPS) Init(ctx context.Context, name string, prefix config.Prefix, callbacks tokens.Callbacks) (err error) { - - h.ctx = log.WithLogField(ctx, "proto", "https") +func (h *FFTokens) Init(ctx context.Context, name string, prefix config.Prefix, callbacks tokens.Callbacks) (err error) { + h.ctx = log.WithLogField(ctx, "proto", "fftokens") h.callbacks = callbacks h.configuredName = name if prefix.GetString(restclient.HTTPConfigURL) == "" { - return i18n.NewError(ctx, i18n.MsgMissingPluginConfig, "url", "tokens.https") + return i18n.NewError(ctx, i18n.MsgMissingPluginConfig, "url", "tokens.fftokens") } h.client = restclient.New(h.ctx, prefix) @@ -95,15 +94,15 @@ func (h *HTTPS) Init(ctx context.Context, name string, prefix config.Prefix, cal return nil } -func (h *HTTPS) Start() error { +func (h *FFTokens) Start() error { return h.wsconn.Connect() } -func (h *HTTPS) Capabilities() *tokens.Capabilities { +func (h *FFTokens) Capabilities() *tokens.Capabilities { return h.capabilities } -func (h *HTTPS) handleReceipt(ctx context.Context, data fftypes.JSONObject) error { +func (h *FFTokens) handleReceipt(ctx context.Context, data fftypes.JSONObject) error { l := log.L(ctx) requestID := data.GetString("id") @@ -121,7 +120,7 @@ func (h *HTTPS) handleReceipt(ctx context.Context, data fftypes.JSONObject) erro return h.callbacks.TokensTxUpdate(h, requestID, updateType, message, data) } -func (h *HTTPS) handleTokenPoolCreate(ctx context.Context, data fftypes.JSONObject) (err error) { +func (h *FFTokens) handleTokenPoolCreate(ctx context.Context, data fftypes.JSONObject) (err error) { packedData := data.GetString("data") tokenType := data.GetString("type") protocolID := data.GetString("poolId") @@ -169,7 +168,7 @@ func (h *HTTPS) handleTokenPoolCreate(ctx context.Context, data fftypes.JSONObje return h.callbacks.TokenPoolCreated(h, pool, operatorAddress, txHash, tx) } -func (h *HTTPS) eventLoop() { +func (h *FFTokens) eventLoop() { defer h.wsconn.Close() l := log.L(h.ctx).WithField("role", "event-loop") ctx := log.WithLogger(h.ctx, l) @@ -219,7 +218,7 @@ func (h *HTTPS) eventLoop() { } } -func (h *HTTPS) CreateTokenPool(ctx context.Context, identity *fftypes.Identity, pool *fftypes.TokenPool) error { +func (h *FFTokens) CreateTokenPool(ctx context.Context, identity *fftypes.Identity, pool *fftypes.TokenPool) error { data := createPoolData{ Namespace: pool.Namespace, Name: pool.Name, diff --git a/internal/tokens/https/https_test.go b/internal/tokens/fftokens/fftokens_test.go similarity index 93% rename from internal/tokens/https/https_test.go rename to internal/tokens/fftokens/fftokens_test.go index f98643d19c..19006bfc13 100644 --- a/internal/tokens/https/https_test.go +++ b/internal/tokens/fftokens/fftokens_test.go @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package https +package fftokens import ( "bytes" @@ -40,7 +40,7 @@ import ( var utConfPrefix = config.NewPluginConfig("tokens").Array() -func newTestHTTPS(t *testing.T) (h *HTTPS, toServer, fromServer chan string, httpURL string, done func()) { +func newTestFFTokens(t *testing.T) (h *FFTokens, toServer, fromServer chan string, httpURL string, done func()) { mockedClient := &http.Client{} httpmock.ActivateNonDefault(mockedClient) @@ -51,18 +51,18 @@ func newTestHTTPS(t *testing.T) (h *HTTPS, toServer, fromServer chan string, htt httpURL = u.String() config.Reset() - h = &HTTPS{} + h = &FFTokens{} h.InitPrefix(utConfPrefix) utConfPrefix.AddKnownKey(tokens.TokensConfigName, "test") - utConfPrefix.AddKnownKey(tokens.TokensConfigConnector, "https") + utConfPrefix.AddKnownKey(tokens.TokensConfigPlugin, "fftokens") utConfPrefix.AddKnownKey(restclient.HTTPConfigURL, httpURL) utConfPrefix.AddKnownKey(restclient.HTTPCustomClient, mockedClient) config.Set("tokens", []fftypes.JSONObject{{}}) err := h.Init(context.Background(), "testtokens", utConfPrefix.ArrayEntry(0), &tokenmocks.Callbacks{}) assert.NoError(t, err) - assert.Equal(t, "https", h.Name()) + assert.Equal(t, "fftokens", h.Name()) assert.Equal(t, "testtokens", h.configuredName) assert.NotNil(t, h.Capabilities()) return h, toServer, fromServer, httpURL, func() { @@ -73,11 +73,11 @@ func newTestHTTPS(t *testing.T) (h *HTTPS, toServer, fromServer chan string, htt func TestInitBadURL(t *testing.T) { config.Reset() - h := &HTTPS{} + h := &FFTokens{} h.InitPrefix(utConfPrefix) utConfPrefix.AddKnownKey(tokens.TokensConfigName, "test") - utConfPrefix.AddKnownKey(tokens.TokensConfigConnector, "https") + utConfPrefix.AddKnownKey(tokens.TokensConfigPlugin, "fftokens") utConfPrefix.AddKnownKey(restclient.HTTPConfigURL, "::::////") err := h.Init(context.Background(), "testtokens", utConfPrefix.ArrayEntry(0), &tokenmocks.Callbacks{}) assert.Regexp(t, "FF10162", err) @@ -85,18 +85,18 @@ func TestInitBadURL(t *testing.T) { func TestInitMissingURL(t *testing.T) { config.Reset() - h := &HTTPS{} + h := &FFTokens{} h.InitPrefix(utConfPrefix) utConfPrefix.AddKnownKey(tokens.TokensConfigName, "test") - utConfPrefix.AddKnownKey(tokens.TokensConfigConnector, "https") + utConfPrefix.AddKnownKey(tokens.TokensConfigPlugin, "fftokens") utConfPrefix.AddKnownKey(restclient.HTTPConfigURL, "") err := h.Init(context.Background(), "testtokens", utConfPrefix.ArrayEntry(0), &tokenmocks.Callbacks{}) assert.Regexp(t, "FF10138", err) } func TestCreateTokenPool(t *testing.T) { - h, _, _, httpURL, done := newTestHTTPS(t) + h, _, _, httpURL, done := newTestFFTokens(t) defer done() pool := &fftypes.TokenPool{ @@ -137,7 +137,7 @@ func TestCreateTokenPool(t *testing.T) { } func TestCreateTokenPoolError(t *testing.T) { - h, _, _, httpURL, done := newTestHTTPS(t) + h, _, _, httpURL, done := newTestFFTokens(t) defer done() pool := &fftypes.TokenPool{ @@ -156,7 +156,7 @@ func TestCreateTokenPoolError(t *testing.T) { } func TestEvents(t *testing.T) { - h, toServer, fromServer, _, done := newTestHTTPS(t) + h, toServer, fromServer, _, done := newTestFFTokens(t) defer done() err := h.Start() @@ -224,7 +224,7 @@ func TestEvents(t *testing.T) { func TestEventLoopReceiveClosed(t *testing.T) { dxc := &tokenmocks.Callbacks{} wsm := &wsmocks.WSClient{} - h := &HTTPS{ + h := &FFTokens{ ctx: context.Background(), callbacks: dxc, wsconn: wsm, @@ -239,7 +239,7 @@ func TestEventLoopReceiveClosed(t *testing.T) { func TestEventLoopSendClosed(t *testing.T) { dxc := &tokenmocks.Callbacks{} wsm := &wsmocks.WSClient{} - h := &HTTPS{ + h := &FFTokens{ ctx: context.Background(), callbacks: dxc, wsconn: wsm, @@ -257,7 +257,7 @@ func TestEventLoopClosedContext(t *testing.T) { wsm := &wsmocks.WSClient{} ctx, cancel := context.WithCancel(context.Background()) cancel() - h := &HTTPS{ + h := &FFTokens{ ctx: ctx, callbacks: dxc, wsconn: wsm, diff --git a/internal/tokens/tifactory/factory.go b/internal/tokens/tifactory/factory.go index b008efa206..22974f9bc5 100644 --- a/internal/tokens/tifactory/factory.go +++ b/internal/tokens/tifactory/factory.go @@ -21,12 +21,12 @@ import ( "github.com/hyperledger/firefly/internal/config" "github.com/hyperledger/firefly/internal/i18n" - "github.com/hyperledger/firefly/internal/tokens/https" + "github.com/hyperledger/firefly/internal/tokens/fftokens" "github.com/hyperledger/firefly/pkg/tokens" ) var plugins = []tokens.Plugin{ - &https.HTTPS{}, + &fftokens.FFTokens{}, } var pluginsByName = make(map[string]tokens.Plugin) @@ -39,6 +39,7 @@ func init() { func InitPrefix(prefix config.PrefixArray) { prefix.AddKnownKey(tokens.TokensConfigConnector) + prefix.AddKnownKey(tokens.TokensConfigPlugin) prefix.AddKnownKey(tokens.TokensConfigName) for _, plugin := range plugins { // Accept a superset of configs allowed by all plugins diff --git a/pkg/tokens/config.go b/pkg/tokens/config.go index 294561a972..2ba581d6bc 100644 --- a/pkg/tokens/config.go +++ b/pkg/tokens/config.go @@ -19,6 +19,8 @@ package tokens const ( // TokensConfigName is the user-supplied name for this token type TokensConfigName = "name" - // TokensConfigConnector is the connector plugin used for this token type - TokensConfigConnector = "connector" + // TokensConfigConnector is the connector plugin used for this token type (deprecated) + TokensConfigConnector = "connector" // TODO: remove + // TokensConfigPlugin is the connector plugin used for this token type + TokensConfigPlugin = "plugin" )