當前位置: 首頁>>代碼示例>>Golang>>正文


Golang rbac.User類代碼示例

本文整理匯總了Golang中github.com/cloudawan/cloudone_utility/rbac.User的典型用法代碼示例。如果您正苦於以下問題:Golang User類的具體用法?Golang User怎麽用?Golang User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了User類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SetPrivilegeHiddenTag

func SetPrivilegeHiddenTag(data map[interface{}]interface{}, tagName string, user *rbac.User, method string, path string) {
	if user.HasPermission(componentName, method, path) {
		data[tagName] = "<div class='btn-group'>"
	} else {
		data[tagName] = "<div hidden>"
	}
}
開發者ID:cloudawan,項目名稱:cloudone_gui,代碼行數:7,代碼來源:authorization.go

示例2: GetDashboardTabMenu

func GetDashboardTabMenu(user *rbac.User, activeTab string) string {
	if user == nil {
		return ""
	}

	buffer := bytes.Buffer{}
	buffer.WriteByte('\n')

	if user.HasPermission(componentName, "GET", "/gui/dashboard/topology") {
		if activeTab == "topology" {
			buffer.WriteString("			<li role='presentation' class='active'><a href='#' role='tab' >Topology</a></li>\n")
		} else {
			buffer.WriteString("			<li role='presentation'><a href='/gui/dashboard/topology/' role='tab' >Topology</a></li>\n")
		}
	}
	if user.HasPermission(componentName, "GET", "/gui/dashboard/healthcheck") {
		if activeTab == "healthcheck" {
			buffer.WriteString("			<li role='presentation' class='active'><a href='#' role='tab' >Health Check</a></li>\n")
		} else {
			buffer.WriteString("			<li role='presentation'><a href='/gui/dashboard/healthcheck/list' role='tab' >Health Check</a></li>\n")
		}
	}
	if user.HasPermission(componentName, "GET", "/gui/dashboard/bluegreen") {
		if activeTab == "bluegreen" {
			buffer.WriteString("			<li role='presentation' class='active'><a href='#' role='tab' >BlueGreen</a></li>\n")
		} else {
			buffer.WriteString("			<li role='presentation'><a href='/gui/dashboard/bluegreen/' role='tab' >BlueGreen</a></li>\n")
		}
	}
	if user.HasPermission(componentName, "GET", "/gui/dashboard/appservice") {
		if activeTab == "appservice" {
			buffer.WriteString("			<li role='presentation' class='active'><a href='#' role='tab' >AppService</a></li>\n")
		} else {
			buffer.WriteString("			<li role='presentation'><a href='/gui/dashboard/appservice/' role='tab' >AppService</a></li>\n")
		}
	}
	if user.HasPermission(componentName, "GET", "/gui/dashboard/deploy") {
		if activeTab == "deploy" {
			buffer.WriteString("			<li role='presentation' class='active'><a href='#' role='tab' >Deployment</a></li>\n")
		} else {
			buffer.WriteString("			<li role='presentation'><a href='/gui/dashboard/deploy/' role='tab' >Deployment</a></li>\n")
		}
	}

	return buffer.String()
}
開發者ID:cloudawan,項目名稱:cloudone_gui,代碼行數:46,代碼來源:authorization.go

示例3: LoadAllUser

