ducky/devices
18:b2fdf827758e
Go to Latest
ducky/devices/vendor/github.com/pborman/uuid/node.go
Add endpoint for retrieving devices.
Add an endpoint for retrieving devices, either as a list or by ID.
Stub endpoints for updating and deleting devices., along with TODOs marking them
as things to still be completed. (Right now, accessing those endpoints is an
insta-panic.)
Simplify our handleCreateDevices by returning StatusUnauthorized if AuthUser
fails, so we can reserve StatusForbidden for when auth succeeds but access is
still denied. Also, delay the instantiation and allocation of a Response
variable until we're actually going to use it.
Create a handleGetDevices handler that authenticates the user, and if no ID is
set, returns a list of all their Devices. If one or more IDs are set, only those
Devices are returned. If ScopeViewPushToken is one of the scopes associated with
the request, the push tokens for each Device will be included in the response.
Otherwise, they will be omitted.
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.
10 interfaces []net.Interface // cached list of interfaces
11 ifname string // name of interface being used
12 nodeID []byte // hardware for version 1 UUIDs
15 // NodeInterface returns the name of the interface from which the NodeID was
16 // derived. The interface "user" is returned if the NodeID was set by
18 func NodeInterface() string {
22 // SetNodeInterface selects the hardware address to be used for Version 1 UUIDs.
23 // If name is "" then the first usable interface found will be used or a random
24 // Node ID will be generated. If a named interface cannot be found then false
27 // SetNodeInterface never fails when name is "".
28 func SetNodeInterface(name string) bool {
29 if interfaces == nil {
31 interfaces, err = net.Interfaces()
32 if err != nil && name != "" {
37 for _, ifs := range interfaces {
38 if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
39 if setNodeID(ifs.HardwareAddr) {
46 // We found no interfaces with a valid hardware address. If name
47 // does not specify a specific interface generate a random Node ID
51 nodeID = make([]byte, 6)
59 // NodeID returns a slice of a copy of the current Node ID, setting the Node ID
60 // if not already set.
61 func NodeID() []byte {
65 nid := make([]byte, 6)
70 // SetNodeID sets the Node ID to be used for Version 1 UUIDs. The first 6 bytes
71 // of id are used. If id is less than 6 bytes then false is returned and the
72 // Node ID is not set.
73 func SetNodeID(id []byte) bool {
81 func setNodeID(id []byte) bool {
86 nodeID = make([]byte, 6)
92 // NodeID returns the 6 byte node id encoded in uuid. It returns nil if uuid is
93 // not valid. The NodeID is only well defined for version 1 and 2 UUIDs.
94 func (uuid UUID) NodeID() []byte {
98 node := make([]byte, 6)