package host import ( "fmt" "regexp" "strings" "github.com/carlosframework/platform/internal/hostactors" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostfloor" ) func activationConsoleEnvironment(roster hostactors.Roster, local hostfloor.Enrollment, hostEnv []byte, id string, runtime bool) ([]byte, error) { env, err := activationEnvironment(hostEnv) if err != nil { return nil, err } if strings.TrimSpace(env["CARLOS_HOST_CLAIM"]) != "" || env["CARLOS_REGION"] != "" || !regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString(id) { return nil, errActivation } c, ok := roster.Consoles[id] if !ok || len(c.Namespaces) != 1 || c.Compute == nil || c.Compute.Box != local.Box || c.Compute.Enrollment != local.Enrollment { return nil, errActivation } b, ok := roster.Boxes[local.Box] if !ok || b.State != "active" || b.Enrollment != local.Enrollment || b.Cloud.InstanceID != local.InstanceID || b.Region != "ie" || b.Cloud.Region != "eu-west-1" || roster.RequestLimitNS != int64(hostbox.RequestLimit) { return nil, errActivation } if runtime && (roster.HomeRegion != "ie" || roster.Publication != "published") { return nil, errActivation } flag := "" if runtime { flag = "1" } return []byte(fmt.Sprintf("CARLOS_CONSOLE_ID=%s\nCONSOLE_HOME_REGION=ie\nCARLOS_HOST_CLAIM=%s\n", id, flag)), nil }