Loading examples/demo6/golang/main.go +12 −0 Original line number Diff line number Diff line Loading @@ -850,6 +850,9 @@ func process_choice(choice []string) string { scenarios, _ = getListOfScenarios() message = fmt.Sprintf("scenarios: %s", fmt.Sprint(scenarios)) } else if strings.Compare(choice[0], SC) == 0 { if len(choice) == 1 { return fmt.Sprintf("Index is not set") } idx, err := verify_idx_len(choice[1], len(scenarios)) if err != nil { return fmt.Sprintf("Invalid index: %s", err.Error()) Loading @@ -857,6 +860,9 @@ func process_choice(choice []string) string { scenario, _ = getScenario(scenarios[idx].Id) message = fmt.Sprintf("Scenario %s:", fmt.Sprint(scenario)) } else if strings.Compare(choice[0], ACTIVATE) == 0 { if len(choice) == 1 { return fmt.Sprintf("Index is not set") } var err error scenarioId, err = verify_idx_len(choice[1], len(scenarios)) if err != nil { Loading Loading @@ -919,6 +925,9 @@ func process_choice(choice []string) string { } message = fmt.Sprintf("List of UEs %v", ues) } else if strings.Compare(choice[0], INC_UE) == 0 { if len(choice) == 1 { return fmt.Sprintf("Index is not set") } ueId, err := verify_idx_len(choice[1], len(ues)) if err != nil { return fmt.Sprintf("Invalid index: %s", err.Error()) Loading @@ -929,6 +938,9 @@ func process_choice(choice []string) string { } message = fmt.Sprintf("Increase %s, new value: %d", ues[ueId].id, ues[ueId].v) } else if strings.Compare(choice[0], DEC_UE) == 0 { if len(choice) == 1 { return fmt.Sprintf("Index is not set") } ueId, err := verify_idx_len(choice[1], len(ues)) if err != nil { return fmt.Sprintf("Invalid index: %s", err.Error()) Loading go-apps/meep-sandbox-api/server/sandbox_api.go +71 −5 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ const moduleNamespace = "default" var baseKey string const authBasepath = "http://meep-auth-svc//auth/v1" const sbxCtrlUrl = "http://mec-platform.etsi.org" //"http://meep-sandbox-ctrl" const pfmCtrlBasepath = "http://meep-platform-ctrl/platform-ctrl/v1" type SandboxApiConnectors struct { Loading Loading @@ -223,6 +222,17 @@ func Init() (err error) { } log.Info("sandboxApiConnectors.uri: ", sandboxApiConnectors.uri) // hostUrl is the url of the node serving the resourceURL // Retrieve public url address where service is reachable, if not present, use Host URL environment variable sandboxApiConnectors.uri, err = url.Parse(strings.TrimSpace(os.Getenv("MEEP_PUBLIC_URL"))) if err != nil || sandboxApiConnectors.uri == nil || sandboxApiConnectors.uri.String() == "" { sandboxApiConnectors.uri, err = url.Parse(strings.TrimSpace(os.Getenv("MEEP_HOST_URL"))) if err != nil { sandboxApiConnectors.uri = new(url.URL) } } log.Info("sandboxApiConnectors.uri: ", sandboxApiConnectors.uri) sandboxApiConnectors.sessionStore = make(map[string]*sm.Session) sandboxApiConnectors.sandboxCtrlAppClient = make(map[string]*sandboxCtrlClient.APIClient) Loading Loading @@ -305,7 +315,7 @@ func login(w http.ResponseWriter, r *http.Request) { } // Get the query parameter provider provider := q.Get("provider") if provider != "github" { if provider != "github" && provider != "Jupyter2024" { // FXIME FSCOM Debug urpose: bypass authent/Author err := errors.New("Wrong provider Value, only github is permitted") log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) Loading @@ -325,6 +335,63 @@ func login(w http.ResponseWriter, r *http.Request) { metric.Provider = provider metric.User = userId if provider == "Jupyter2024" { // FXIME FSCOM Debug urpose: bypass authent/Author log.Info("Start user session") sandboxName, isNew, _, err, _ := startSession(provider, userId, w, r, createSandbox) if err != nil { log.Error(err.Error()) metricSessionFail.WithLabelValues("Session").Inc() errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } metric.Sandbox = sandboxName _ = sandboxApiConnectors.metricStore.SetSessionMetric(met.SesMetTypeLogin, metric) sandboxCtrlAppClientCfg := sandboxCtrlClient.NewConfiguration() sandboxCtrlAppClientCfg.BasePath = sandboxApiConnectors.uri + "/" + sandboxName + "/sandbox-ctrl/v1" log.Info("sandboxCtrlAppClientCfg.BasePath: ", sandboxCtrlAppClientCfg.BasePath) tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} sandboxCtrlAppClientCfg.HTTPClient = &http.Client{Transport: tr} log.Info("sandboxCtrlAppClientCfg.HTTPClient: ", sandboxCtrlAppClientCfg.HTTPClient) sandboxApiConnectors.sandboxCtrlAppClient[sandboxName] = sandboxCtrlClient.NewAPIClient(sandboxCtrlAppClientCfg) if sandboxApiConnectors.sandboxCtrlAppClient[sandboxName] == nil { log.Error("Failed to create Sandbox Ctrl REST API client") metricSessionFail.WithLabelValues("Session").Inc() _ = processLogout(sandboxName, w, r) w.WriteHeader(http.StatusInternalServerError) return } metricSessionSuccess.Inc() if isNew { metricSessionActive.Inc() } deviceOauth := DeviceOauth{ UserCode: sandboxName, VerificationURI: "", } sandboxInfo := SandboxName{ SandboxName: sandboxName, } jsonResponseToSave, _ := json.Marshal(sandboxInfo) timeInHours := 8 timeInSeconds := timeInHours * 3600 _ = sandboxApiConnectors.rc.JSONSetEntryWithExpiry(baseKey+":"+sandboxName, string(jsonResponseToSave), timeInSeconds) log.Info("Sandbox Info is stored into the Redis DB") // Format response jsonResponse, _ := json.Marshal(deviceOauth) log.Info("Response body: ", string(jsonResponse)) // Send response w.WriteHeader(http.StatusCreated) fmt.Fprint(w, string(jsonResponse)) return } clientID := strings.TrimSpace(os.Getenv("MEEP_OAUTH_GITHUB_CLIENT_ID")) requestUrl := strings.TrimSpace(os.Getenv("MEEP_OAUTH_GITHUB_AUTH_URL")) pollingRequestUrl := strings.TrimSpace(os.Getenv("MEEP_OAUTH_GITHUB_POLL_URL")) Loading Loading @@ -469,7 +536,7 @@ func login(w http.ResponseWriter, r *http.Request) { _ = sandboxApiConnectors.metricStore.SetSessionMetric(met.SesMetTypeLogin, metric) sandboxCtrlAppClientCfg := sandboxCtrlClient.NewConfiguration() sandboxCtrlAppClientCfg.BasePath = sbxCtrlUrl + "/" + sandboxName + "/sandbox-ctrl/v1" sandboxCtrlAppClientCfg.BasePath = sandboxApiConnectors.uri + "/" + sandboxName + "/sandbox-ctrl/v1" log.Info("sandboxCtrlAppClientCfg.BasePath: ", sandboxCtrlAppClientCfg.BasePath) tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} sandboxCtrlAppClientCfg.HTTPClient = &http.Client{Transport: tr} Loading @@ -488,8 +555,7 @@ func login(w http.ResponseWriter, r *http.Request) { metricSessionActive.Inc() } timeInHours := 8 timeInSeconds := timeInHours * 3600 timeInSeconds := 30 _ = sandboxApiConnectors.rc.JSONSetEntryWithExpiry(baseKey+":"+userCode, string(jsonResponseToSave), timeInSeconds) log.Info("Sandbox Info is stored into the Redis DB") Loading Loading
examples/demo6/golang/main.go +12 −0 Original line number Diff line number Diff line Loading @@ -850,6 +850,9 @@ func process_choice(choice []string) string { scenarios, _ = getListOfScenarios() message = fmt.Sprintf("scenarios: %s", fmt.Sprint(scenarios)) } else if strings.Compare(choice[0], SC) == 0 { if len(choice) == 1 { return fmt.Sprintf("Index is not set") } idx, err := verify_idx_len(choice[1], len(scenarios)) if err != nil { return fmt.Sprintf("Invalid index: %s", err.Error()) Loading @@ -857,6 +860,9 @@ func process_choice(choice []string) string { scenario, _ = getScenario(scenarios[idx].Id) message = fmt.Sprintf("Scenario %s:", fmt.Sprint(scenario)) } else if strings.Compare(choice[0], ACTIVATE) == 0 { if len(choice) == 1 { return fmt.Sprintf("Index is not set") } var err error scenarioId, err = verify_idx_len(choice[1], len(scenarios)) if err != nil { Loading Loading @@ -919,6 +925,9 @@ func process_choice(choice []string) string { } message = fmt.Sprintf("List of UEs %v", ues) } else if strings.Compare(choice[0], INC_UE) == 0 { if len(choice) == 1 { return fmt.Sprintf("Index is not set") } ueId, err := verify_idx_len(choice[1], len(ues)) if err != nil { return fmt.Sprintf("Invalid index: %s", err.Error()) Loading @@ -929,6 +938,9 @@ func process_choice(choice []string) string { } message = fmt.Sprintf("Increase %s, new value: %d", ues[ueId].id, ues[ueId].v) } else if strings.Compare(choice[0], DEC_UE) == 0 { if len(choice) == 1 { return fmt.Sprintf("Index is not set") } ueId, err := verify_idx_len(choice[1], len(ues)) if err != nil { return fmt.Sprintf("Invalid index: %s", err.Error()) Loading
go-apps/meep-sandbox-api/server/sandbox_api.go +71 −5 Original line number Diff line number Diff line Loading @@ -66,7 +66,6 @@ const moduleNamespace = "default" var baseKey string const authBasepath = "http://meep-auth-svc//auth/v1" const sbxCtrlUrl = "http://mec-platform.etsi.org" //"http://meep-sandbox-ctrl" const pfmCtrlBasepath = "http://meep-platform-ctrl/platform-ctrl/v1" type SandboxApiConnectors struct { Loading Loading @@ -223,6 +222,17 @@ func Init() (err error) { } log.Info("sandboxApiConnectors.uri: ", sandboxApiConnectors.uri) // hostUrl is the url of the node serving the resourceURL // Retrieve public url address where service is reachable, if not present, use Host URL environment variable sandboxApiConnectors.uri, err = url.Parse(strings.TrimSpace(os.Getenv("MEEP_PUBLIC_URL"))) if err != nil || sandboxApiConnectors.uri == nil || sandboxApiConnectors.uri.String() == "" { sandboxApiConnectors.uri, err = url.Parse(strings.TrimSpace(os.Getenv("MEEP_HOST_URL"))) if err != nil { sandboxApiConnectors.uri = new(url.URL) } } log.Info("sandboxApiConnectors.uri: ", sandboxApiConnectors.uri) sandboxApiConnectors.sessionStore = make(map[string]*sm.Session) sandboxApiConnectors.sandboxCtrlAppClient = make(map[string]*sandboxCtrlClient.APIClient) Loading Loading @@ -305,7 +315,7 @@ func login(w http.ResponseWriter, r *http.Request) { } // Get the query parameter provider provider := q.Get("provider") if provider != "github" { if provider != "github" && provider != "Jupyter2024" { // FXIME FSCOM Debug urpose: bypass authent/Author err := errors.New("Wrong provider Value, only github is permitted") log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) Loading @@ -325,6 +335,63 @@ func login(w http.ResponseWriter, r *http.Request) { metric.Provider = provider metric.User = userId if provider == "Jupyter2024" { // FXIME FSCOM Debug urpose: bypass authent/Author log.Info("Start user session") sandboxName, isNew, _, err, _ := startSession(provider, userId, w, r, createSandbox) if err != nil { log.Error(err.Error()) metricSessionFail.WithLabelValues("Session").Inc() errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } metric.Sandbox = sandboxName _ = sandboxApiConnectors.metricStore.SetSessionMetric(met.SesMetTypeLogin, metric) sandboxCtrlAppClientCfg := sandboxCtrlClient.NewConfiguration() sandboxCtrlAppClientCfg.BasePath = sandboxApiConnectors.uri + "/" + sandboxName + "/sandbox-ctrl/v1" log.Info("sandboxCtrlAppClientCfg.BasePath: ", sandboxCtrlAppClientCfg.BasePath) tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} sandboxCtrlAppClientCfg.HTTPClient = &http.Client{Transport: tr} log.Info("sandboxCtrlAppClientCfg.HTTPClient: ", sandboxCtrlAppClientCfg.HTTPClient) sandboxApiConnectors.sandboxCtrlAppClient[sandboxName] = sandboxCtrlClient.NewAPIClient(sandboxCtrlAppClientCfg) if sandboxApiConnectors.sandboxCtrlAppClient[sandboxName] == nil { log.Error("Failed to create Sandbox Ctrl REST API client") metricSessionFail.WithLabelValues("Session").Inc() _ = processLogout(sandboxName, w, r) w.WriteHeader(http.StatusInternalServerError) return } metricSessionSuccess.Inc() if isNew { metricSessionActive.Inc() } deviceOauth := DeviceOauth{ UserCode: sandboxName, VerificationURI: "", } sandboxInfo := SandboxName{ SandboxName: sandboxName, } jsonResponseToSave, _ := json.Marshal(sandboxInfo) timeInHours := 8 timeInSeconds := timeInHours * 3600 _ = sandboxApiConnectors.rc.JSONSetEntryWithExpiry(baseKey+":"+sandboxName, string(jsonResponseToSave), timeInSeconds) log.Info("Sandbox Info is stored into the Redis DB") // Format response jsonResponse, _ := json.Marshal(deviceOauth) log.Info("Response body: ", string(jsonResponse)) // Send response w.WriteHeader(http.StatusCreated) fmt.Fprint(w, string(jsonResponse)) return } clientID := strings.TrimSpace(os.Getenv("MEEP_OAUTH_GITHUB_CLIENT_ID")) requestUrl := strings.TrimSpace(os.Getenv("MEEP_OAUTH_GITHUB_AUTH_URL")) pollingRequestUrl := strings.TrimSpace(os.Getenv("MEEP_OAUTH_GITHUB_POLL_URL")) Loading Loading @@ -469,7 +536,7 @@ func login(w http.ResponseWriter, r *http.Request) { _ = sandboxApiConnectors.metricStore.SetSessionMetric(met.SesMetTypeLogin, metric) sandboxCtrlAppClientCfg := sandboxCtrlClient.NewConfiguration() sandboxCtrlAppClientCfg.BasePath = sbxCtrlUrl + "/" + sandboxName + "/sandbox-ctrl/v1" sandboxCtrlAppClientCfg.BasePath = sandboxApiConnectors.uri + "/" + sandboxName + "/sandbox-ctrl/v1" log.Info("sandboxCtrlAppClientCfg.BasePath: ", sandboxCtrlAppClientCfg.BasePath) tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} sandboxCtrlAppClientCfg.HTTPClient = &http.Client{Transport: tr} Loading @@ -488,8 +555,7 @@ func login(w http.ResponseWriter, r *http.Request) { metricSessionActive.Inc() } timeInHours := 8 timeInSeconds := timeInHours * 3600 timeInSeconds := 30 _ = sandboxApiConnectors.rc.JSONSetEntryWithExpiry(baseKey+":"+userCode, string(jsonResponseToSave), timeInSeconds) log.Info("Sandbox Info is stored into the Redis DB") Loading