Download this file
| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "regexp" |
| 6 | "strings" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/hostactors" |
| 9 | "github.com/carlosframework/platform/internal/hostbox" |
| 10 | "github.com/carlosframework/platform/internal/hostfloor" |
| 11 | ) |
| 12 | |
| 13 | func activationConsoleEnvironment(roster hostactors.Roster, local hostfloor.Enrollment, hostEnv []byte, id string, runtime bool) ([]byte, error) { |
| 14 | env, err := activationEnvironment(hostEnv) |
| 15 | if err != nil { |
| 16 | return nil, err |
| 17 | } |
| 18 | if strings.TrimSpace(env["CARLOS_HOST_CLAIM"]) != "" || env["CARLOS_REGION"] != "" || !regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString(id) { |
| 19 | return nil, errActivation |
| 20 | } |
| 21 | c, ok := roster.Consoles[id] |
| 22 | if !ok || len(c.Namespaces) != 1 || c.Compute == nil || c.Compute.Box != local.Box || c.Compute.Enrollment != local.Enrollment { |
| 23 | return nil, errActivation |
| 24 | } |
| 25 | b, ok := roster.Boxes[local.Box] |
| 26 | 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) { |
| 27 | return nil, errActivation |
| 28 | } |
| 29 | if runtime && (roster.HomeRegion != "ie" || roster.Publication != "published") { |
| 30 | return nil, errActivation |
| 31 | } |
| 32 | flag := "" |
| 33 | if runtime { |
| 34 | flag = "1" |
| 35 | } |
| 36 | return []byte(fmt.Sprintf("CARLOS_CONSOLE_ID=%s\nCONSOLE_HOME_REGION=ie\nCARLOS_HOST_CLAIM=%s\n", id, flag)), nil |
| 37 | } |
| 38 | |