本文整理汇总了Golang中github.com/cloudwan/gohan/server/middleware.IdentityService类的典型用法代码示例。如果您正苦于以下问题:Golang IdentityService类的具体用法?Golang IdentityService怎么用?Golang IdentityService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IdentityService类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: fillInContext
func fillInContext(context middleware.Context, r *http.Request, w http.ResponseWriter, s *schema.Schema, sync sync.Sync, identityService middleware.IdentityService) {
context["path"] = r.URL.Path
context["http_request"] = r
context["http_response"] = w
context["schema"] = s
context["sync"] = sync
context["identity_service"] = identityService
context["service_auth"], _ = identityService.GetServiceAuthorization()
}
开发者ID:masaki-saeki,项目名称:gohan,代码行数:9,代码来源:api.go
示例2: fillInContext
func fillInContext(context middleware.Context, db db.DB,
r *http.Request, w http.ResponseWriter,
s *schema.Schema, p martini.Params, sync sync.Sync,
identityService middleware.IdentityService,
queue *job.Queue) {
context["path"] = r.URL.Path
context["http_request"] = r
context["http_response"] = w
context["schema"] = s
context["params"] = p
context["sync"] = sync
context["db"] = db
context["queue"] = queue
context["identity_service"] = identityService
context["service_auth"], _ = identityService.GetServiceAuthorization()
context["openstack_client"] = identityService.GetClient()
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:17,代码来源:api.go
示例3: UpdateResource
// UpdateResource updates the resource specified by the schema and ID using the dataMap
func UpdateResource(
context middleware.Context,
dataStore db.DB, identityService middleware.IdentityService,
resourceSchema *schema.Schema,
resourceID string, dataMap map[string]interface{},
) error {
context["id"] = resourceID
//load environment
environmentManager := extension.GetManager()
environment, ok := environmentManager.GetEnvironment(resourceSchema.ID)
if !ok {
return fmt.Errorf("No environment for schema")
}
auth := context["auth"].(schema.Authorization)
//load policy
policy, err := loadPolicy(context, "update", strings.Replace(resourceSchema.GetSingleURL(), ":id", resourceID, 1), auth)
if err != nil {
return err
}
context["policy"] = policy
//fillup default values
if tenantID, ok := dataMap["tenant_id"]; ok && tenantID != nil {
dataMap["tenant_name"], err = identityService.GetTenantName(tenantID.(string))
}
if err != nil {
return ResourceError{err, err.Error(), Unauthorized}
}
//check policy
err = policy.Check(schema.ActionUpdate, auth, dataMap)
delete(dataMap, "tenant_name")
if err != nil {
return ResourceError{err, err.Error(), Unauthorized}
}
context["resource"] = dataMap
if err := extension.HandleEvent(context, environment, "pre_update"); err != nil {
return err
}
if resourceData, ok := context["resource"].(map[string]interface{}); ok {
dataMap = resourceData
}
if err := InTransaction(
context, dataStore,
transaction.GetIsolationLevel(resourceSchema, schema.ActionUpdate),
func() error {
return UpdateResourceInTransaction(context, resourceSchema, resourceID, dataMap, policy.GetTenantIDFilter(schema.ActionUpdate, auth.TenantID()))
},
); err != nil {
return err
}
if err := extension.HandleEvent(context, environment, "post_update"); err != nil {
return err
}
if err := ApplyPolicyForResource(context, resourceSchema); err != nil {
return ResourceError{err, "", NotFound}
}
return nil
}
开发者ID:cloudwan,项目名称:gohan,代码行数:69,代码来源:resource_management.go
示例4: CreateResource
// CreateResource creates the resource specified by the schema and dataMap
func CreateResource(
context middleware.Context,
dataStore db.DB,
identityService middleware.IdentityService,
resourceSchema *schema.Schema,
dataMap map[string]interface{},
) error {
manager := schema.GetManager()
// Load environment
environmentManager := extension.GetManager()
environment, ok := environmentManager.GetEnvironment(resourceSchema.ID)
if !ok {
return fmt.Errorf("No environment for schema")
}
auth := context["auth"].(schema.Authorization)
//LoadPolicy
policy, err := loadPolicy(context, "create", resourceSchema.GetPluralURL(), auth)
if err != nil {
return err
}
_, err = resourceSchema.GetPropertyByID("tenant_id")
if _, ok := dataMap["tenant_id"]; err == nil && !ok {
dataMap["tenant_id"] = context["tenant_id"]
}
if tenantID, ok := dataMap["tenant_id"]; ok && tenantID != nil {
dataMap["tenant_name"], err = identityService.GetTenantName(tenantID.(string))
if err != nil {
return ResourceError{err, err.Error(), Unauthorized}
}
}
//Apply policy for api input
err = policy.Check(schema.ActionCreate, auth, dataMap)
if err != nil {
return ResourceError{err, err.Error(), Unauthorized}
}
delete(dataMap, "tenant_name")
// apply property filter
err = policy.ApplyPropertyConditionFilter(schema.ActionCreate, dataMap, nil)
if err != nil {
return ResourceError{err, err.Error(), Unauthorized}
}
context["resource"] = dataMap
if id, ok := dataMap["id"]; !ok || id == "" {
dataMap["id"] = uuid.NewV4().String()
}
context["id"] = dataMap["id"]
if err := extension.HandleEvent(context, environment, "pre_create"); err != nil {
return err
}
if resourceData, ok := context["resource"].(map[string]interface{}); ok {
dataMap = resourceData
}
//Validation
err = resourceSchema.ValidateOnCreate(dataMap)
if err != nil {
return ResourceError{err, fmt.Sprintf("Validation error: %s", err), WrongData}
}
resource, err := manager.LoadResource(resourceSchema.ID, dataMap)
if err != nil {
return err
}
//Fillup default
err = resource.PopulateDefaults()
if err != nil {
return err
}
context["resource"] = resource.Data()
if err := InTransaction(
context, dataStore,
transaction.GetIsolationLevel(resourceSchema, schema.ActionCreate),
func() error {
return CreateResourceInTransaction(context, resource)
},
); err != nil {
return err
}
if err := extension.HandleEvent(context, environment, "post_create"); err != nil {
return err
}
if err := ApplyPolicyForResource(context, resourceSchema); err != nil {
return ResourceError{err, "", Unauthorized}
}
return nil
}
开发者ID:cloudwan,项目名称:gohan,代码行数:100,代码来源:resource_management.go
注:本文中的github.com/cloudwan/gohan/server/middleware.IdentityService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论