update
This commit is contained in:
@@ -280,7 +280,7 @@ func (cli *Client) connect(ctx context.Context) <-chan conn {
|
||||
|
||||
cn, err := cli.connector.Connect(ctx, addr)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to create a LDAP connection", "address", addr)
|
||||
fmt.Println("Failed to create a LDAP connection", "address", addr, err)
|
||||
return
|
||||
}
|
||||
select {
|
||||
|
||||
25
main.go
25
main.go
@@ -19,6 +19,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/beego/v2/server/web/filter/cors"
|
||||
"github.com/i-core/rlog"
|
||||
)
|
||||
|
||||
const appname = "oc-auth"
|
||||
@@ -79,6 +80,7 @@ func generateRole() {
|
||||
}()
|
||||
// if from ldap, create roles from ldap
|
||||
if conf.GetConfig().SourceMode == "ldap" {
|
||||
for {
|
||||
ldap := auth_connectors.New()
|
||||
roles, err := ldap.GetRoles(context.Background())
|
||||
if err == nil {
|
||||
@@ -91,9 +93,11 @@ func generateRole() {
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
} else {
|
||||
time.Sleep(10 * time.Second) // Pause execution for 10 seconds
|
||||
generateRole()
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +108,8 @@ func generateSelfPeer() error {
|
||||
fmt.Println("Recovered in f", r)
|
||||
}
|
||||
}()
|
||||
log := rlog.FromContext(context.Background()).Sugar()
|
||||
for {
|
||||
// TODO check if files at private & public path are set
|
||||
// check if files at private & public path are set
|
||||
if _, err := os.Stat(conf.GetConfig().PrivateKeyPath); errors.Is(err, os.ErrNotExist) {
|
||||
@@ -117,7 +123,9 @@ func generateSelfPeer() error {
|
||||
file := ""
|
||||
f, err := os.ReadFile(conf.GetConfig().PublicKeyPath)
|
||||
if err != nil {
|
||||
return err
|
||||
time.Sleep(10 * time.Second)
|
||||
log.Error(err)
|
||||
continue
|
||||
}
|
||||
file = string(f)
|
||||
if len(p.Data) > 0 {
|
||||
@@ -142,9 +150,12 @@ func generateSelfPeer() error {
|
||||
data := oclib.NewRequest(oclib.LibDataEnum(oclib.PEER), "", "", []string{}, nil).StoreOne(peer.Serialize(peer))
|
||||
if data.Err != "" {
|
||||
time.Sleep(10 * time.Second) // Pause execution for 10 seconds
|
||||
generateSelfPeer()
|
||||
return errors.New(data.Err)
|
||||
log.Error(err)
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -154,14 +165,14 @@ func discovery() {
|
||||
fmt.Println("Recovered in f", r)
|
||||
}
|
||||
}()
|
||||
for {
|
||||
api := tools.API{}
|
||||
conn := infrastructure.GetPermissionConnector("")
|
||||
fmt.Println("AdminRole", conn, conf.GetConfig().PermissionConnectorWriteHost)
|
||||
_, _, err := conn.CreateRole(conf.GetConfig().AdminRole)
|
||||
if err != nil {
|
||||
time.Sleep(10 * time.Second) // Pause execution for 10 seconds
|
||||
discovery()
|
||||
return
|
||||
continue
|
||||
}
|
||||
conn.BindRole(conf.GetConfig().AdminRole, "admin")
|
||||
addPermissions := func(m map[string]interface{}) {
|
||||
@@ -173,4 +184,6 @@ func discovery() {
|
||||
}
|
||||
api.ListenRouter(addPermissions)
|
||||
tools.NewNATSCaller().SetNATSPub("api", tools.DISCOVERY, map[string]interface{}{})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user