luci: Index | Files | Directories

package common

import ""


Package Files

acl.go config.go error.go pubsub.go testBundle.go


const ServiceConfigID = "service_config"

ServiceConfigID is the key for the service config entity in datastore.


var ErrConsoleNotFound = errors.New("console not found", CodeNotFound)

ErrConsoleNotFound is returned from GetConsole if the requested console isn't known to exist.

func BucketPermissions Uses

func BucketPermissions(c context.Context, buckets ...string) (bbAccess.Permissions, error)

BucketPermissions gets permissions for the current identity for all given buckets.

TODO(mknyszek): If a cache entry expires, then there could be QPS issues if all instances query buildbucket for an update simultaneously. Evaluate whether there's an issue in practice, and if so, consider expiring cache entries randomly.

func EnsurePubSubSubscribed Uses

func EnsurePubSubSubscribed(c context.Context, settings *config.Settings) error

EnsurePubSubSubscribed makes sure the following subscriptions are in place: * buildbucket, via the settings.Buildbucket.Topic setting

func GetSettings Uses

func GetSettings(c context.Context) *config.Settings

GetSettings returns the service (aka global) config for the current instance of Milo from the datastore. Returns an empty config and warn heavily if none is found. TODO(hinoka): Use process cache to cache configs.

func IsAdmin Uses

func IsAdmin(c context.Context) (bool, error)

IsAdmin returns true if the current identity is an administrator.

func IsAllowed Uses

func IsAllowed(c context.Context, project string) (bool, error)

IsAllowed checks to see if the user in the context is allowed to access the given project.

func LuciConfigURL Uses

func LuciConfigURL(c context.Context, configSet, path, revision string) string

LuciConfigURL returns a user friendly URL that specifies where to view this console definition.

func ReplaceNSEWith Uses

func ReplaceNSEWith(err errors.MultiError, replacement error) error

ReplaceNSEWith takes an errors.MultiError returned by a datastore.Get() on a slice (which is always a MultiError), filters out all datastore.ErrNoSuchEntitiy or replaces it with replacement instances, and returns an error generated by errors.LazyMultiError.

func UpdateConsoles Uses

func UpdateConsoles(c context.Context) error

UpdateConsoles updates internal console definitions entities based off luci-config.

func UpdateServiceConfig Uses

func UpdateServiceConfig(c context.Context) (*config.Settings, error)

UpdateServiceConfig fetches the service config from luci-config and then stores a snapshot of the configuration in datastore.

func WithAccessClient Uses

func WithAccessClient(c context.Context, a *AccessClient) context.Context

WithAccessClient attaches an AccessClient to the given context.

type AccessClient Uses

