ducky/devices

Paddy 2015-12-19 Parent:vendor/code.google.com/p/go-uuid/uuid/dce.go@b6494e1a499e

16:a700ede02f91 Go to Latest

ducky/devices/vendor/github.com/pborman/uuid/dce.go

Validate device creation. Update our uuid package to the latest, which is now based on the GitHub fork instead of the Google Code. Also, update our api package to its latest version, which now needs the pqarrays package as a dependency. We fleshed out the validateDeviceCreation. We now pass in the scopes we have (for broad access control) and the user ID (for fine-grained access control). This helper returns the first error it encounters, though it should probably return a slice so we can return multiple errors all at once. Before we even decode the request to create a Device, let's check if the user is even logged in. If we can't ascertain that or they're not, there's no point in even consuming the memory necessary to read the request, because we know we're not going to use it anyways. Finally actually validate the devices we're creating, and return an appropriate error for each error we can get. Also, the api.CheckScopes helper function now takes the scopes passed in as a string slice, and we have an api.GetScopes helper function to retrieve the scopes associated with the request. Let's not keep parsing that. We need two new scopes to control access for device creation; ScopeImport lets users import devices in and is pretty much admin access. ScopeCreateOtherUserDevices allows a user to create Devices that are owned by another user.

History
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/vendor/github.com/pborman/uuid/dce.go	Sat Dec 19 00:18:25 2015 -0800
     1.3 @@ -0,0 +1,84 @@
     1.4 +// Copyright 2011 Google Inc.  All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style
     1.6 +// license that can be found in the LICENSE file.
     1.7 +
     1.8 +package uuid
     1.9 +
    1.10 +import (
    1.11 +	"encoding/binary"
    1.12 +	"fmt"
    1.13 +	"os"
    1.14 +)
    1.15 +
    1.16 +// A Domain represents a Version 2 domain
    1.17 +type Domain byte
    1.18 +
    1.19 +// Domain constants for DCE Security (Version 2) UUIDs.
    1.20 +const (
    1.21 +	Person = Domain(0)
    1.22 +	Group  = Domain(1)
    1.23 +	Org    = Domain(2)
    1.24 +)
    1.25 +
    1.26 +// NewDCESecurity returns a DCE Security (Version 2) UUID.
    1.27 +//
    1.28 +// The domain should be one of Person, Group or Org.
    1.29 +// On a POSIX system the id should be the users UID for the Person
    1.30 +// domain and the users GID for the Group.  The meaning of id for
    1.31 +// the domain Org or on non-POSIX systems is site defined.
    1.32 +//
    1.33 +// For a given domain/id pair the same token may be returned for up to
    1.34 +// 7 minutes and 10 seconds.
    1.35 +func NewDCESecurity(domain Domain, id uint32) UUID {
    1.36 +	uuid := NewUUID()
    1.37 +	if uuid != nil {
    1.38 +		uuid[6] = (uuid[6] & 0x0f) | 0x20 // Version 2
    1.39 +		uuid[9] = byte(domain)
    1.40 +		binary.BigEndian.PutUint32(uuid[0:], id)
    1.41 +	}
    1.42 +	return uuid
    1.43 +}
    1.44 +
    1.45 +// NewDCEPerson returns a DCE Security (Version 2) UUID in the person
    1.46 +// domain with the id returned by os.Getuid.
    1.47 +//
    1.48 +//  NewDCEPerson(Person, uint32(os.Getuid()))
    1.49 +func NewDCEPerson() UUID {
    1.50 +	return NewDCESecurity(Person, uint32(os.Getuid()))
    1.51 +}
    1.52 +
    1.53 +// NewDCEGroup returns a DCE Security (Version 2) UUID in the group
    1.54 +// domain with the id returned by os.Getgid.
    1.55 +//
    1.56 +//  NewDCEGroup(Group, uint32(os.Getgid()))
    1.57 +func NewDCEGroup() UUID {
    1.58 +	return NewDCESecurity(Group, uint32(os.Getgid()))
    1.59 +}
    1.60 +
    1.61 +// Domain returns the domain for a Version 2 UUID or false.
    1.62 +func (uuid UUID) Domain() (Domain, bool) {
    1.63 +	if v, _ := uuid.Version(); v != 2 {
    1.64 +		return 0, false
    1.65 +	}
    1.66 +	return Domain(uuid[9]), true
    1.67 +}
    1.68 +
    1.69 +// Id returns the id for a Version 2 UUID or false.
    1.70 +func (uuid UUID) Id() (uint32, bool) {
    1.71 +	if v, _ := uuid.Version(); v != 2 {
    1.72 +		return 0, false
    1.73 +	}
    1.74 +	return binary.BigEndian.Uint32(uuid[0:4]), true
    1.75 +}
    1.76 +
    1.77 +func (d Domain) String() string {
    1.78 +	switch d {
    1.79 +	case Person:
    1.80 +		return "Person"
    1.81 +	case Group:
    1.82 +		return "Group"
    1.83 +	case Org:
    1.84 +		return "Org"
    1.85 +	}
    1.86 +	return fmt.Sprintf("Domain%d", int(d))
    1.87 +}