ducky/devices
2015-11-29
Parent:b6494e1a499e
ducky/devices/vendor/code.google.com/p/go-uuid/uuid/dce.go
Set up DeleteDevices in Memstore. Implement the DeleteDevices method for our Memstore, removing the Devices specified by the passed IDs. Also, create a simple test that verifies that when Devices are deleted, only the Devices you intend to delete are actually deleted. Further tests should be written to verify that this extends to ListDevicesByOwner (e.g., deleted devices will not be returned when listing them), CreateDevices (e.g., will not result in an ErrDeviceAlreadyExists error), and UpdateDevice (e.g., will return an ErrDeviceNotFound error after the Device is deleted). But for now, we're confident that it works in the simplest possible case.
1 // Copyright 2011 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package uuid
7 import (
8 "encoding/binary"
9 "fmt"
10 "os"
11 )
13 // A Domain represents a Version 2 domain
14 type Domain byte
16 // Domain constants for DCE Security (Version 2) UUIDs.
17 const (
18 Person = Domain(0)
19 Group = Domain(1)
20 Org = Domain(2)
21 )
23 // NewDCESecurity returns a DCE Security (Version 2) UUID.
24 //
25 // The domain should be one of Person, Group or Org.
26 // On a POSIX system the id should be the users UID for the Person
27 // domain and the users GID for the Group. The meaning of id for
28 // the domain Org or on non-POSIX systems is site defined.
29 //
30 // For a given domain/id pair the same token may be returned for up to
31 // 7 minutes and 10 seconds.
32 func NewDCESecurity(domain Domain, id uint32) UUID {
33 uuid := NewUUID()
34 if uuid != nil {
35 uuid[6] = (uuid[6] & 0x0f) | 0x20 // Version 2
36 uuid[9] = byte(domain)
37 binary.BigEndian.PutUint32(uuid[0:], id)
38 }
39 return uuid
40 }
42 // NewDCEPerson returns a DCE Security (Version 2) UUID in the person
43 // domain with the id returned by os.Getuid.
44 //
45 // NewDCEPerson(Person, uint32(os.Getuid()))
46 func NewDCEPerson() UUID {
47 return NewDCESecurity(Person, uint32(os.Getuid()))
48 }
50 // NewDCEGroup returns a DCE Security (Version 2) UUID in the group
51 // domain with the id returned by os.Getgid.
52 //
53 // NewDCEGroup(Group, uint32(os.Getgid()))
54 func NewDCEGroup() UUID {
55 return NewDCESecurity(Group, uint32(os.Getgid()))
56 }
58 // Domain returns the domain for a Version 2 UUID or false.
59 func (uuid UUID) Domain() (Domain, bool) {
60 if v, _ := uuid.Version(); v != 2 {
61 return 0, false
62 }
63 return Domain(uuid[9]), true
64 }
66 // Id returns the id for a Version 2 UUID or false.
67 func (uuid UUID) Id() (uint32, bool) {
68 if v, _ := uuid.Version(); v != 2 {
69 return 0, false
70 }
71 return binary.BigEndian.Uint32(uuid[0:4]), true
72 }
74 func (d Domain) String() string {
75 switch d {
76 case Person:
77 return "Person"
78 case Group:
79 return "Group"
80 case Org:
81 return "Org"
82 }
83 return fmt.Sprintf("Domain%d", int(d))
84 }