type AccessClient struct {
    Host string

AccessClient wraps an accessProto.AccessClient and exports its Host.

func GetAccessClient Uses

func GetAccessClient(c context.Context) *AccessClient

GetAccessClient retrieves an AccessClient from the given context.

func NewAccessClient Uses

func NewAccessClient(c context.Context) (*AccessClient, error)

NewAccessClient creates a new AccessClient for talking to this milo instance's buildbucket instance.

type Console Uses

type Console struct {
    // Parent is a key to the parent Project entity where this console was
    // defined in.
    Parent *datastore.Key `gae:"$parent"`

    // ID is the ID of the console.
    ID  string `gae:"$id"`

    // Ordinal specifies the console's ordering in its project's consoles list.
    Ordinal int

    // The URL to the luci-config definition of this console.
    ConfigURL string

    // The luci-config reivision from when this Console was retrieved.
    ConfigRevision string `gae:",noindex"`

    // (indexed) All builder IDs mentioned by this console config.
    Builders []string

    // Def is the actual underlying proto Console definition.
    Def config.Console `gae:",noindex"`
    // contains filtered or unexported fields

Console is a datastore entity representing a single console.

func GetAllConsoles Uses

func GetAllConsoles(c context.Context, builderID string) ([]*Console, error)

GetAllConsoles returns all Consoles (across all projects) which contian the builder ID. If builderID is empty, then this retrieves all Consoles.

TODO-perf(iannucci): Maybe memcache this too.

func GetConsole Uses

func GetConsole(c context.Context, proj, id string) (*Console, error)

GetConsole returns the requested console.

TODO-perf(iannucci,hinoka): Memcache this.

func GetConsoles Uses

func GetConsoles(c context.Context, consoles []ConsoleID) ([]*Console, error)

GetConsoles returns the requested consoles.

TODO-perf(iannucci,hinoka): Memcache this.

func GetProjectConsoles Uses

func GetProjectConsoles(c context.Context, projectID string) ([]*Console, error)

GetProjectConsoles returns all consoles for the given project ordered as in config.

func (*Console) Buckets Uses

func (c *Console) Buckets() stringset.Set

Buckets returns all buckets referenced by this Console's Builders.

func (*Console) ConsoleID Uses

func (c *Console) ConsoleID() ConsoleID

func (*Console) FilterBuilders Uses

func (c *Console) FilterBuilders(perms access.Permissions)

FilterBuilders uses an access.Permissions to filter out builder IDs and builders from the definition, and builders in the definition's header, which are not allowed by the permissions.

func (*Console) ProjectID Uses

func (c *Console) ProjectID() string

ProjectID retrieves the project ID string of the console out of the Console's parent key.

type ConsoleID Uses

type ConsoleID struct {
    Project string
    ID      string

ConsoleID is a reference to a console.

func ParseConsoleID Uses

func ParseConsoleID(id string) (cid ConsoleID, err error)

func (*ConsoleID) SetID Uses

func (id *ConsoleID) SetID(c context.Context, console *Console) *Console

NewEntity returns an empty Console datastore entity keyed with itself.

func (*ConsoleID) String Uses

func (id *ConsoleID) String() string

type ErrorCode Uses

type ErrorCode int

ErrorCode represents milo's internal error code system. The subsystems in milo can attach an ErrorCode to an error (using ErrorTag), and then the html and grpc frontends know how to render the error in a way that will help the user.

const (
    // CodeUnknown means an error happened, but we weren't able to classify it.
    CodeUnknown ErrorCode = iota

    // CodeUnauthorized occurs when a user isn't logged in, but needs to be to
    // proceed further.

    // CodeNoAccess occurs when the currently logged-in user is not permitted to
    // see the resource.

    // CodeNotFound occurs when we weren't able to find the build that the
    // user asked for.

    // CodeParameterError occurs when one or more of the user-provided parameters
    // was malformed.

    // CodeOK indicates absense of any error.

func ErrorCodeIn Uses

func ErrorCodeIn(err error) ErrorCode

ErrorCodeIn returns the ErrorCode in err. If err is nil, returns CodeOK. If not present, returns CodeUnknown.

func (ErrorCode) GenerateErrorTagValue Uses

func (c ErrorCode) GenerateErrorTagValue() errors.TagValue

GenerateErrorTagValue implements errors.TagValueGenerator so that ErrorCodes can be used like:

errors.New("terrible thing", CodeNotFound)

func (ErrorCode) HTTPStatus Uses

func (c ErrorCode) HTTPStatus() int

HTTPStatus returns an HTTP Status code corresponding to this ErrorCode.

func (ErrorCode) Tag Uses

func (c ErrorCode) Tag() errors.TagValue

Tag returns an errors.TagValue for this code.

type Project Uses

type Project struct {
    ID      string `gae:"$id"`
    LogoURL string

Project is a datastore entity representing a single project. Its children are consoles.

func GetAllProjects Uses

func GetAllProjects(c context.Context) ([]Project, error)

GetAllProjects returns all projects the current user has access to.

type PubSubMessage Uses

type PubSubMessage struct {
    Attributes map[string]interface{} `json:"attributes"`
    Data       string                 `json:"data"`
    MessageID  string                 `json:"message_id"`

type PubSubSubscription Uses

type PubSubSubscription struct {
    Message      PubSubMessage `json:"message"`
    Subscription string        `json:"subscription"`

func (*PubSubSubscription) GetData Uses

func (m *PubSubSubscription) GetData() ([]byte, error)

GetData returns the expanded form of Data (decoded from base64).

type ServiceConfig Uses

type ServiceConfig struct {
    // ID is the datastore key.  This should be static, as there should only be
    // one service config.
    ID  string `gae:"$id"`
    // Revision is the revision of the config, taken from luci-config.  This is used
    // to determine if the entry needs to be refreshed.
    Revision string
    // Data is the binary proto of the config.
    Data []byte `gae:",noindex"`
    // Text is the text format of the config.  For human consumption only.
    Text string `gae:",noindex"`
    // LastUpdated is the time this config was last updated.
    LastUpdated time.Time

ServiceConfig is a container for the instance's service config.

func GetCurrentServiceConfig Uses

func GetCurrentServiceConfig(c context.Context) (*ServiceConfig, error)

GetCurrentServiceConfig gets the service config for the instance from either process cache or datastore cache.

type TestBundle Uses

type TestBundle struct {
    // Description is a short one line description of what the data contains.
    Description string
    // Data is the data fed directly into the template.
    Data templates.Args

TestBundle is a template arg associated with a description used for testing.



Package common imports 31 packages (graph) and is imported by 21 packages. Updated 2018-12-14. Refresh now. Tools for package owners.