Set implements NsEndDeviceRegistryServer.
(ctx context.Context, req *ttnpb.SetEndDeviceRequest)
| 316 | |
| 317 | // Set implements NsEndDeviceRegistryServer. |
| 318 | func (ns *NetworkServer) Set(ctx context.Context, req *ttnpb.SetEndDeviceRequest) (*ttnpb.EndDevice, error) { // nolint: gocyclo,lll |
| 319 | st := newSetDeviceState(req.EndDevice, req.FieldMask.GetPaths()...) |
| 320 | |
| 321 | requiredRights := append(make([]ttnpb.Right, 0, 2), |
| 322 | ttnpb.Right_RIGHT_APPLICATION_DEVICES_WRITE, |
| 323 | ) |
| 324 | if st.HasSetField( |
| 325 | "pending_mac_state.queued_join_accept.keys.app_s_key.encrypted_key", |
| 326 | "pending_mac_state.queued_join_accept.keys.app_s_key.kek_label", |
| 327 | "pending_mac_state.queued_join_accept.keys.app_s_key.key", |
| 328 | "pending_mac_state.queued_join_accept.keys.f_nwk_s_int_key.key", |
| 329 | "pending_mac_state.queued_join_accept.keys.nwk_s_enc_key.key", |
| 330 | "pending_mac_state.queued_join_accept.keys.s_nwk_s_int_key.key", |
| 331 | "pending_mac_state.queued_join_accept.keys.session_key_id", |
| 332 | "pending_session.keys.f_nwk_s_int_key.key", |
| 333 | "pending_session.keys.nwk_s_enc_key.key", |
| 334 | "pending_session.keys.s_nwk_s_int_key.key", |
| 335 | "pending_session.keys.session_key_id", |
| 336 | "session.keys.f_nwk_s_int_key.key", |
| 337 | "session.keys.nwk_s_enc_key.key", |
| 338 | "session.keys.s_nwk_s_int_key.key", |
| 339 | "session.keys.session_key_id", |
| 340 | ) { |
| 341 | requiredRights = append(requiredRights, ttnpb.Right_RIGHT_APPLICATION_DEVICES_WRITE_KEYS) |
| 342 | } |
| 343 | if err := rights.RequireApplication(ctx, st.Device.Ids.ApplicationIds, requiredRights...); err != nil { |
| 344 | return nil, err |
| 345 | } |
| 346 | |
| 347 | // Account for CLI not sending ids.* paths. |
| 348 | st.AddSetFields( |
| 349 | "ids.application_ids", |
| 350 | "ids.device_id", |
| 351 | ) |
| 352 | if st.Device.Ids.JoinEui != nil { |
| 353 | st.AddSetFields( |
| 354 | "ids.join_eui", |
| 355 | ) |
| 356 | } |
| 357 | if st.Device.Ids.DevEui != nil { |
| 358 | st.AddSetFields( |
| 359 | "ids.dev_eui", |
| 360 | ) |
| 361 | } |
| 362 | if st.Device.Ids.DevAddr != nil { |
| 363 | st.AddSetFields( |
| 364 | "ids.dev_addr", |
| 365 | ) |
| 366 | } |
| 367 | |
| 368 | if err := st.ValidateSetField( |
| 369 | func() bool { return st.Device.FrequencyPlanId != "" }, |
| 370 | "frequency_plan_id", |
| 371 | ); err != nil { |
| 372 | return nil, err |
| 373 | } |
| 374 | if err := st.ValidateSetFieldWithCause( |
| 375 | st.Device.LorawanPhyVersion.Validate, |
nothing calls this directly
no test coverage detected