Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5968,6 +5968,23 @@ func GetEnvironments(ctx context.Context, orgId string) ([]Environment, error) {
}
}

//Check if this is suborg and get parent org environments if it distributed
foundOrg, err := GetOrg(ctx, orgId)
if err == nil && len(foundOrg.ChildOrgs) == 0 && len(foundOrg.CreatorOrg) > 0 && foundOrg.CreatorOrg != orgId {
parentOrg, err := GetOrg(ctx, foundOrg.CreatorOrg)
if err == nil {
parentEnvs, err := GetEnvironments(ctx, parentOrg.Id)
if err == nil {
for _, parentEnv := range parentEnvs {
if !ArrayContains(parentEnv.SuborgDistribution, orgId) {
continue
}
environments = append(environments, parentEnv)
}
}
}
}

// Fixing environment return search problems
timenow := time.Now().Unix()
for envIndex, env := range environments {
Expand Down
113 changes: 112 additions & 1 deletion shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,7 @@ func HandleSetEnvironments(resp http.ResponseWriter, request *http.Request) {
}

item.RunningIp = ""
if item.OrgId != user.ActiveOrg.Id {
if item.OrgId != user.ActiveOrg.Id && len(item.SuborgDistribution) == 0 {
item.OrgId = user.ActiveOrg.Id
}

Expand Down Expand Up @@ -3322,6 +3322,10 @@ func HandleGetEnvironments(resp http.ResponseWriter, request *http.Request) {
newEnvironments[envIndex].Licensed = false
newEnvironments[envIndex].DataLake.Enabled = false
}

if len(env.SuborgDistribution) != 0 {
newEnvironments[envIndex].SuborgDistribution = env.SuborgDistribution
}
}

newjson, err := json.Marshal(newEnvironments)
Expand Down Expand Up @@ -28274,6 +28278,113 @@ func HandleGetenvStats(resp http.ResponseWriter, request *http.Request) {
resp.Write([]byte(fmt.Sprintf(`{"success": true}`)))
}

func HandleSetenvConfig(resp http.ResponseWriter, request *http.Request) {

cors := HandleCors(resp, request)
if cors {
return
}

user, err := HandleApiAuthentication(resp, request)
if err != nil {
log.Printf("[AUDIT] Api authentication failed in set env config: %s", err)
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}

if user.Role != "admin" {
log.Printf("[AUDIT] User isn't admin during set env config")
resp.WriteHeader(409)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Must be admin to perform this action"}`)))
return
}

ctx := GetContext(request)

var environmentId string
location := strings.Split(request.URL.String(), "/")
if location[1] == "api" {
if len(location) <= 4 {
log.Printf("Path too short: %d", len(location))
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}

environmentId = location[4]
}

if len(environmentId) == 0 {
log.Printf("[Error] No environment ID found in path")
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}

type environmentConfig struct {
Action string `json:"action"`
SelectedSuborg []string `json:"selected_suborgs"`
}

var config environmentConfig

body, err := ioutil.ReadAll(request.Body)
if err != nil {
log.Printf("[Error] Failed reading body in set env config: %s", err)
resp.WriteHeader(500)
resp.Write([]byte(`{"success": false}`))
return
}

err = json.Unmarshal(body, &config)
if err != nil {
log.Printf("[Error] Failed unmarshalling body in set env config: %s", err)
resp.WriteHeader(500)
resp.Write([]byte(`{"success": false}`))
return
}

environment, err := GetEnvironment(ctx, environmentId, user.ActiveOrg.Id)
if err != nil {
log.Printf("[Error] Failed getting environment in set env config: %s for Id: %s", err, environmentId)
resp.WriteHeader(500)
resp.Write([]byte(`{"success": false}`))
return
}

if config.Action == "suborg_distribute" {

if len(config.SelectedSuborg) == 0 {
environment.SuborgDistribution = []string{}
} else {
environment.SuborgDistribution = config.SelectedSuborg
}

err = SetEnvironment(ctx, environment)
if err != nil {
log.Printf("[Error] Failed setting environment in set env config: %s", err)
resp.WriteHeader(500)
resp.Write([]byte(`{"success": false}`))
return
}

foundOrg, err := GetOrg(ctx, user.ActiveOrg.Id)
if err == nil {
for _, childOrg := range foundOrg.ChildOrgs {
nameKey := "Environments"
cacheKey := fmt.Sprintf("%s_%s", nameKey, childOrg.Id)
DeleteCache(ctx, cacheKey)
}
}

log.Printf("[INFO] Successfully updated environment in set env config for environment id: %s", environmentId)
resp.WriteHeader(200)
resp.Write([]byte(`{"success": true, "reason" : "Successfully updated environment"}`))

}
}

func GetWorkflowSuggestions(ctx context.Context, user User, org *Org, orgUpdated bool, amount int) (*Org, bool) {
// Loop workflows

Expand Down
2 changes: 2 additions & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ type Environment struct {
Licensed bool `json:"licensed" datastore:"licensed"`
RunType string `json:"run_type" datastore:"run_type"`
DataLake LakeConfig `json:"data_lake" datastore:"data_lake"`

SuborgDistribution []string `json:"suborg_distribution" datastore:"suborg_distribution"`
}

type LakeConfig struct {
Expand Down
Loading