func (storageEtcd *StorageEtcd) LoadAllUser() ([]rbac.User, error) {
	keysAPI, err := etcd.EtcdClient.GetKeysAPI()
	if err != nil {
		log.Error("Get keysAPI error %s", err)
		return nil, err
	}

	response, err := keysAPI.Get(context.Background(), etcd.EtcdClient.EtcdBasePath+"/user", nil)
	if err != nil {
		log.Error("Load all user error: %s", err)
		log.Error(response)
		return nil, err
	}

	userSlice := make([]rbac.User, 0)
	for _, node := range response.Node.Nodes {
		user := rbac.User{}
		err := json.Unmarshal([]byte(node.Value), &user)
		if err != nil {
			log.Error("Unmarshal user %v error %s", node.Value, err)
			return nil, err
		}

		// User doesn't have role data but only role name so load role
		roleSlice := make([]*rbac.Role, 0)
		for _, savedRole := range user.RoleSlice {
			role, err := storageEtcd.LoadRole(savedRole.Name)
			if err != nil {
				log.Error("Fail to load role with name %s error %s", savedRole.Name, err)
			} else {
				roleSlice = append(roleSlice, role)
			}
		}
		user.RoleSlice = roleSlice

		userSlice = append(userSlice, user)
	}

	return userSlice, nil
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:40,代碼來源:storage_etcd.go

示例4: LoadUser

func (storageEtcd *StorageEtcd) LoadUser(name string) (*rbac.User, error) {
	keysAPI, err := etcd.EtcdClient.GetKeysAPI()
	if err != nil {
		log.Error("Get keysAPI error %s", err)
		return nil, err
	}

	response, err := keysAPI.Get(context.Background(), etcd.EtcdClient.EtcdBasePath+"/user/"+name, nil)
	etcdError, _ := err.(client.Error)
	if etcdError.Code == client.ErrorCodeKeyNotFound {
		return nil, etcdError
	}
	if err != nil {
		log.Error("Load name with name %s error: %s", name, err)
		log.Error(response)
		return nil, err
	}

	user := new(rbac.User)
	err = json.Unmarshal([]byte(response.Node.Value), &user)
	if err != nil {
		log.Error("Unmarshal user %v error %s", response.Node.Value, err)
		return nil, err
	}

	// User doesn't have role data but only role name so load role
	roleSlice := make([]*rbac.Role, 0)
	for _, savedRole := range user.RoleSlice {
		role, err := storageEtcd.LoadRole(savedRole.Name)
		if err != nil {
			log.Error("Fail to load role with name %s error %s", savedRole.Name, err)
		} else {
			roleSlice = append(roleSlice, role)
		}
	}
	user.RoleSlice = roleSlice

	return user, nil
}
開發者ID:cloudawan,項目名稱:cloudone,代碼行數:39,代碼來源:storage_etcd.go

示例5: GetSystemRBACTabMenu

func GetSystemRBACTabMenu(user *rbac.User, activeTab string) string {
	if user == nil {
		return ""
	}

	buffer := bytes.Buffer{}
	buffer.WriteByte('\n')

	if user.HasPermission(componentName, "GET", "/gui/system/rbac/user/list") {
		if activeTab == "user" {
			buffer.WriteString("			<li role='presentation' class='active'><a href='#' role='tab' >User</a></li>\n")
		} else {
			buffer.WriteString("			<li role='presentation'><a href='/gui/system/rbac/user/list' role='tab' >User</a></li>\n")
		}
	}
	if user.HasPermission(componentName, "GET", "/gui/system/rbac/role/list") {
		if activeTab == "role" {
			buffer.WriteString("			<li role='presentation' class='active'><a href='#' role='tab' >Role</a></li>\n")
		} else {
			buffer.WriteString("			<li role='presentation'><a href='/gui/system/rbac/role/list' role='tab' >Role</a></li>\n")
		}
	}
	return buffer.String()
}
開發者ID:cloudawan,項目名稱:cloudone_gui,代碼行數:24,代碼來源:authorization.go

示例6: GetSystemNotificationTabMenu

func GetSystemNotificationTabMenu(user *rbac.User, activeTab string) string {
	if user == nil {
		return ""
	}

	buffer := bytes.Buffer{}
	buffer.WriteByte('\n')

	if user.HasPermission(componentName, "GET", "/gui/system/notification/emailserver/list") {
		if activeTab == "emailserver" {
			buffer.WriteString("			<li role='presentation' class='active'><a href='#' role='tab' >Email Server</a></li>\n")
		} else {
			buffer.WriteString("			<li role='presentation'><a href='/gui/system/notification/emailserver/list' role='tab' >Email Server</a></li>\n")
		}
	}
	if user.HasPermission(componentName, "GET", "/gui/system/notification/sms/list") {
		if activeTab == "sms" {
			buffer.WriteString("			<li role='presentation' class='active'><a href='#' role='tab' >SMS</a></li>\n")
		} else {
			buffer.WriteString("			<li role='presentation'><a href='/gui/system/notification/sms/list' role='tab' >SMS</a></li>\n")
		}
	}
	return buffer.String()
}
開發者ID:cloudawan,項目名稱:cloudone_gui,代碼行數:24,代碼來源:authorization.go

示例7: GetLayoutMenu

func GetLayoutMenu(user *rbac.User) string {
	if user == nil {
		return ""
	}

	buffer := bytes.Buffer{}
	buffer.WriteByte('\n')

	// Dashboard
	if user.HasChildPermission(componentName, "GET", "/gui/dashboard") {
		buffer.WriteString("					<li class=''><a href='/gui/dashboard/topology'>Dashboard</a></li>\n")
	}

	// Repository
	// Parent
	if user.HasChildPermission(componentName, "GET", "/gui/repository") {
		buffer.WriteString("					<li class='dropdown'>\n")
		buffer.WriteString("						<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-expanded='false'>Repository<span class='caret'></span></a>\n")
		buffer.WriteString("						<ul class='dropdown-menu' role='menu'>\n")
	}
	// Child
	if user.HasPermission(componentName, "GET", "/gui/repository/imageinformation/list") {
		buffer.WriteString("							<li><a href='/gui/repository/imageinformation/list'>Applications</a></li>\n")
	}
	if user.HasPermission(componentName, "GET", "/gui/repository/thirdparty/list") {
		buffer.WriteString("							<li><a href='/gui/repository/thirdparty/list'>Third-party Services</a></li>\n")
	}
	if user.HasPermission(componentName, "GET", "/gui/repository/topologytemplate/list") {
		buffer.WriteString("							<li><a href='/gui/repository/topologytemplate/list'>Topology template</a></li>\n")
	}
	// Parent
	if user.HasChildPermission(componentName, "GET", "/gui/repository") {
		buffer.WriteString("						</ul>\n")
		buffer.WriteString("					</li>\n")
	}

	// Deploy
	// Parent
	if user.HasChildPermission(componentName, "GET", "/gui/deploy") {
		buffer.WriteString("					<li class='dropdown'>\n")
		buffer.WriteString("						<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-expanded='false'>Deploy<span class='caret'></span></a>\n")
		buffer.WriteString("						<ul class='dropdown-menu' role='menu'>\n")
	}
	// Child
	if user.HasPermission(componentName, "GET", "/gui/deploy/deploy/list") {
		buffer.WriteString("							<li><a href='/gui/deploy/deploy/list'>Applications</a></li>\n")
	}
	if user.HasPermission(componentName, "GET", "/gui/deploy/deploybluegreen/list") {
		buffer.WriteString("							<li><a href='/gui/deploy/deploybluegreen/list'>Blue Green Deployments</a></li>\n")
	}
	if user.HasPermission(componentName, "GET", "/gui/deploy/autoscaler/list") {
		buffer.WriteString("							<li><a href='/gui/deploy/autoscaler/list'>Autoscalers</a></li>\n")
	}
	if user.HasPermission(componentName, "GET", "/gui/deploy/deployclusterapplication/list") {
		buffer.WriteString("							<li><a href='/gui/deploy/deployclusterapplication/list'>Third-party Services</a></li>\n")
	}
	if user.HasPermission(componentName, "GET", "/gui/deploy/clone/topology") {
		buffer.WriteString("							<li><a href='/gui/deploy/clone/select'>Clone Topology</a></li>\n")
	}
	// Parent
	if user.HasChildPermission(componentName, "GET", "/gui/deploy") {
		buffer.WriteString("						</ul>\n")
		buffer.WriteString("					</li>\n")
	}

	// Inventory
	// Parent
	if user.HasChildPermission(componentName, "GET", "/gui/inventory") {
		buffer.WriteString("					<li class='dropdown'>\n")
		buffer.WriteString("						<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-expanded='false'>Inventory<span class='caret'></span></a>\n")
		buffer.WriteString("						<ul class='dropdown-menu' role='menu'>\n")
	}
	// Child
	if user.HasPermission(componentName, "GET", "/gui/inventory/replicationcontroller/list") {
		buffer.WriteString("							<li><a href='/gui/inventory/replicationcontroller/list'>Replications</a></li>\n")
	}
	if user.HasPermission(componentName, "GET", "/gui/inventory/service/list") {
		buffer.WriteString("							<li><a href='/gui/inventory/service/list'>Services</a></li>\n")
	}
	// Parent
	if user.HasChildPermission(componentName, "GET", "/gui/inventory") {
		buffer.WriteString("						</ul>\n")
		buffer.WriteString("					</li>\n")
	}

	// Filesystem
	// Parent
	if user.HasChildPermission(componentName, "GET", "/gui/filesystem") {
		buffer.WriteString("					<li class='dropdown'>\n")
		buffer.WriteString("						<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-expanded='false'>Filesystem<span class='caret'></span></a>\n")
		buffer.WriteString("						<ul class='dropdown-menu' role='menu'>\n")
	}
	// Child
	if user.HasPermission(componentName, "GET", "/gui/filesystem/glusterfs/cluster/list") {
		buffer.WriteString("							<li><a href='/gui/filesystem/glusterfs/cluster/list'>Glusterfs</a></li>\n")
	}
	// Parent
	if user.HasChildPermission(componentName, "GET", "/gui/filesystem") {
		buffer.WriteString("						</ul>\n")
		buffer.WriteString("					</li>\n")
//.........這裏部分代碼省略.........
開發者ID:cloudawan,項目名稱:cloudone_gui,代碼行數:101,代碼來源:authorization.go


注:本文中的github.com/cloudawan/cloudone_utility/rbac.User類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。