Skip to content

Commit a61328d

Browse files
authored
feat(iot): add name generation on hub network and device (#526)
1 parent e5e3600 commit a61328d

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

api/iot/v1beta1/iot_sdk.go

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,6 @@ type DatabaseSettings struct {
625625
type Device struct {
626626
// ID: device ID, also used as MQTT Client ID or Username
627627
ID string `json:"id"`
628-
// OrganizationID: organization owning the resource
629-
OrganizationID string `json:"organization_id"`
630628
// Name: device name
631629
Name string `json:"name"`
632630
// Status: device status
@@ -635,18 +633,20 @@ type Device struct {
635633
Status DeviceStatus `json:"status"`
636634
// HubID: hub ID
637635
HubID string `json:"hub_id"`
638-
// CreatedAt: device add date
639-
CreatedAt *time.Time `json:"created_at"`
640-
// UpdatedAt: device last modification date
641-
UpdatedAt *time.Time `json:"updated_at"`
642-
// AllowInsecure: whether to allow device to connect without TLS mutual authentication
643-
AllowInsecure bool `json:"allow_insecure"`
644636
// LastActivityAt: device last connection/activity date
645637
LastActivityAt *time.Time `json:"last_activity_at"`
646638
// IsConnected: whether the device is connected to the Hub or not
647639
IsConnected bool `json:"is_connected"`
640+
// AllowInsecure: whether to allow device to connect without TLS mutual authentication
641+
AllowInsecure bool `json:"allow_insecure"`
648642
// MessageFilters: filter-sets to restrict the topics the device can publish/subscribe to
649643
MessageFilters *DeviceMessageFilters `json:"message_filters"`
644+
// CreatedAt: device add date
645+
CreatedAt *time.Time `json:"created_at"`
646+
// UpdatedAt: device last modification date
647+
UpdatedAt *time.Time `json:"updated_at"`
648+
// OrganizationID: organization owning the resource
649+
OrganizationID string `json:"organization_id"`
650650
}
651651

652652
// DeviceMessageFilters: device message filters
@@ -686,12 +686,8 @@ type FunctionsRoute struct {
686686

687687
// Hub: hub
688688
type Hub struct {
689-
// Region: region of the Hub
690-
Region scw.Region `json:"region"`
691689
// ID: hub ID
692690
ID string `json:"id"`
693-
// OrganizationID: organization owning the resource
694-
OrganizationID string `json:"organization_id"`
695691
// Name: hub name
696692
Name string `json:"name"`
697693
// Status: current status of the Hub
@@ -702,24 +698,28 @@ type Hub struct {
702698
//
703699
// Default value: plan_unknown
704700
ProductPlan ProductPlan `json:"product_plan"`
705-
// Endpoint: host to connect your devices to
706-
//
707-
// Devices should be connected to this host, port may be 1883 (MQTT), 8883 (MQTT over TLS), 80 (MQTT over Websocket) or 443 (MQTT over Websocket over TLS).
708-
Endpoint string `json:"endpoint"`
709-
// CreatedAt: hub creation date
710-
CreatedAt *time.Time `json:"created_at"`
711-
// UpdatedAt: hub last modification date
712-
UpdatedAt *time.Time `json:"updated_at"`
713701
// Enabled: whether the hub has been enabled
714702
Enabled bool `json:"enabled"`
715703
// DeviceCount: number of registered devices
716704
DeviceCount uint64 `json:"device_count"`
717705
// ConnectedDeviceCount: number of currently connected devices
718706
ConnectedDeviceCount uint64 `json:"connected_device_count"`
707+
// Endpoint: host to connect your devices to
708+
//
709+
// Devices should be connected to this host, port may be 1883 (MQTT), 8883 (MQTT over TLS), 80 (MQTT over Websocket) or 443 (MQTT over Websocket over TLS).
710+
Endpoint string `json:"endpoint"`
719711
// EventsEnabled: wether Hub events are enabled or not
720712
EventsEnabled bool `json:"events_enabled"`
721713
// EventsTopicPrefix: hub events topic prefix
722714
EventsTopicPrefix string `json:"events_topic_prefix"`
715+
// Region: region of the Hub
716+
Region scw.Region `json:"region"`
717+
// CreatedAt: hub creation date
718+
CreatedAt *time.Time `json:"created_at"`
719+
// UpdatedAt: hub last modification date
720+
UpdatedAt *time.Time `json:"updated_at"`
721+
// OrganizationID: organization owning the resource
722+
OrganizationID string `json:"organization_id"`
723723
}
724724

725725
// ListDevicesResponse: list devices response
@@ -778,20 +778,16 @@ type MetricsMetricValue struct {
778778

779779
// Network: network
780780
type Network struct {
781-
// Region: region of the Network
782-
Region scw.Region `json:"region"`
783781
// ID: network ID
784782
ID string `json:"id"`
785-
// OrganizationID: organization owning the resource
786-
OrganizationID string `json:"organization_id"`
787783
// Name: network name
788784
Name string `json:"name"`
789-
// Endpoint: endpoint to use for interacting with the network
790-
Endpoint string `json:"endpoint"`
791785
// Type: type of network to connect with
792786
//
793787
// Default value: unknown
794788
Type NetworkNetworkType `json:"type"`
789+
// Endpoint: endpoint to use for interacting with the network
790+
Endpoint string `json:"endpoint"`
795791
// HubID: hub ID to connect the Network to
796792
HubID string `json:"hub_id"`
797793
// CreatedAt: network creation date
@@ -800,6 +796,10 @@ type Network struct {
800796
//
801797
// This prefix will be prepended to all topics for this Network.
802798
TopicPrefix string `json:"topic_prefix"`
799+
// Region: region of the Network
800+
Region scw.Region `json:"region"`
801+
// OrganizationID: organization owning the resource
802+
OrganizationID string `json:"organization_id"`
803803
}
804804

805805
// RestRoute: rest route
@@ -989,7 +989,7 @@ type CreateHubRequest struct {
989989
OrganizationID string `json:"organization_id"`
990990
// ProductPlan: hub feature set
991991
//
992-
// Default value: plan_unknown
992+
// Default value: plan_shared
993993
ProductPlan ProductPlan `json:"product_plan"`
994994
// DisableEvents: disable Hub events (default false)
995995
DisableEvents *bool `json:"disable_events"`
@@ -1011,6 +1011,10 @@ func (s *API) CreateHub(req *CreateHubRequest, opts ...scw.RequestOption) (*Hub,
10111011
req.Region = defaultRegion
10121012
}
10131013

1014+
if req.Name == "" {
1015+
req.Name = namegenerator.GetRandomName("hub")
1016+
}
1017+
10141018
if fmt.Sprint(req.Region) == "" {
10151019
return nil, errors.New("field Region cannot be empty in request")
10161020
}
@@ -1400,6 +1404,10 @@ func (s *API) CreateDevice(req *CreateDeviceRequest, opts ...scw.RequestOption)
14001404
req.Region = defaultRegion
14011405
}
14021406

1407+
if req.Name == "" {
1408+
req.Name = namegenerator.GetRandomName("device")
1409+
}
1410+
14031411
if fmt.Sprint(req.Region) == "" {
14041412
return nil, errors.New("field Region cannot be empty in request")
14051413
}
@@ -2374,6 +2382,10 @@ func (s *API) CreateNetwork(req *CreateNetworkRequest, opts ...scw.RequestOption
23742382
req.Region = defaultRegion
23752383
}
23762384

2385+
if req.Name == "" {
2386+
req.Name = namegenerator.GetRandomName("network")
2387+
}
2388+
23772389
if fmt.Sprint(req.Region) == "" {
23782390
return nil, errors.New("field Region cannot be empty in request")
23792391
}

0 commit comments

Comments
 (0)