Skip to content

Commit

Permalink
el2g: Add status command
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Doan <[email protected]>
  • Loading branch information
doanac committed Sep 2, 2022
1 parent 8aa91d3 commit 2128240
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
50 changes: 50 additions & 0 deletions client/foundries_el2g.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ import (
"github.com/sirupsen/logrus"
)

type El2gOverview struct {
Subdomain string `json:"subdomain"`
ProductIds []int `json:"product-ids"`
}

func (a *Api) El2gOverview(factory string) (El2gOverview, error) {
url := a.serverUrl + "/ota/factories/" + factory + "/el2g/overview/"
body, err := a.Get(url)
if err != nil {
return El2gOverview{}, err
}
var overview El2gOverview
err = json.Unmarshal(*body, &overview)
return overview, err
}

type El2gCsr struct {
Id int `json:"id"`
Value string `json:"value"`
Expand Down Expand Up @@ -141,6 +157,27 @@ func (a *Api) El2gProductInfo(factory, deviceId string) (El2gProduct, error) {
return prod, nil
}

type El2gIntermediateCa struct {
Id json.Number `json:"id"`
Name string `json:"name"`
Algorithm string `json:"algorithm"`
Value string `json:"value"`
}

func (a *Api) El2gIntermediateCas(factory string) ([]El2gIntermediateCa, error) {
url := a.serverUrl + "/ota/factories/" + factory + "/el2g/intermediate-cas/"
body, err := a.Get(url)

var objs []El2gIntermediateCa
if err != nil {
return nil, err
}
if err = json.Unmarshal(*body, &objs); err != nil {
return nil, err
}
return objs, nil
}

type El2gSecureObject struct {
Id json.Number `json:"id"`
Type string `json:"type"`
Expand Down Expand Up @@ -184,3 +221,16 @@ func (a *Api) El2gSecureObjectProvisionings(factory, deviceId string) ([]El2gSec
}
return devices.Content, nil
}

func (a *Api) El2gProducts(factory string) ([]El2gProduct, error) {
url := a.serverUrl + "/ota/factories/" + factory + "/el2g-proxy/products"
body, err := a.Get(url)
if err != nil {
return nil, err
}
var products []El2gProduct
if err = json.Unmarshal(*body, &products); err != nil {
return nil, err
}
return products, nil
}
2 changes: 2 additions & 0 deletions subcommands/el2g/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func init() {
Args: cobra.ExactArgs(2),
Run: doAdd,
Example: `# Add a device with an SE050 (product ID: 935389312472)
# The product IDs configured for you factory can be found by running
# fioctl el2g status
# Device ID can be found on a device by running:
# $ ssscli se05x uid | grep "Unique ID:" | cut -d: -f2
# ssscli se05x uid | grep "Unique ID:" | cut -d: -f2
Expand Down
64 changes: 64 additions & 0 deletions subcommands/el2g/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package el2g

import (
"fmt"
"strconv"

"github.com/foundriesio/fioctl/subcommands"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func init() {
cmd.AddCommand(&cobra.Command{
Use: "status",
Short: "Show the overall status of the Edgelock 2Go integration",
Run: doStatus,
})
}

func doStatus(cmd *cobra.Command, args []string) {
factory := viper.GetString("factory")

products, err := api.El2gProducts(factory)
subcommands.DieNotNil(err)

overview, err := api.El2gOverview(factory)
subcommands.DieNotNil(err)
fmt.Println("# Subdomain:", overview.Subdomain)
fmt.Println("\n# Product IDs")
t := subcommands.Tabby(1, "ID", "NAME")
for _, id := range overview.ProductIds {
name := ""
for _, prod := range products {
if prod.Nc12 == strconv.Itoa(id) {
name = prod.Type
break
}
}
t.AddLine(id, name)
}
t.Print()

secureObjects, err := api.El2gSecureObjects(factory)
subcommands.DieNotNil(err)
fmt.Println("\n# Secure Objects")
t = subcommands.Tabby(1, "TYPE", "NAME", "OBJECT ID")
for _, so := range secureObjects {
t.AddLine(so.Type, so.Name, so.ObjectId)
}
t.Print()

fmt.Println("\n# Intermediate CAs")
cas, err := api.El2gIntermediateCas(factory)
subcommands.DieNotNil(err)
for i, ca := range cas {
if i > 0 {
fmt.Println()
}
fmt.Println("Name:", ca.Name)
fmt.Println("Algorithm:", ca.Algorithm)
fmt.Println("ID:", ca.Id)
fmt.Println(ca.Value)
}
}

0 comments on commit 2128240

Please sign in to comment.