package main import ( "fmt" "oc-auth/conf" "oc-auth/infrastructure" _ "oc-auth/routers" oclib "cloud.o-forge.io/core/oc-lib" "cloud.o-forge.io/core/oc-lib/tools" beego "github.com/beego/beego/v2/server/web" ) const appname = "oc-auth" // @securityDefinitions.apikey Bearer // @in header // @name Authorization // @description Type "Bearer" followed by a space and JWT token. func main() { // Init the oc-lib oclib.Init(appname) // Load the right config file o := oclib.GetConfLoader() conf.GetConfig().PVKPath = o.GetStringDefault("PVK_PATH", "./pvk.pem") conf.GetConfig().ClientSecret = o.GetStringDefault("CLIENT_SECRET", "oc-auth-got-secret") conf.GetConfig().Auth = o.GetStringDefault("AUTH", "hydra") conf.GetConfig().AuthConnectorHost = o.GetStringDefault("AUTH_CONNECTOR_HOST", "localhost") conf.GetConfig().AuthConnectorPort = o.GetIntDefault("AUTH_CONNECTOR_PORT", 4444) conf.GetConfig().AuthConnectorAdminPort = o.GetIntDefault("AUTH_CONNECTOR_ADMIN_PORT", 4445) conf.GetConfig().PermissionConnectorHost = o.GetStringDefault("PERMISSION_CONNECTOR_HOST", "keto") conf.GetConfig().PermissionConnectorPort = o.GetIntDefault("PERMISSION_CONNECTOR_PORT", 4466) conf.GetConfig().PermissionConnectorAdminPort = o.GetIntDefault("PERMISSION_CONNECTOR_ADMIN_PORT", 4467) // config LDAP conf.GetConfig().LDAPEndpoints = o.GetStringDefault("LDAP_ENDPOINTS", "ldap:389") conf.GetConfig().LDAPBindDN = o.GetStringDefault("LDAP_BINDDN", "cn=admin,dc=example,dc=com") conf.GetConfig().LDAPBindPW = o.GetStringDefault("LDAP_BINDPW", "password") conf.GetConfig().LDAPBaseDN = o.GetStringDefault("LDAP_BASEDN", "dc=example,dc=com") conf.GetConfig().LDAPRoleBaseDN = o.GetStringDefault("LDAP_ROLE_BASEDN", "ou=AppRoles,dc=example,dc=com") Discovery() beego.Run() } func Discovery() { fmt.Println("Discovered") api := tools.API{} addPermissions := func(m map[string]interface{}) { conn := infrastructure.GetPermissionConnector() for k, v := range m { for _, p := range v.([]interface{}) { conn.CreatePermission(k, p.(string), true) } } } api.ListenRouter(addPermissions) tools.NewNATSCaller().SetNATSPub("api", tools.DISCOVERY, map[string]interface{}{}) }