Skip to content
Snippets Groups Projects
Select Git revision
  • f9a8cf203e3327094ba32e34c8667fdfefc09e31
  • 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
  • user avatar
    Wolfgang Welz authored and GitHub committed
    f9a8cf20
    History
    plugin.go 2.46 KiB
    package info
    
    import (
    	"net/http"
    
    	"github.com/iotaledger/goshimmer/plugins/autopeering/local"
    	"github.com/iotaledger/goshimmer/plugins/banner"
    	"github.com/iotaledger/goshimmer/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"
    
    // Plugin is the plugin instance of the web API info endpoint plugin.
    var Plugin = node.NewPlugin(PluginName, node.Enabled, configure)
    
    func configure(_ *node.Plugin) {
    	webapi.Server.GET("info", getInfo)
    }
    
    // getInfo returns the info of the node
    // e.g.,
    // {
    // 	"version":"v0.2.0",
    // 	"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"
    // 	],
    // 	"disabledlugins":[
    // 		"Graph",
    // 		"RemoteLog",
    // 		"Spammer",
    // 		"WebAPI Auth"
    // 	]
    // }
    func getInfo(c echo.Context) error {
    	var enabledPlugins []string
    	var disabledPlugins []string
    	for plugin, status := range node.GetPlugins() {
    		switch status {
    		case node.Disabled:
    			disabledPlugins = append(disabledPlugins, plugin)
    		case node.Enabled:
    			enabledPlugins = append(enabledPlugins, plugin)
    		default:
    			continue
    		}
    	}
    
    	return c.JSON(http.StatusOK, Response{
    		Version:         banner.AppVersion,
    		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"`
    	// identity ID of the node encoded in hex 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:"disabledlugins,omitempty"`
    	// error of the response
    	Error string `json:"error,omitempty"`
    }