当前位置: 首页>>代码示例>>Golang>>正文


Golang schema.NewAuthorization函数代码示例

本文整理汇总了Golang中github.com/cloudwan/gohan/schema.NewAuthorization函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAuthorization函数的具体用法?Golang NewAuthorization怎么用?Golang NewAuthorization使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewAuthorization函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: VerifyToken

//VerifyToken verifies keystone v3.0 token
func (client *keystoneV3Client) VerifyToken(token string) (schema.Authorization, error) {
	tokenResult := v3tokens.Get(client.client, token)
	_, err := tokenResult.Extract()
	if err != nil {
		return nil, fmt.Errorf("Invalid token")
	}
	tokenBody := tokenResult.Body.(map[string]interface{})["token"]
	roles := tokenBody.(map[string]interface{})["roles"]
	roleIDs := []string{}
	for _, roleBody := range roles.([]interface{}) {
		roleIDs = append(roleIDs, roleBody.(map[string]interface{})["name"].(string))
	}
	tokenBodyMap := tokenBody.(map[string]interface{})
	project := tokenBodyMap["project"].(map[string]interface{})
	tenantID := project["id"].(string)
	tenantName := project["name"].(string)
	catalogList, ok := tokenBodyMap["catalog"].([]interface{})
	catalogObj := []*schema.Catalog{}
	if ok {
		for _, rawCatalog := range catalogList {
			catalog := rawCatalog.(map[string]interface{})
			endPoints := []*schema.Endpoint{}
			rawEndpoints, ok := catalog["endpoints"].([]interface{})
			if ok {
				for _, rawEndpoint := range rawEndpoints {
					endpoint := rawEndpoint.(map[string]interface{})
					endPoints = append(endPoints,
						schema.NewEndpoint(endpoint["url"].(string), endpoint["region"].(string), endpoint["interface"].(string)))
				}
			}
			catalogObj = append(catalogObj, schema.NewCatalog(catalog["name"].(string), catalog["type"].(string), endPoints))
		}
	}
	return schema.NewAuthorization(tenantID, tenantName, token, roleIDs, catalogObj), nil
}
开发者ID:gitter-badger,项目名称:gohan,代码行数:36,代码来源:keystone.go

示例2: addTestingAPI

