| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "strings" | 8 "strings" |
| 9 | 9 |
| 10 "github.com/luci/gae/service/info" | 10 "github.com/luci/gae/service/info" |
| 11 log "github.com/luci/luci-go/common/logging" | |
| 12 "github.com/luci/luci-go/logdog/api/config/svcconfig" | 11 "github.com/luci/luci-go/logdog/api/config/svcconfig" |
| 13 "github.com/luci/luci-go/logdog/appengine/coordinator/config" | |
| 14 "github.com/luci/luci-go/luci_config/common/cfgtypes" | 12 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 15 | 13 |
| 16 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
| 17 ) | 15 ) |
| 18 | 16 |
| 19 const ( | 17 const ( |
| 20 // projectNamespacePrefix is the datastore namespace prefix for project | 18 // projectNamespacePrefix is the datastore namespace prefix for project |
| 21 // namespaces. | 19 // namespaces. |
| 22 projectNamespacePrefix = "luci." | 20 projectNamespacePrefix = "luci." |
| 23 ) | 21 ) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 53 } | 51 } |
| 54 | 52 |
| 55 // CurrentProjectConfig returns the project-specific configuration for the | 53 // CurrentProjectConfig returns the project-specific configuration for the |
| 56 // current project. | 54 // current project. |
| 57 // | 55 // |
| 58 // If there is no current project namespace, or if the current project has no | 56 // If there is no current project namespace, or if the current project has no |
| 59 // configuration, config.ErrInvalidConfig will be returned. | 57 // configuration, config.ErrInvalidConfig will be returned. |
| 60 func CurrentProjectConfig(c context.Context) (*svcconfig.ProjectConfig, error) { | 58 func CurrentProjectConfig(c context.Context) (*svcconfig.ProjectConfig, error) { |
| 61 return GetServices(c).ProjectConfig(c, CurrentProject(c)) | 59 return GetServices(c).ProjectConfig(c, CurrentProject(c)) |
| 62 } | 60 } |
| 63 | |
| 64 // ActiveUserProjects returns a full list of all config service projects with | |
| 65 // LogDog project configurations that the current user has READ access to. | |
| 66 // | |
| 67 // TODO: Load project configs and all project configs lists from datastore. Add | |
| 68 // a background cron job to periodically update these lists from luci-config. | |
| 69 // This should be a generic config service capability. | |
| 70 func ActiveUserProjects(c context.Context) (map[cfgtypes.ProjectName]*svcconfig.
ProjectConfig, error) { | |
| 71 allPcfgs, err := config.AllProjectConfigs(c) | |
| 72 if err != nil { | |
| 73 return nil, err | |
| 74 } | |
| 75 | |
| 76 for project, pcfg := range allPcfgs { | |
| 77 // Verify user READ access. | |
| 78 if err := IsProjectReader(c, pcfg); err != nil { | |
| 79 delete(allPcfgs, project) | |
| 80 | |
| 81 // If it is a membership error, prune this project and c
ontinue. | |
| 82 // Otherwise, forward the error. | |
| 83 if !IsMembershipError(err) { | |
| 84 // No configuration for this project, the config
uration is invalid, or | |
| 85 // the user didn't have access. Remove it from t
he list. | |
| 86 log.Fields{ | |
| 87 log.ErrorKey: err, | |
| 88 "project": project, | |
| 89 }.Errorf(c, "Failed to check project.") | |
| 90 return nil, err | |
| 91 } | |
| 92 } | |
| 93 } | |
| 94 return allPcfgs, nil | |
| 95 } | |
| OLD | NEW |