Exemplo n.º 1
0
func (c *ListController) Get() {
	c.TplName = "repository/thirdparty/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiRepositoryThirdPartyEdit", user, "GET", "/gui/repository/thirdparty/edit")
	// Tag won't work in loop so need to be placed in data
	hasGuiRepositoryThirdPartyLaunch := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/thirdparty/launch")
	hasGuiRepositoryThirdPartyEdit := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/thirdparty/edit")
	hasGuiRepositoryThirdPartyDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/thirdparty/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/clusterapplications/"

	thirdPartyApplicationSlice := make([]ThirdPartyApplication, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &thirdPartyApplicationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(thirdPartyApplicationSlice); i++ {
			if hasGuiRepositoryThirdPartyLaunch {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyLaunch = "<div class='btn-group'>"
			} else {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyLaunch = "<div hidden>"
			}
			if hasGuiRepositoryThirdPartyEdit {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyEdit = "<div class='btn-group'>"
			} else {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyEdit = "<div hidden>"
			}
			if hasGuiRepositoryThirdPartyDelete {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyDelete = "<div class='btn-group'>"
			} else {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyDelete = "<div hidden>"
			}
		}

		sort.Sort(ByThirdPartyApplication(thirdPartyApplicationSlice))
		c.Data["thirdPartyApplicationSlice"] = thirdPartyApplicationSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 2
0
func (c *ListController) Get() {
	c.TplName = "deploy/deploybluegreen/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	// Tag won't work in loop so need to be placed in data
	hasGuiDeployDeployBlueGreenSelect := user.HasPermission(identity.GetConponentName(), "GET", "/gui/deploy/deploybluegreen/select")
	hasGuiDeployDeployBlueGreenDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/deploy/deploybluegreen/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deploybluegreens/"

	deployBlueGreenSlice := make([]DeployBlueGreen, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &deployBlueGreenSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(deployBlueGreenSlice); i++ {
			if deployBlueGreenSlice[i].NodePort == 0 {
				deployBlueGreenSlice[i].NodePortDisplay = "Auto-generated"
			} else {
				deployBlueGreenSlice[i].NodePortDisplay = strconv.Itoa(deployBlueGreenSlice[i].NodePort)
			}

			if hasGuiDeployDeployBlueGreenSelect {
				deployBlueGreenSlice[i].HiddenTagGuiDeployDeployBlueGreenSelect = "<div class='btn-group'>"
			} else {
				deployBlueGreenSlice[i].HiddenTagGuiDeployDeployBlueGreenSelect = "<div hidden>"
			}
			if hasGuiDeployDeployBlueGreenDelete {
				deployBlueGreenSlice[i].HiddenTagGuiDeployDeployBlueGreenDelete = "<div class='btn-group'>"
			} else {
				deployBlueGreenSlice[i].HiddenTagGuiDeployDeployBlueGreenDelete = "<div hidden>"
			}
		}

		sort.Sort(ByDeployBlueGreen(deployBlueGreenSlice))
		c.Data["deployBlueGreenSlice"] = deployBlueGreenSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 3
0
func (c *ListController) Get() {
	c.TplName = "filesystem/glusterfs/volume/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiFileSystemGlusterfsClusterList", user, "GET", "/gui/filesystem/glusterfs/cluster/list")
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuifFileSystemGlusterfsVolumeCreate", user, "GET", "/gui/filesystem/glusterfs/volume/create")
	// Tag won't work in loop so need to be placed in data
	hasHiddenTagGuiFileSystemGlusterfsVolumeReset := user.HasPermission(identity.GetConponentName(), "GET", "/gui/filesystem/glusterfs/volume/reset")
	hasHiddenTagGuiFileSystemGlusterfsVolumeDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/filesystem/glusterfs/volume/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	clusterName := c.GetString("clusterName")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/glusterfs/clusters/" + clusterName + "/volumes/"

	glusterfsVolumeSlice := make([]GlusterfsVolume, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &glusterfsVolumeSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(glusterfsVolumeSlice); i++ {
			glusterfsVolumeSlice[i].ClusterName = clusterName

			if hasHiddenTagGuiFileSystemGlusterfsVolumeReset {
				glusterfsVolumeSlice[i].HiddenTagGuiFileSystemGlusterfsVolumeReset = "<div class='btn-group'>"
			} else {
				glusterfsVolumeSlice[i].HiddenTagGuiFileSystemGlusterfsVolumeReset = "<div hidden>"
			}
			if hasHiddenTagGuiFileSystemGlusterfsVolumeDelete {
				glusterfsVolumeSlice[i].HiddenTagGuiFileSystemGlusterfsVolumeDelete = "<div class='btn-group'>"
			} else {
				glusterfsVolumeSlice[i].HiddenTagGuiFileSystemGlusterfsVolumeDelete = "<div hidden>"
			}
		}

		c.Data["glusterfsVolumeSlice"] = glusterfsVolumeSlice
		c.Data["clusterName"] = clusterName
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 4
0
func (c *ListController) Get() {
	c.TplName = "system/rbac/role/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// System RBAC tab menu
	user, _ := c.GetSession("user").(*rbac.User)
	c.Data["systemRBACTabMenu"] = identity.GetSystemRBACTabMenu(user, "role")
	// Authorization for Button
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiSystemRBACRoleEdit", user, "GET", "/gui/system/rbac/role/edit")
	// Tag won't work in loop so need to be placed in data
	hasGuiSystemRBACRoleEdit := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/rbac/role/edit")
	hasGuiSystemRBACRoleDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/rbac/role/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/authorizations/roles"

	simplifiedRoleSlice := make([]SimplifiedRole, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &simplifiedRoleSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(simplifiedRoleSlice); i++ {
			if hasGuiSystemRBACRoleEdit {
				simplifiedRoleSlice[i].HiddenTagGuiSystemRBACRoleEdit = "<div class='btn-group'>"
			} else {
				simplifiedRoleSlice[i].HiddenTagGuiSystemRBACRoleEdit = "<div hidden>"
			}
			if hasGuiSystemRBACRoleDelete {
				simplifiedRoleSlice[i].HiddenTagGuiSystemRBACRoleDelete = "<div class='btn-group'>"
			} else {
				simplifiedRoleSlice[i].HiddenTagGuiSystemRBACRoleDelete = "<div hidden>"
			}
		}

		sort.Sort(BySimplifiedRole(simplifiedRoleSlice))
		c.Data["simplifiedRoleSlice"] = simplifiedRoleSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 5
0
func (c *ListController) Get() {
	c.TplName = "system/privateregistry/image/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	serverName := c.GetString("serverName")
	repositoryName := c.GetString("repositoryName")

	c.Data["serverName"] = serverName

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiSystemPrivateRegistryRepositoryList", user, "GET", "/gui/system/privateregistry/repository/list")
	// Tag won't work in loop so need to be placed in data
	hasGuiSystemPrivateRegistryImageDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/privateregistry/image/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/privateregistries/servers/" + serverName + "/repositories/" + repositoryName + "/tags/"

	tagSlice := make([]string, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &tagSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		imageSlice := make([]Image, 0)
		for _, tag := range tagSlice {
			imageSlice = append(imageSlice, Image{tag, serverName, repositoryName, ""})
		}

		for i := 0; i < len(imageSlice); i++ {
			if hasGuiSystemPrivateRegistryImageDelete {
				imageSlice[i].HiddenTagGuiSystemPrivateRegistryImageDelete = "<div class='btn-group'>"
			} else {
				imageSlice[i].HiddenTagGuiSystemPrivateRegistryImageDelete = "<div hidden>"
			}
		}

		sort.Sort(ByImage(imageSlice))
		c.Data["imageSlice"] = imageSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 6
0
func (c *SelectController) Get() {
	c.TplName = "deploy/clone/select.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)

	currentNamespace, _ := c.GetSession("namespace").(string)

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/namespaces/"

	nameSlice := make([]string, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &nameSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		guimessage.OutputMessage(c.Data)
		return
	}

	namespaceSlice := make([]string, 0)
	for _, name := range nameSlice {
		if user.HasResource(identity.GetConponentName(), "/namespaces/"+name) {
			namespaceSlice = append(namespaceSlice, name)
		}
	}

	c.Data["currentNamespace"] = currentNamespace
	c.Data["namespaceSlice"] = namespaceSlice

	guimessage.OutputMessage(c.Data)

}
Exemplo n.º 7
0
func (c *ListController) Get() {
	c.TplName = "repository/imagerecord/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiRepositoryImageInformationList", user, "GET", "/gui/repository/imageinformation/list")
	// Tag won't work in loop so need to be placed in data
	hasGuiRepositoryImageRecordLog := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/imagerecord/log")
	hasGuiRepositoryImageRecordDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/imagerecord/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	name := c.GetString("name")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/imagerecords/" + name

	imageRecordSlice := make([]ImageRecord, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	returnedJsonMap, err := restclient.RequestGetWithStructure(url, &imageRecordSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		errorJsonMap, _ := returnedJsonMap.(map[string]interface{})
		errorMessage, _ := errorJsonMap["ErrorMessage"].(string)
		if strings.HasPrefix(errorMessage, "100: Key not found") {

		} else {
			// Error
			guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		}
	}

	for i := 0; i < len(imageRecordSlice); i++ {
		if imageRecordSlice[i].Failure {
			imageRecordSlice[i].FieldFailureStyleColor = "red"
		}
		if hasGuiRepositoryImageRecordLog {
			imageRecordSlice[i].HiddenTagGuiRepositoryImageRecordLog = "<div class='btn-group'>"
		} else {
			imageRecordSlice[i].HiddenTagGuiRepositoryImageRecordLog = "<div hidden>"
		}
		if hasGuiRepositoryImageRecordDelete {
			imageRecordSlice[i].HiddenTagGuiRepositoryImageRecordDelete = "<div class='btn-group'>"
		} else {
			imageRecordSlice[i].HiddenTagGuiRepositoryImageRecordDelete = "<div hidden>"
		}
	}

	sort.Sort(ByImageRecord(imageRecordSlice))
	c.Data["imageRecordSlice"] = imageRecordSlice

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 8
0
func (c *ListController) Get() {
	c.TplName = "event/kubernetes/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	// Tag won't work in loop so need to be placed in data
	hasGuiEventKubernetesAcknowledge := user.HasPermission(identity.GetConponentName(), "GET", "/gui/event/kubernetes/acknowledge")

	cloudoneAnalysisProtocol := beego.AppConfig.String("cloudoneAnalysisProtocol")
	cloudoneAnalysisHost := beego.AppConfig.String("cloudoneAnalysisHost")
	cloudoneAnalysisPort := beego.AppConfig.String("cloudoneAnalysisPort")

	acknowledge := c.GetString("acknowledge")
	if acknowledge == "" {
		acknowledge = "false"
	}

	offset, _ := c.GetInt("offset")

	url := cloudoneAnalysisProtocol + "://" + cloudoneAnalysisHost + ":" + cloudoneAnalysisPort +
		"/api/v1/historicalevents?acknowledge=" + acknowledge + "&size=" + strconv.Itoa(amountPerPage) + "&offset=" + strconv.Itoa(offset)

	jsonMapSlice := make([]map[string]interface{}, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &jsonMapSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		var action string
		var button string
		if acknowledge == "true" {
			action = "false"
			button = "Unacknowledge"
		} else {
			action = "true"
			button = "Acknowledge"
		}

		kubernetesEventSlice := make([]KubernetesEvent, 0)
		for _, jsonMap := range jsonMapSlice {
			sourceJsonMap, _ := jsonMap["_source"].(map[string]interface{})

			namespace, _ := sourceJsonMap["metadata"].(map[string]interface{})["namespace"].(string)
			name, _ := sourceJsonMap["involvedObject"].(map[string]interface{})["name"].(string)
			kind, _ := sourceJsonMap["involvedObject"].(map[string]interface{})["kind"].(string)
			source, _ := sourceJsonMap["source"].(map[string]interface{})
			id, _ := jsonMap["_id"].(string)
			firstTimestamp, _ := sourceJsonMap["firstTimestamp"].(string)
			lastTimestamp, _ := sourceJsonMap["lastTimestamp"].(string)
			count, _ := sourceJsonMap["count"].(float64)
			message, _ := sourceJsonMap["message"].(string)
			reason, _ := sourceJsonMap["reason"].(string)
			acknowledge, _ := sourceJsonMap["searchMetaData"].(map[string]interface{})["acknowledge"].(bool)

			firstTime, err := time.Parse(time.RFC3339, firstTimestamp)
			if err == nil {
				firstTime = firstTime.Local()
			}
			lastTime, err := time.Parse(time.RFC3339, lastTimestamp)
			if err == nil {
				lastTime = lastTime.Local()
			}

			kubernetesEvent := KubernetesEvent{
				namespace,
				name,
				kind,
				source,
				id,
				firstTime,
				lastTime,
				int(count),
				message,
				reason,
				acknowledge,
				action,
				button,
				"",
			}

			kubernetesEventSlice = append(kubernetesEventSlice, kubernetesEvent)
		}

		previousOffset := offset - amountPerPage
		if previousOffset < 0 {
			previousOffset = 0
		}
		nextOffset := offset + amountPerPage

		previousFrom := previousOffset
		if previousFrom < 0 {
			previousFrom = 0
		}
		previousFrom += 1
		previousTo := previousOffset + amountPerPage
		c.Data["previousLabel"] = strconv.Itoa(previousFrom) + "~" + strconv.Itoa(previousTo)
		if offset == 0 {
			c.Data["previousButtonHidden"] = "hidden"
		} else {
			c.Data["previousButtonHidden"] = ""
		}

		nextFrom := nextOffset + 1
		nextTo := nextOffset + amountPerPage
		c.Data["nextLabel"] = strconv.Itoa(nextFrom) + "~" + strconv.Itoa(nextTo)

		if acknowledge == "true" {
			c.Data["acknowledgeActive"] = "active"
			c.Data["paginationUrlPrevious"] = "/gui/event/kubernetes/list?acknowledge=true&offset=" + strconv.Itoa(previousOffset)
			c.Data["paginationUrlNext"] = "/gui/event/kubernetes/list?acknowledge=true&offset=" + strconv.Itoa(nextOffset)
		} else {
			c.Data["unacknowledgeActive"] = "active"
			c.Data["paginationUrlPrevious"] = "/gui/event/kubernetes/list?acknowledge=false&offset=" + strconv.Itoa(previousOffset)
			c.Data["paginationUrlNext"] = "/gui/event/kubernetes/list?acknowledge=false&offset=" + strconv.Itoa(nextOffset)
		}

		for i := 0; i < len(kubernetesEventSlice); i++ {
			if hasGuiEventKubernetesAcknowledge {
				kubernetesEventSlice[i].HiddenTagGuiEventKubernetesAcknowledge = "<div class='btn-group'>"
			} else {
				kubernetesEventSlice[i].HiddenTagGuiEventKubernetesAcknowledge = "<div hidden>"
			}
		}

		c.Data["kubernetesEventSlice"] = kubernetesEventSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 9
0
func (c *ListController) Get() {
	c.TplName = "inventory/replicationcontroller/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiInventoryReplicationControllerEdit", user, "GET", "/gui/inventory/replicationcontroller/edit")
	// Tag won't work in loop so need to be placed in data
	hasGuiInventoryReplicationControllerSize := user.HasPermission(identity.GetConponentName(), "GET", "/gui/inventory/replicationcontroller/size")
	hasGuiInventoryReplicationControllerDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/inventory/replicationcontroller/delete")
	hasGuiInventoryReplicationControllerPodlog := user.HasPermission(identity.GetConponentName(), "GET", "/gui/inventory/replicationcontroller/pod/log")
	hasGuiInventoryReplicationControllerPodDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/inventory/replicationcontroller/pod/delete")
	hasGuiInventoryReplicationControllerDockerterminal := user.HasPermission(identity.GetConponentName(), "GET", "/gui/inventory/replicationcontroller/dockerterminal")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	namespace, _ := c.GetSession("namespace").(string)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/replicationcontrollers/" + namespace

	replicationControllerAndRelatedPodSlice := make([]ReplicationControllerAndRelatedPod, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &replicationControllerAndRelatedPodSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(replicationControllerAndRelatedPodSlice); i++ {
			replicationControllerAndRelatedPodSlice[i].Display =
				displayMap[replicationControllerAndRelatedPodSlice[i].Name]

			if hasGuiInventoryReplicationControllerSize {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerSize = "<div class='btn-group'>"
			} else {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerSize = "<div hidden>"
			}
			if hasGuiInventoryReplicationControllerDelete {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerDelete = "<div class='btn-group'>"
			} else {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerDelete = "<div hidden>"
			}
			if hasGuiInventoryReplicationControllerPodlog {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerPodlog = "<div class='btn-group'>"
			} else {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerPodlog = "<div hidden>"
			}
			if hasGuiInventoryReplicationControllerPodDelete {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerPodDelete = "<div class='btn-group'>"
			} else {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerPodDelete = "<div hidden>"
			}
			if hasGuiInventoryReplicationControllerDockerterminal {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerDockerterminal = "<div class='btn-group'>"
			} else {
				replicationControllerAndRelatedPodSlice[i].HiddenTagGuiInventoryReplicationControllerDockerterminal = "<div hidden>"
			}
		}
		c.Data["replicationControllerAndRelatedPodSlice"] = replicationControllerAndRelatedPodSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 10
0
func (c *ListController) Get() {
	c.TplName = "notification/notifier/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiNotificationNotifierEdit", user, "GET", "/gui/notification/notifier/edit")
	// Tag won't work in loop so need to be placed in data
	hasGuiNotificationNotifierEdit := user.HasPermission(identity.GetConponentName(), "GET", "/gui/notification/notifier/edit")
	hasGuiNotificationNotifierDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/notification/notifier/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/notifiers/"

	replicationControllerNotifierSlice := make([]ReplicationControllerNotifier, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &replicationControllerNotifierSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		namespace, _ := c.GetSession("namespace").(string)

		filteredReplicationControllerNotifierSlice := make([]ReplicationControllerNotifier, 0)

		for i := 0; i < len(replicationControllerNotifierSlice); i++ {
			if hasGuiNotificationNotifierEdit {
				replicationControllerNotifierSlice[i].HiddenTagGuiNotificationNotifierEdit = "<div class='btn-group'>"
			} else {
				replicationControllerNotifierSlice[i].HiddenTagGuiNotificationNotifierEdit = "<div hidden>"
			}
			if hasGuiNotificationNotifierDelete {
				replicationControllerNotifierSlice[i].HiddenTagGuiNotificationNotifierDelete = "<div class='btn-group'>"
			} else {
				replicationControllerNotifierSlice[i].HiddenTagGuiNotificationNotifierDelete = "<div hidden>"
			}

			if replicationControllerNotifierSlice[i].Namespace == namespace {
				filteredReplicationControllerNotifierSlice = append(filteredReplicationControllerNotifierSlice, replicationControllerNotifierSlice[i])
			}
		}

		sort.Sort(ByReplicationControllerNotifier(filteredReplicationControllerNotifierSlice))
		c.Data["replicationControllerNotifierSlice"] = filteredReplicationControllerNotifierSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 11
0
func (c *ListController) Get() {
	c.TplName = "inventory/service/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiInventoryServiceEdit", user, "GET", "/gui/inventory/service/edit")
	// Tag won't work in loop so need to be placed in data
	hasGuiInventoryServiceDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/inventory/service/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	serverHost := c.Ctx.Input.Host()

	namespace := c.GetSession("namespace").(string)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/services/" + namespace

	serviceSlice := make([]Service, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &serviceSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(serviceSlice); i++ {
			serviceSlice[i].Display = displayMap[serviceSlice[i].Name]

			for j := 0; j < len(serviceSlice[i].PortSlice); j++ {
				// < 0 not used, == 0 auto-generated, > 0 port number
				if serviceSlice[i].PortSlice[j].NodePort < 0 {
					serviceSlice[i].PortSlice[j].NodePortText = ""
					serviceSlice[i].PortSlice[j].HiddenTagNodePort = "hidden"
				} else {
					serviceSlice[i].PortSlice[j].NodePortText = strconv.Itoa(serviceSlice[i].PortSlice[j].NodePort)
					serviceSlice[i].PortSlice[j].NodePortURL = "http://" + serverHost + ":" + strconv.Itoa(serviceSlice[i].PortSlice[j].NodePort)
				}
			}

			if hasGuiInventoryServiceDelete {
				serviceSlice[i].HiddenTagGuiInventoryServiceDelete = "<div class='btn-group'>"
			} else {
				serviceSlice[i].HiddenTagGuiInventoryServiceDelete = "<div hidden>"
			}
		}

		c.Data["serviceSlice"] = serviceSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 12
0
func (c *ListController) Get() {
	c.TplName = "system/rbac/user/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// System RBAC tab menu
	user, _ := c.GetSession("user").(*rbac.User)
	c.Data["systemRBACTabMenu"] = identity.GetSystemRBACTabMenu(user, "user")
	// Authorization for Button
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiSystemRBACUserEdit", user, "GET", "/gui/system/rbac/user/edit")
	// Tag won't work in loop so need to be placed in data
	hasGuiSystemRBACUserEdit := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/rbac/user/edit")
	hasGuiSystemRBACUserDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/rbac/user/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/authorizations/users"

	userSlice := make([]rbac.User, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &userSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/namespaces"

		namespaceNameSlice := make([]string, 0)

		_, err = restclient.RequestGetWithStructure(url, &namespaceNameSlice, tokenHeaderMap)

		if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
			return
		}

		if err != nil {
			guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		} else {
			simplifiedUserSlice := make([]SimplifiedUser, 0)
			for _, user := range userSlice {
				roleNameSlice := make([]string, 0)
				for _, role := range user.RoleSlice {
					roleNameSlice = append(roleNameSlice, role.Name)
				}

				namespaceSlice := make([]string, 0)
				for _, resource := range user.ResourceSlice {
					// Use component * only since they are the same in all components in the simplified version
					if resource.Component == "*" {
						if resource.Path == "*" || resource.Path == "/namespaces/" {
							namespaceSlice = make([]string, 0)
							namespaceSlice = append(namespaceSlice, "*")
							break
						} else if strings.HasPrefix(resource.Path, "/namespaces/") {
							splitSlice := strings.Split(resource.Path, "/")
							namespace := splitSlice[2]
							namespaceSlice = append(namespaceSlice, namespace)
						}
					}
				}

				expiredTimeText := ""
				if user.ExpiredTime != nil {
					expiredTimeText = user.ExpiredTime.String()
				}

				simplifiedUser := SimplifiedUser{
					user.Name,
					user.Disabled,
					expiredTimeText,
					roleNameSlice,
					namespaceSlice,
					user.Description,
					"",
					"",
				}

				if hasGuiSystemRBACUserEdit {
					simplifiedUser.HiddenTagGuiSystemRBACUserEdit = "<div class='btn-group'>"
				} else {
					simplifiedUser.HiddenTagGuiSystemRBACUserEdit = "<div hidden>"
				}
				if hasGuiSystemRBACUserDelete {
					simplifiedUser.HiddenTagGuiSystemRBACUserDelete = "<div class='btn-group'>"
				} else {
					simplifiedUser.HiddenTagGuiSystemRBACUserDelete = "<div hidden>"
				}

				simplifiedUserSlice = append(simplifiedUserSlice, simplifiedUser)
			}

			sort.Sort(BySimplifiedUser(simplifiedUserSlice))
			c.Data["simplifiedUserSlice"] = simplifiedUserSlice
		}
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 13
0
func (c *ListController) Get() {
	c.TplName = "repository/imageinformation/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiRepositoryImageInformationCreate", user, "GET", "/gui/repository/imageinformation/create")
	// Tag won't work in loop so need to be placed in data
	hasGuiRepositoryImageRecordList := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/imagerecord/list")
	hasGuiRepositoryImageInformationUpgrade := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/imageinformation/upgrade")
	hasGuiRepositoryImageInformationLog := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/imageinformation/log")
	hasGuiDeployDeployCreate := user.HasPermission(identity.GetConponentName(), "GET", "/gui/deploy/deploy/create")
	hasGuiDeployDeployBlueGreenSelect := user.HasPermission(identity.GetConponentName(), "GET", "/gui/deploy/deploybluegreen/select")
	hasGuiRepositoryImageInformationDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/imageinformation/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	cloudoneGUIProtocol := beego.AppConfig.String("cloudoneGUIProtocol")
	cloudoneGUIHost, cloudoneGUIPort := dashboard.GetServerHostAndPortFromUserRequest(c.Ctx.Input)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/imageinformations/"

	imageInformationSlice := make([]ImageInformation, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &imageInformationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(imageInformationSlice); i++ {
			if hasGuiRepositoryImageRecordList {
				imageInformationSlice[i].HiddenTagGuiRepositoryImageRecordList = "<div class='btn-group'>"
			} else {
				imageInformationSlice[i].HiddenTagGuiRepositoryImageRecordList = "<div hidden>"
			}
			if hasGuiRepositoryImageInformationUpgrade {
				imageInformationSlice[i].HiddenTagGuiRepositoryImageInformationUpgrade = "<div class='btn-group'>"
			} else {
				imageInformationSlice[i].HiddenTagGuiRepositoryImageInformationUpgrade = "<div hidden>"
			}
			if hasGuiRepositoryImageInformationLog {
				imageInformationSlice[i].HiddenTagGuiRepositoryImageInformationLog = "<div class='btn-group'>"
			} else {
				imageInformationSlice[i].HiddenTagGuiRepositoryImageInformationLog = "<div hidden>"
			}
			if hasGuiDeployDeployCreate {
				imageInformationSlice[i].HiddenTagGuiDeployDeployCreate = "<div class='btn-group'>"
			} else {
				imageInformationSlice[i].HiddenTagGuiDeployDeployCreate = "<div hidden>"
			}
			if hasGuiDeployDeployBlueGreenSelect {
				imageInformationSlice[i].HiddenTagGuiDeployDeployBlueGreenSelect = "<div class='btn-group'>"
			} else {
				imageInformationSlice[i].HiddenTagGuiDeployDeployBlueGreenSelect = "<div hidden>"
			}
			if hasGuiRepositoryImageInformationDelete {
				imageInformationSlice[i].HiddenTagGuiRepositoryImageInformationDelete = "<div class='btn-group'>"
			} else {
				imageInformationSlice[i].HiddenTagGuiRepositoryImageInformationDelete = "<div hidden>"
			}

			// Add git webhook information
			if imageInformationSlice[i].Kind == "git" {
				githubWebhookUrl := cloudoneGUIProtocol + "://" + cloudoneGUIHost + ":" + strconv.Itoa(cloudoneGUIPort) + "/api/v1/webhook/github?user="******"&imageInformation=" + imageInformationSlice[i].Name
				imageInformationSlice[i].BuildParameter["githubWebhookUrl"] = githubWebhookUrl
			}
		}

		sort.Sort(ByImageInformation(imageInformationSlice))
		c.Data["imageInformationSlice"] = imageInformationSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 14
0
func (c *ListController) Get() {
	c.TplName = "repository/topologytemplate/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	// Tag won't work in loop so need to be placed in data
	hasGuiRepositoryTopologyTemplateClone := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/topologytemplate/clone")
	hasGuiRepositoryTopologyTemplateDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/topologytemplate/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/topology/"

	topologySlice := make([]Topology, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &topologySlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(topologySlice); i++ {
			if hasGuiRepositoryTopologyTemplateClone {
				topologySlice[i].HiddenTagGuiRepositoryTopologyTemplateClone = "<div class='btn-group'>"
			} else {
				topologySlice[i].HiddenTagGuiRepositoryTopologyTemplateClone = "<div hidden>"
			}
			if hasGuiRepositoryTopologyTemplateDelete {
				topologySlice[i].HiddenTagGuiRepositoryTopologyTemplateDelete = "<div class='btn-group'>"
			} else {
				topologySlice[i].HiddenTagGuiRepositoryTopologyTemplateDelete = "<div hidden>"
			}

			for j := 0; j < len(topologySlice[i].LaunchSlice); j++ {
				if topologySlice[i].LaunchSlice[j].LaunchApplication != nil {
					topologySlice[i].LaunchSlice[j].Information = "APP: " + topologySlice[i].LaunchSlice[j].LaunchApplication.ImageInformationName + " " + topologySlice[i].LaunchSlice[j].LaunchApplication.Version + " (" + strconv.Itoa(topologySlice[i].LaunchSlice[j].LaunchApplication.ReplicaAmount) + ")"
				} else if topologySlice[i].LaunchSlice[j].LaunchClusterApplication != nil {
					topologySlice[i].LaunchSlice[j].Information = "3rd: " + topologySlice[i].LaunchSlice[j].LaunchClusterApplication.Name + " (" + strconv.Itoa(topologySlice[i].LaunchSlice[j].LaunchClusterApplication.Size) + ")"
				}

			}

			// Change time format
			topologySlice[i].CreatedDate = topologySlice[i].CreatedDate.Round(time.Second)
		}

		sort.Sort(ByTopology(topologySlice))
		c.Data["topologySlice"] = topologySlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 15
0
func (c *ListController) Get() {
	c.TplName = "system/namespace/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiSystemNamespaceEdit", user, "GET", "/gui/system/namespace/edit")
	// Tag won't work in loop so need to be placed in data
	hasGuiSystemNamespaceSelect := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/namespace/select")
	hasGuiSystemNamespaceBookmark := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/namespace/bookmark")
	hasGuiSystemNamespaceDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/namespace/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/namespaces"

	nameSlice := make([]string, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &nameSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		selectedNamespace := c.GetSession("namespace")

		metaDataMap := user.MetaDataMap
		if metaDataMap == nil {
			metaDataMap = make(map[string]string)
		}
		loginNamespace := metaDataMap["loginNamespace"]

		namespaceSlice := make([]Namespace, 0)
		for _, name := range nameSlice {
			namespace := Namespace{name, false, false, "", "", "", ""}
			if name == selectedNamespace {
				namespace.Selected = true
			}
			namespace.Display = displayMap[name]

			if len(loginNamespace) > 0 && loginNamespace == namespace.Name {
				namespace.Bookmarked = true
			}

			if hasGuiSystemNamespaceSelect {
				namespace.HiddenTagGuiSystemNamespaceSelect = "<div class='btn-group'>"
			} else {
				namespace.HiddenTagGuiSystemNamespaceSelect = "<div hidden>"
			}
			if hasGuiSystemNamespaceBookmark {
				namespace.HiddenTagGuiSystemNamespaceBookmark = "<div class='btn-group'>"
			} else {
				namespace.HiddenTagGuiSystemNamespaceBookmark = "<div hidden>"
			}
			if hasGuiSystemNamespaceDelete {
				namespace.HiddenTagGuiSystemNamespaceDelete = "<div class='btn-group'>"
			} else {
				namespace.HiddenTagGuiSystemNamespaceDelete = "<div hidden>"
			}

			if user.HasResource(identity.GetConponentName(), "/namespaces/"+namespace.Name) {
				namespaceSlice = append(namespaceSlice, namespace)
			}
		}

		sort.Sort(ByNamespace(namespaceSlice))
		c.Data["namespaceSlice"] = namespaceSlice
	}

	guimessage.OutputMessage(c.Data)
}
Exemplo n.º 16
0
func (c *ListController) Get() {
	c.TplName = "deploy/deploy/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	// Tag won't work in loop so need to be placed in data
	hiddenTagGuiDeployDeployUpdate := user.HasPermission(identity.GetConponentName(), "GET", "/gui/deploy/deploy/update")
	hiddenTagGuiDeployDeployResize := user.HasPermission(identity.GetConponentName(), "GET", "/gui/deploy/deploy/resize")
	hiddenTagGuiDeployDeployDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/deploy/deploy/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	namespace, _ := c.GetSession("namespace").(string)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deploys/" + namespace

	deployInformationSlice := make([]DeployInformation, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &deployInformationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		// Only show those belonging to this namespace
		filteredDeployInformationSlice := make([]DeployInformation, 0)
		for _, deployInformation := range deployInformationSlice {
			if hiddenTagGuiDeployDeployUpdate {
				deployInformation.HiddenTagGuiDeployDeployUpdate = "<div class='btn-group'>"
			} else {
				deployInformation.HiddenTagGuiDeployDeployUpdate = "<div hidden>"
			}
			if hiddenTagGuiDeployDeployResize {
				deployInformation.HiddenTagGuiDeployDeployResize = "<div class='btn-group'>"
			} else {
				deployInformation.HiddenTagGuiDeployDeployResize = "<div hidden>"
			}
			if hiddenTagGuiDeployDeployDelete {
				deployInformation.HiddenTagGuiDeployDeployDelete = "<div class='btn-group'>"
			} else {
				deployInformation.HiddenTagGuiDeployDeployDelete = "<div hidden>"
			}

			filteredDeployInformationSlice = append(filteredDeployInformationSlice, deployInformation)
		}

		sort.Sort(ByDeployInformation(filteredDeployInformationSlice))
		c.Data["deployInformationSlice"] = filteredDeployInformationSlice
	}

	guimessage.OutputMessage(c.Data)
}