feat: expand companion platform, device controls, and memoir workflows
ci / verify (push) Canceled after 0s
ci / verify (push) Canceled after 0s
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
This commit is contained in:
@@ -58,7 +58,7 @@ func NewHTTPRegistrar(endpoint, productSecret string, timeout time.Duration) (*H
|
||||
}
|
||||
return &HTTPRegistrar{
|
||||
endpoint: endpoint, productSecret: strings.TrimSpace(productSecret),
|
||||
client: &http.Client{Timeout: timeout}, now: time.Now,
|
||||
client: &http.Client{Timeout: timeout, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}, now: time.Now,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -104,15 +104,17 @@ func (r *HTTPRegistrar) Register(ctx context.Context, input RegisterInput) (Regi
|
||||
} `json:"Error"`
|
||||
} `json:"ResponseMetadata"`
|
||||
Result struct {
|
||||
Payload string `json:"payload"`
|
||||
RTCAppID string `json:"RTCAppID"`
|
||||
Payload string `json:"payload"`
|
||||
RTCAppID string `json:"RTCAppID"`
|
||||
RTCAppIDAlt string `json:"rtc_app_id"`
|
||||
} `json:"Result"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &payload); err != nil {
|
||||
return RegisterResult{}, fmt.Errorf("decode Volcengine dynamic registration response: HTTP %d", response.StatusCode)
|
||||
}
|
||||
if response.StatusCode < 200 || response.StatusCode >= 300 || payload.ResponseMetadata.Error.Code != "" || payload.ResponseMetadata.Error.CodeN != nil {
|
||||
codeN := fmt.Sprint(payload.ResponseMetadata.Error.CodeN)
|
||||
if response.StatusCode < 200 || response.StatusCode >= 300 || payload.ResponseMetadata.Error.Code != "" || (payload.ResponseMetadata.Error.CodeN != nil && codeN != "0") {
|
||||
code := payload.ResponseMetadata.Error.Code
|
||||
if code == "" {
|
||||
code = fmt.Sprintf("HTTP_%d", response.StatusCode)
|
||||
@@ -130,7 +132,14 @@ func (r *HTTPRegistrar) Register(ctx context.Context, input RegisterInput) (Regi
|
||||
if err != nil {
|
||||
return RegisterResult{}, err
|
||||
}
|
||||
return RegisterResult{DeviceSecret: secret, RTCAppID: strings.TrimSpace(payload.Result.RTCAppID)}, nil
|
||||
appID := strings.TrimSpace(payload.Result.RTCAppID)
|
||||
if appID == "" {
|
||||
appID = strings.TrimSpace(payload.Result.RTCAppIDAlt)
|
||||
}
|
||||
if appID == "" {
|
||||
return RegisterResult{}, errors.New("Volcengine registration response missing RTCAppID")
|
||||
}
|
||||
return RegisterResult{DeviceSecret: secret, RTCAppID: appID}, nil
|
||||
}
|
||||
|
||||
func decryptRegisteredDeviceSecret(encoded, productSecret string) (string, error) {
|
||||
|
||||
@@ -71,6 +71,36 @@ func TestDisabledProvisioningDoesNotRequireProductSecret(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPRegistrarRTCAppIDVariantsAndMissingID(t *testing.T) {
|
||||
for _, field := range []string{"RTCAppID", "rtc_app_id", "missing"} {
|
||||
t.Run(field, func(t *testing.T) {
|
||||
const productSecret = "1234567890abcdef-product-secret"
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
result := map[string]any{"payload": encryptDeviceSecretForTest(t, "fixture-device-secret-123456789", productSecret)}
|
||||
if field != "missing" {
|
||||
result[field] = "rtc-app"
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"Result": result, "ResponseMetadata": map[string]any{"Error": map[string]any{"CodeN": 0}}})
|
||||
}))
|
||||
defer server.Close()
|
||||
r, err := NewHTTPRegistrar(server.URL, productSecret, time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out, err := r.Register(context.Background(), RegisterInput{"instance", "product", "device"})
|
||||
if field == "missing" {
|
||||
if err == nil {
|
||||
t.Fatal("missing RTCAppID was accepted")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil || out.RTCAppID != "rtc-app" {
|
||||
t.Fatalf("app ID decoding failed: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func encryptDeviceSecretForTest(t *testing.T, secret, productSecret string) string {
|
||||
t.Helper()
|
||||
key := []byte(productSecret)[:aes.BlockSize]
|
||||
|
||||
Reference in New Issue
Block a user