Skip to content

Commit

Permalink
HGWGDC-32792: bootTime conversion from int64 to localTime (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
renujangra01051999 authored Nov 7, 2024
1 parent ace8475 commit d3cf2d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion datastruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type UpdateResourceRequest struct {
WanInterfaceUsed string `json:"wanInterfaceUsed,omitempty"`
LastReconnectReason string `json:"lastReconnectReason,omitempty"`
ManagementProtocol string `json:"managementProtocol,omitempty"`
LastBootTime int64 `json:"lastBootTime,omitempty"`
LastBootTime string `json:"lastBootTime,omitempty"`
FirmwareVersion string `json:"firmwareVersion,omitempty"`
}

Expand Down
5 changes: 3 additions & 2 deletions forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net/url"
"regexp"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -250,7 +251,7 @@ func populateWebPaConveyHeaderDataIfPresent(webPAConveyHeader string, updatedRes
updatedResourceRequestBody.WanInterfaceUsed = conveyHeaderData.WebpaInterfaceUsed
updatedResourceRequestBody.LastReconnectReason = conveyHeaderData.WebpaLastReconnectReason
updatedResourceRequestBody.ManagementProtocol = conveyHeaderData.WebpaProtocol
updatedResourceRequestBody.LastBootTime = conveyHeaderData.BootTime
updatedResourceRequestBody.LastBootTime = time.Unix(conveyHeaderData.BootTime, 0).Local().Format(time.RFC3339Nano)
updatedResourceRequestBody.FirmwareVersion = conveyHeaderData.FwName
}
return nil
Expand All @@ -275,7 +276,7 @@ func updateResourceDetails(req *http.Request, client *http.Client, resourceURL *
return err
}

log.Ctx(req.Context()).Info().Msgf("Certificate Provider type: [%s], Certificate expiry date: [%s], HW Last Reboot Reason: [%s], Webpa Interface Used: [%s], Webpa Last Reconnect Reason: [%s], Webpa Protocol: [%s], Last Boot Time: [%d], Firmware Version: [%s]",
log.Ctx(req.Context()).Info().Msgf("Certificate Provider type: [%s], Certificate expiry date: [%s], HW Last Reboot Reason: [%s], Webpa Interface Used: [%s], Webpa Last Reconnect Reason: [%s], Webpa Protocol: [%s], Last Boot Time: [%s], Firmware Version: [%s]",
requestBody.CertificateProviderType, requestBody.CertificateExpiryDate,
requestBody.LastRebootReason, requestBody.WanInterfaceUsed,
requestBody.LastReconnectReason, requestBody.ManagementProtocol,
Expand Down
8 changes: 4 additions & 4 deletions forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestUpdateResourceDetails(t *testing.T) {
certificateExpiryDate: "Sep 19 23:59:59 2031 GMT",
deviceCN: "TestCPE",
webpaConveyHeader: "eyJody1tb2RlbCI6IlwiRkdBMjIzM1wiIiwiaHctc2VyaWFsLW51bWJlciI6IjIyMzNBRENNTCIsImh3LW1hbnVmYWN0dXJlciI6IlwiVGVjaG5pY29sb3JcIiIsImZ3LW5hbWUiOiIwMDUuMDMzLjAwMSIsImJvb3QtdGltZSI6MTcyNTAwMDYwOCwid2VicGEtcHJvdG9jb2wiOiJQQVJPRFVTLTIuMC02MWIxYTdhIiwid2VicGEtaW50ZXJmYWNlLXVzZWQiOiJlcm91dGVyMCIsImh3LWxhc3QtcmVib290LXJlYXNvbiI6InVua25vd24iLCJ3ZWJwYS1sYXN0LXJlY29ubmVjdC1yZWFzb24iOiJTU0xfU29ja2V0X0Nsb3NlIn0=",
expectedUpdateResourceRequestBody: `{"ipAddress":"127.0.0.1","certificateProviderType":"DTSECURITY","certificateExpiryDate":"Sep 19 23:59:59 2031 GMT","lastRebootReason":"unknown","wanInterfaceUsed":"erouter0","lastReconnectReason":"SSL_Socket_Close","managementProtocol":"PARODUS-2.0-61b1a7a","lastBootTime":1.725000608e+09,"firmwareVersion":"005.033.001"}`,
expectedUpdateResourceRequestBody: `{"ipAddress":"127.0.0.1","certificateProviderType":"DTSECURITY","certificateExpiryDate":"Sep 19 23:59:59 2031 GMT","lastRebootReason":"unknown","wanInterfaceUsed":"erouter0","lastReconnectReason":"SSL_Socket_Close","managementProtocol":"PARODUS-2.0-61b1a7a","lastBootTime":"2024-08-30T12:20:08+05:30","firmwareVersion":"005.033.001"}`,
expectedStatus: http.StatusOK,
},
{
Expand All @@ -161,7 +161,7 @@ func TestUpdateResourceDetails(t *testing.T) {
certificateExpiryDate: "Dec 31 23:59:59 2025 GMT",
deviceCN: "TestCPE",
webpaConveyHeader: "eyJody1tb2RlbCI6IlwiQ2hhcmFjdGVyMS5NRSIsImh3LW1hbnVmYWN0dXJlciI6IlwiU3RhcHRvbXNcIiIsImJvb3QtdGltZSI6MTY2NzkwMDAwMCwid2VicGEtcHJvdG9jb2wiOiJQQVJPRFVTLTEuMC0xYjJhZDU3MCIsIndlYnBhLWFuZGVyeWRlLXNlY3RvciI6InRlc3RfcHJvdG90YWN0dXJlIiwiZ3VhZ2UtdHlwZSI6InVua25vd24ifQ==",
expectedUpdateResourceRequestBody: `{"ipAddress":"","certificateProviderType":"IRDETO","certificateExpiryDate":"Dec 31 23:59:59 2025 GMT","managementProtocol":"PARODUS-1.0-1b2ad570","lastBootTime":1.6679e+09}`,
expectedUpdateResourceRequestBody: `{"ipAddress":"","certificateProviderType":"IRDETO","certificateExpiryDate":"Dec 31 23:59:59 2025 GMT","managementProtocol":"PARODUS-1.0-1b2ad570","lastBootTime":"2022-11-08T15:03:20+05:30"}`,
expectedStatus: http.StatusOK,
},
{
Expand All @@ -171,7 +171,7 @@ func TestUpdateResourceDetails(t *testing.T) {
certificateExpiryDate: "Dec 31 23:59:59 2025 GMT",
deviceCN: "TestCPE",
webpaConveyHeader: "eyJody1tb2RlbCI6IlwiQ2hhcmFjdGVyMS5MRSIsImh3LW1hbnVmYWN0dXJlciI6IlwiVGVjaG5pY29sb3JcIiIsImZ3LW5hbWUiOiIwMDUuMDMzLjAwMSIsImJvb3QtdGltZSI6MTY2NzkwMDAwMCwid2VicGEtcHJvdG9jb2wiOiJQQVJPRFVTLTEuMC0xYjJhZDU3MCIsIndlYnBhLWFuZGVyeWRlLXNlY3RvciI6InRlc3RfcHJvdG90YWN0dXVyZSIsImh3LWxhc3QtcmVib290LXJlYXNvbiI6InVua25vd24ifQ==",
expectedUpdateResourceRequestBody: `{"ipAddress":"127.0.0.1","certificateProviderType":"DTSECURITY","certificateExpiryDate":"Dec 31 23:59:59 2025 GMT","lastRebootReason":"unknown","managementProtocol":"PARODUS-1.0-1b2ad570","lastBootTime":1.6679e+09,"firmwareVersion":"005.033.001"}`,
expectedUpdateResourceRequestBody: `{"ipAddress":"127.0.0.1","certificateProviderType":"DTSECURITY","certificateExpiryDate":"Dec 31 23:59:59 2025 GMT","lastRebootReason":"unknown","managementProtocol":"PARODUS-1.0-1b2ad570","lastBootTime":"2022-11-08T15:03:20+05:30","firmwareVersion":"005.033.001"}`,
expectedStatus: http.StatusOK,
},
{
Expand All @@ -181,7 +181,7 @@ func TestUpdateResourceDetails(t *testing.T) {
certificateExpiryDate: "",
deviceCN: "TestCPE",
webpaConveyHeader: "eyJody1tb2RlbCI6IlwiRkdBMjIzM1wiIiwiaHctc2VyaWFsLW51bWJlciI6IjIyMzNBRENNTCIsImh3LW1hbnVmYWN0dXJlciI6IlwiVGVjaG5pY29sb3JcIiIsImZ3LW5hbWUiOiIwMDUuMDMzLjAwMSIsImJvb3QtdGltZSI6MTcyNTAwMDYwOCwid2VicGEtcHJvdG9jb2wiOiJQQVJPRFVTLTIuMC02MWIxYTdhIiwid2VicGEtaW50ZXJmYWNlLXVzZWQiOiJlcm91dGVyMCIsImh3LWxhc3QtcmVib290LXJlYXNvbiI6InVua25vd24ifQ==",
expectedUpdateResourceRequestBody: `{"ipAddress":"127.0.0.1","certificateProviderType":"DTSECURITY","certificateExpiryDate":"","lastRebootReason":"unknown","wanInterfaceUsed":"erouter0","managementProtocol":"PARODUS-2.0-61b1a7a","lastBootTime":1.725000608e+09,"firmwareVersion":"005.033.001"}`,
expectedUpdateResourceRequestBody: `{"ipAddress":"127.0.0.1","certificateProviderType":"DTSECURITY","certificateExpiryDate":"","lastRebootReason":"unknown","wanInterfaceUsed":"erouter0","managementProtocol":"PARODUS-2.0-61b1a7a","lastBootTime":"2024-08-30T12:20:08+05:30","firmwareVersion":"005.033.001"}`,
expectedStatus: http.StatusOK,
},
{
Expand Down

0 comments on commit d3cf2d6

Please sign in to comment.