oclib -> Generate Peer ID
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
@@ -30,6 +31,7 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
beego "github.com/beego/beego/v2/server/web"
|
beego "github.com/beego/beego/v2/server/web"
|
||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/goraz/onion"
|
"github.com/goraz/onion"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
@@ -60,6 +62,25 @@ const (
|
|||||||
NATIVE_TOOL = tools.NATIVE_TOOL
|
NATIVE_TOOL = tools.NATIVE_TOOL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GenerateNodeID() (string, error) {
|
||||||
|
folderStatic := "/var/lib/opencloud-node"
|
||||||
|
if _, err := os.Stat(folderStatic); err == nil {
|
||||||
|
os.MkdirAll(folderStatic, 0644)
|
||||||
|
}
|
||||||
|
folderStatic += "/node_id"
|
||||||
|
if _, err := os.Stat(folderStatic); os.IsNotExist(err) {
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
id := uuid.NewSHA1(uuid.NameSpaceOID, []byte("oc-"+hostname))
|
||||||
|
err = os.WriteFile(folderStatic, []byte(id.String()), 0644)
|
||||||
|
return id.String(), err
|
||||||
|
}
|
||||||
|
data, err := os.ReadFile(folderStatic)
|
||||||
|
return string(data), err
|
||||||
|
}
|
||||||
|
|
||||||
// will turn into standards api hostnames
|
// will turn into standards api hostnames
|
||||||
func (d LibDataEnum) API() string {
|
func (d LibDataEnum) API() string {
|
||||||
return tools.DefaultAPI[d]
|
return tools.DefaultAPI[d]
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type MockPartner struct {
|
|||||||
groups map[string][]string
|
groups map[string][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abs *MockPartner) RefineResourceByPartnership(peerID string) (resources.ResourceInstanceITF, bool) {
|
func (abs *MockPartner) RefineResourceByPartnership(peerID string) (resources.ResourcePartnerITF, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user