Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions note/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type DeviceSession struct {
SessionUID string `json:"session,omitempty"`
// When the session was initially opened
SessionBegan int64 `json:"session_began,omitempty"`
// When a persistent session was last updated
SessionUpdated int64 `json:"session_updated,omitempty"`
// Why a session was opened
WhySessionOpened string `json:"why_session_opened,omitempty"`
// When the session was initially opened
Expand Down Expand Up @@ -80,6 +82,8 @@ type DeviceSession struct {
HighPowerCyclesTotal uint32 `json:"hp_cycles_total,omitempty"`
HighPowerCyclesData uint32 `json:"hp_cycles_data,omitempty"`
HighPowerCyclesGPS uint32 `json:"hp_cycles_gps,omitempty"`
// Amount of packet usage within the session, keyed by PSID
PacketUsage map[string]PacketUsage `json:"packet_usage,omitempty"`
// Total device usage at the beginning of the period
ThisPtr *DeviceUsage `json:"this,omitempty"`
// Total device usage at the beginning of the next period, whenever it happens to occur
Expand Down Expand Up @@ -123,6 +127,18 @@ func (s *DeviceSession) Period() *DeviceUsage {
return s.PeriodPtr
}

// Indication of the packet usage within a session
type PacketUsage struct {
Updated int64 `json:"updated,omitempty"`
DownlinkPackets int64 `json:"dl_p,omitempty"`
DownlinkBytes int64 `json:"dl_b,omitempty"`
DownlinkBytesBillable int64 `json:"dl_bb,omitempty"`
UplinkPackets int64 `json:"ul_p,omitempty"`
UplinkBytes int64 `json:"ul_b,omitempty"`
UplinkBytesBillable int64 `json:"ul_bb,omitempty"`
BillableMinBytesPerPacket int64 `json:"bmbpp,omitempty"`
}

// TowerLocation is a location structure generated by a lookup
type TowerLocation struct {
Source string `json:"source,omitempty"` // source of this location
Expand Down
2 changes: 2 additions & 0 deletions note/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type DeviceUsage struct {
SentBytesSecondary uint32 `json:"bytes_sent_secondary,omitempty"`
TCPSessions uint32 `json:"sessions_tcp,omitempty"`
TLSSessions uint32 `json:"sessions_tls,omitempty"`
PacketSessions uint32 `json:"sessions_packet,omitempty"`
WebhookSessions uint32 `json:"sessions_webhook,omitempty"`
RcvdNotes uint32 `json:"notes_rcvd,omitempty"`
SentNotes uint32 `json:"notes_sent,omitempty"`
}
1 change: 0 additions & 1 deletion notecard/i2c-unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Forked from github.com/davecheney/i2c

//go:build !windows
// +build !windows

// Before usage you must load the i2c-dev kernel module.
// Each i2c bus can address 127 independent i2c devices, and most
Expand Down
1 change: 0 additions & 1 deletion notecard/i2c-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// copyright holder including that found in the LICENSE file.

//go:build windows
// +build windows

package notecard

Expand Down
1 change: 1 addition & 0 deletions notecard/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ type Request struct {
Voltage float64 `json:"voltage,omitempty"`
MilliampHours float64 `json:"milliamp_hours,omitempty"`
Default bool `json:"default,omitempty"`
In bool `json:"in,omitempty"`
}

// A Note on Time
Expand Down
1 change: 0 additions & 1 deletion notecard/serial-unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// copyright holder including that found in the LICENSE file.

//go:build !windows
// +build !windows

package notecard

Expand Down
1 change: 0 additions & 1 deletion notecard/serial-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// copyright holder including that found in the LICENSE file.

//go:build windows
// +build windows

// If you have odd serial port behavior (where responses are apparently lost or delayed), try this:
// 1) open Control Panel -> Device Manager -> Ports (COM & LPT)
Expand Down
13 changes: 11 additions & 2 deletions notehub/api/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type FleetResponse struct {

EnvironmentVariables map[string]string `json:"environment_variables"`

SmartRule string `json:"smart_rule,omitempty"`
WatchdogMins int64 `json:"watchdog_mins,omitempty"`
SmartRule string `json:"smart_rule,omitempty"`
WatchdogMins int64 `json:"watchdog_mins,omitempty"`
ConnectivityAssurance FleetConnectivityAssurance `json:"connectivity_assurance,omitempty"`
}

// PutDeviceFleetsRequest v1
Expand Down Expand Up @@ -67,3 +68,11 @@ type PutFleetRequest struct {
SmartRule string `json:"smart_rule,omitempty"`
WatchdogMins int64 `json:"watchdog_mins,omitempty"`
}

// FleetConnectivityAssurance v1
//
// Includes, Enabled = Whether Connectivity Assurance is enabled for this fleet
// With flexibility to add more information in the future
type FleetConnectivityAssurance struct {
Enabled bool `json:"enabled"`
}
25 changes: 19 additions & 6 deletions notehub/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,21 @@ func RevokeAccessToken(hub, token string) error {
// InitiateBrowserBasedLogin starts the OAuth2 login flow by opening the user's browser.
// the `hub` parameter is the hostname of Notehub where it is assumed that an OAuth2 client
// with client ID `notehub_cli` is configured for authorization code flow.
func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) {
func InitiateBrowserBasedLogin(notehubApiHost string) (*AccessToken, error) {
// this is the hard-coded OAuth client ID that's persisted in Hydra
clientId := "notehub_cli"

if !strings.HasPrefix(notehubApiHost, "api.") {
notehubApiHost = "api." + notehubApiHost
}

var notehubUiHost string
if notehubApiHost == "api.notefile.net" {
notehubUiHost = "notehub.io"
} else {
notehubUiHost = strings.TrimPrefix(notehubApiHost, "api.")
}

// Try these ports in order until one is available:
//
// these ports are randomly chosen and hard-coded into
Expand Down Expand Up @@ -157,7 +168,7 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) {
tokenResp, err := http.Post(
(&url.URL{
Scheme: "https",
Host: hub,
Host: notehubUiHost,
Path: "/oauth2/token",
}).String(),
"application/x-www-form-urlencoded",
Expand Down Expand Up @@ -217,7 +228,7 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) {
// Get user's information (specifically email)
///////////////////////////////////////////

req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/userinfo", hub), nil)
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/userinfo", notehubApiHost), nil)
if err != nil {
errHandler("could not create request for /userinfo: " + err.Error())
return
Expand Down Expand Up @@ -253,7 +264,7 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) {
///////////////////////////////////////////

accessToken = &AccessToken{
Host: hub,
Host: notehubApiHost,
Email: email,
AccessToken: accessTokenString,
ExpiresAt: time.Now().Add(expiresIn),
Expand Down Expand Up @@ -304,7 +315,7 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) {
// Build the authorize URL using the chosen port
authorizeUrl := url.URL{
Scheme: "https",
Host: hub,
Host: notehubUiHost,
Path: "/oauth2/auth",
RawQuery: url.Values{
"client_id": {clientId},
Expand All @@ -319,7 +330,9 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) {

// Open web browser to authorize
fmt.Printf("Opening web browser to initiate authentication (redirect port %d)...\n", chosenPort)
open(authorizeUrl.String())
if err := open(authorizeUrl.String()); err != nil {
fmt.Printf("error opening web browser: %v", err)
}

// Wait for exchange to finish
<-done
Expand Down
9 changes: 9 additions & 0 deletions notehub/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ import (
// HubDeviceContact (golint)
const HubDeviceContact = "hub.device.contact"

// HubDeviceSessionBegin (golint)
const HubDeviceSessionBegin = "hub.device.session.begin"

// HubDeviceSessionUsage (golint)
const HubDeviceSessionUsage = "hub.device.session.usage"

// HubDeviceSessionEnd (golint)
const HubDeviceSessionEnd = "hub.device.session.end"

// HubAppGetSchemas (golint)
const HubAppGetSchemas = "hub.app.schemas.get"

Expand Down