func (env *Environment) addTestingAPI() {
	builtins := map[string]interface{}{
		"Fail": func(call otto.FunctionCall) otto.Value {
			if len(call.ArgumentList) == 0 {
				panic(fmt.Errorf("Fail!"))
			}

			if !call.ArgumentList[0].IsString() {
				panic(fmt.Errorf("Invalid call to 'Fail': format string expected first"))
			}

			format, _ := call.ArgumentList[0].ToString()
			args := []interface{}{}
			for _, value := range call.ArgumentList[1:] {
				args = append(args, gohan_otto.ConvertOttoToGo(value))
			}

			panic(fmt.Errorf(format, args...))
		},
		"MockTransaction": func(call otto.FunctionCall) otto.Value {
			newTransaction := false
			if len(call.ArgumentList) > 1 {
				panic("Wrong number of arguments in MockTransaction call.")
			} else if len(call.ArgumentList) == 1 {
				rawNewTransaction, _ := call.Argument(0).Export()
				newTransaction = rawNewTransaction.(bool)
			}
			transactionValue, _ := call.Otto.ToValue(env.getTransaction(newTransaction))
			return transactionValue
		},
		"CommitMockTransaction": func(call otto.FunctionCall) otto.Value {
			tx := env.getTransaction(false)
			tx.Commit()
			tx.Close()
			return otto.Value{}
		},
		"MockPolicy": func(call otto.FunctionCall) otto.Value {
			policyValue, _ := call.Otto.ToValue(schema.NewEmptyPolicy())
			return policyValue
		},
		"MockAuthorization": func(call otto.FunctionCall) otto.Value {
			authorizationValue, _ := call.Otto.ToValue(schema.NewAuthorization("", "", "", []string{}, []*schema.Catalog{}))
			return authorizationValue
		},
	}
	for name, object := range builtins {
		env.VM.Set(name, object)
	}
	// NOTE: There is no way to return error back to Otto after calling a Go
	// function, so the following function has to be written in pure JavaScript.
	env.VM.Otto.Run(`function GohanTrigger(event, context) { gohan_handle_event(event, context); }`)
	env.mockFunction("gohan_http")
	env.mockFunction("gohan_raw_http")
	env.mockFunction("gohan_db_transaction")
	env.mockFunction("gohan_config")
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:56,代码来源:environment.go

示例3: VerifyToken

//VerifyToken fake verify
func (*FakeIdentity) VerifyToken(tokenID string) (schema.Authorization, error) {
	rawToken, ok := fakeTokens[tokenID]
	if !ok {
		return nil, fmt.Errorf("authentication error")
	}

	access, _ := rawToken.(map[string]interface{})["access"].(map[string]interface{})
	tenantID := access["token"].(token).Tenant.ID
	tenantName := access["token"].(token).Tenant.Name
	role := access["user"].(map[string]interface{})["roles"].([]role)[0].Name

	return schema.NewAuthorization(tenantID, tenantName, tokenID, []string{role}, nil), nil
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:14,代码来源:fake.go

示例4: VerifyToken

//VerifyToken verifies keystone v2.0 token
func (client *keystoneV2Client) VerifyToken(token string) (schema.Authorization, error) {
	tokenResult, err := verifyV2Token(client.client, token)
	if err != nil {
		return nil, fmt.Errorf("Invalid token")
	}
	fmt.Printf("%v", tokenResult)
	tokenBody := tokenResult.(map[string]interface{})["access"]
	userBody := tokenBody.(map[string]interface{})["user"]
	roles := userBody.(map[string]interface{})["roles"]
	roleIDs := []string{}
	for _, roleBody := range roles.([]interface{}) {
		roleIDs = append(roleIDs, roleBody.(map[string]interface{})["name"].(string))
	}
	tokenBodyMap := tokenBody.(map[string]interface{})
	tenantObj, ok := tokenBodyMap["token"].(map[string]interface{})["tenant"]
	if !ok {
		return nil, fmt.Errorf("Token is unscoped")
	}
	tenant := tenantObj.(map[string]interface{})
	tenantID := tenant["id"].(string)
	tenantName := tenant["name"].(string)
	catalogList := tokenBodyMap["serviceCatalog"].([]interface{})
	catalogObj := []*schema.Catalog{}
	for _, rawCatalog := range catalogList {
		catalog := rawCatalog.(map[string]interface{})
		endPoints := []*schema.Endpoint{}
		rawEndpoints := catalog["endpoints"].([]interface{})
		for _, rawEndpoint := range rawEndpoints {
			endpoint := rawEndpoint.(map[string]interface{})
			region := endpoint["region"].(string)
			adminURL, ok := endpoint["adminURL"].(string)
			if ok {
				endPoints = append(endPoints,
					schema.NewEndpoint(adminURL, region, "admin"))
			}
			internalURL, ok := endpoint["internalURL"].(string)
			if ok {
				endPoints = append(endPoints,
					schema.NewEndpoint(internalURL, region, "internal"))
			}
			publicURL, ok := endpoint["publicURL"].(string)
			if ok {
				endPoints = append(endPoints,
					schema.NewEndpoint(publicURL, region, "public"))
			}
		}
		catalogObj = append(catalogObj, schema.NewCatalog(catalog["name"].(string), catalog["type"].(string), endPoints))
	}
	return schema.NewAuthorization(tenantID, tenantName, token, roleIDs, catalogObj), nil
}
开发者ID:cloudwan,项目名称:gohan,代码行数:51,代码来源:keystone.go

示例5: GetServiceAuthorization

//GetServiceAuthorization returns always authorization for admin
func (i *NoIdentityService) GetServiceAuthorization() (schema.Authorization, error) {
	return schema.NewAuthorization("admin", "admin", "admin_token", []string{"admin"}, nil), nil
}
开发者ID:vozhyk-,项目名称:gohan,代码行数:4,代码来源:middleware.go

示例6:

			context       middleware.Context
			schemaID      string
			path          string
			action        string
			currentSchema *schema.Schema
			extensions    []*schema.Extension
			env           extension.Environment
			events        map[string]string

			network1 map[string]interface{}
			network2 map[string]interface{}
			subnet1  map[string]interface{}
		)

		BeforeEach(func() {
			adminAuth = schema.NewAuthorization(adminTenantID, "admin", adminTokenID, []string{"admin"}, nil)
			memberAuth = schema.NewAuthorization(memberTenantID, "member", memberTokenID, []string{"_member_"}, nil)
			auth = adminAuth

			context = middleware.Context{}

			events = map[string]string{}

			network1 = map[string]interface{}{
				"id":                "test1",
				"name":              "Rohan",
				"description":       "The proud horsemasters",
				"tenant_id":         adminTenantID,
				"providor_networks": map[string]interface{}{},
				"route_targets":     []interface{}{},
				"shared":            false,
开发者ID:nati,项目名称:gohan,代码行数:31,代码来源:otto_test.go

示例7: GetServiceAuthorization

//GetServiceAuthorization returns always authorization for nobody
func (i *NobodyIdentityService) GetServiceAuthorization() (schema.Authorization, error) {
	return schema.NewAuthorization("nobody", "nobody", "nobody_token", []string{"Nobody"}, nil), nil
}
开发者ID:cloudwan,项目名称:gohan,代码行数:4,代码来源:middleware.go

示例8: NewServer


//.........这里部分代码省略.........
			if err != nil {
				log.Fatal(err)
			}
			db.CopyDBResources(inDB, server.db, false)
		}
	}

	if config.GetBool("keystone/use_keystone", false) {
		//TODO remove this
		if config.GetBool("keystone/fake", false) {
			server.keystoneIdentity = &middleware.FakeIdentity{}
			//TODO(marcin) requests to fake server also get authenticated
			//             we need a separate routing Group
			log.Info("Debug Mode with Fake Keystone Server")
		} else {
			log.Info("Keystone backend server configured")
			server.keystoneIdentity, err = cloud.NewKeystoneIdentity(
				config.GetString("keystone/auth_url", "http://localhost:35357/v3"),
				config.GetString("keystone/user_name", "admin"),
				config.GetString("keystone/password", "password"),
				config.GetString("keystone/domain_name", "Default"),
				config.GetString("keystone/tenant_name", "admin"),
				config.GetString("keystone/version", ""),
			)
			if err != nil {
				log.Fatal(err)
			}
		}
		m.MapTo(server.keystoneIdentity, (*middleware.IdentityService)(nil))
		m.Use(middleware.Authentication())
		//m.Use(Authorization())
	} else {
		m.MapTo(&middleware.NoIdentityService{}, (*middleware.IdentityService)(nil))
		m.Map(schema.NewAuthorization("admin", "admin", "admin_token", []string{"admin"}, nil))
	}

	if err != nil {
		return nil, fmt.Errorf("invalid base dir: %s", err)
	}

	server.addOptionsRoute()
	cors := config.GetString("cors", "")
	if cors != "" {
		log.Info("Enabling CORS for %s", cors)
		if cors == "*" {
			log.Warning("cors for * have security issue")
		}
		server.martini.Use(func(rw http.ResponseWriter, r *http.Request) {
			rw.Header().Add("Access-Control-Allow-Origin", cors)
			rw.Header().Add("Access-Control-Allow-Headers", "X-Auth-Token, Content-Type")
			rw.Header().Add("Access-Control-Expose-Headers", "X-Total-Count")
			rw.Header().Add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE")
		})
	}

	documentRoot := config.GetString("document_root", "embed")
	if config.GetBool("webui_config/enabled", false) {
		m.Use(func(res http.ResponseWriter, req *http.Request, c martini.Context) {
			if req.URL.Path != "/webui/config.json" {
				c.Next()
				return
			}
			address := config.GetString("webui_config/address", server.address)
			if address[0] == ':' {
				address = "__HOST__" + address
			}
开发者ID:vozhyk-,项目名称:gohan,代码行数:67,代码来源:server.go


注:本文中的github.com/cloudwan/gohan/schema.NewAuthorization函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。