Skip to content
Snippets Groups Projects
Select Git revision
  • e96061cc78447cefd83fe955c7fcfa991b25a9b4
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

plugin.go

Blame
  • plugin.go 2.96 KiB
    package info
    
    import (
    	"net/http"
    	"sort"
    	goSync "sync"
    
    	"gitlab.imt-atlantique.fr/i18colle/goshimmer_without_tipselection/plugins/autopeering/local"
    	"gitlab.imt-atlantique.fr/i18colle/goshimmer_without_tipselection/plugins/banner"
    	"gitlab.imt-atlantique.fr/i18colle/goshimmer_without_tipselection/plugins/sync"
    	"gitlab.imt-atlantique.fr/i18colle/goshimmer_without_tipselection/plugins/webapi"
    	"github.com/iotaledger/hive.go/node"
    	"github.com/labstack/echo"
    )
    
    // PluginName is the name of the web API info endpoint plugin.
    const PluginName = "WebAPI info Endpoint"
    
    var (
    	// plugin is the plugin instance of the web API info endpoint plugin.
    	plugin *node.Plugin
    	once   goSync.Once
    )
    
    // Plugin gets the plugin instance.
    func Plugin() *node.Plugin {
    	once.Do(func() {
    		plugin = node.NewPlugin(PluginName, node.Enabled, configure)
    	})
    	return plugin
    }
    
    func configure(_ *node.Plugin) {
    	webapi.Server().GET("info", getInfo)
    }
    
    // getInfo returns the info of the node
    // e.g.,
    // {
    // 	"version":"v0.2.0",
    //  "synchronized": true,
    // 	"identityID":"5bf4aa1d6c47e4ce",
    // 	"publickey":"CjUsn86jpFHWnSCx3NhWfU4Lk16mDdy1Hr7ERSTv3xn9",
    // 	"enabledplugins":[
    // 		"Config",
    // 		"Autopeering",
    // 		"Analysis",
    // 		"WebAPI data Endpoint",
    // 		"WebAPI dRNG Endpoint",
    // 		"MessageLayer",
    // 		"CLI",
    // 		"Database",
    // 		"DRNG",
    // 		"WebAPI autopeering Endpoint",
    // 		"Metrics",
    // 		"PortCheck",
    // 		"Dashboard",
    // 		"WebAPI",
    // 		"WebAPI info Endpoint",
    // 		"WebAPI message Endpoint",
    // 		"Banner",
    // 		"Gossip",
    // 		"Graceful Shutdown",
    // 		"Logger"
    // 	],
    // 	"disabledplugins":[
    // 		"RemoteLog",
    // 		"Spammer",
    // 		"WebAPI Auth"
    // 	]
    // }
    func getInfo(c echo.Context) error {
    	var enabledPlugins []string
    	var disabledPlugins []string
    	for pluginName, plugin := range node.GetPlugins() {
    		if node.IsSkipped(plugin) {
    			disabledPlugins = append(disabledPlugins, pluginName)
    		} else {
    			enabledPlugins = append(enabledPlugins, pluginName)
    		}
    	}
    
    	sort.Strings(enabledPlugins)
    	sort.Strings(disabledPlugins)
    
    	return c.JSON(http.StatusOK, Response{
    		Version:         banner.AppVersion,
    		Synced:          sync.Synced(),
    		IdentityID:      local.GetInstance().Identity.ID().String(),
    		PublicKey:       local.GetInstance().PublicKey().String(),
    		EnabledPlugins:  enabledPlugins,
    		DisabledPlugins: disabledPlugins,
    	})
    }
    
    // Response holds the response of the GET request.
    type Response struct {
    	// version of GoShimmer
    	Version string `json:"version,omitempty"`
    	// whether the node is synchronized
    	Synced bool `json:"synced"`
    	// identity ID of the node encoded in base58 and truncated to its first 8 bytes
    	IdentityID string `json:"identityID,omitempty"`
    	// public key of the node encoded in base58
    	PublicKey string `json:"publicKey,omitempty"`
    	// list of enabled plugins
    	EnabledPlugins []string `json:"enabledPlugins,omitempty"`
    	// list if disabled plugins
    	DisabledPlugins []string `json:"disabledPlugins,omitempty"`
    	// error of the response
    	Error string `json:"error,omitempty"`
    }