mirror of
https://github.com/hanzozt/zt.git
synced 2026-10-30 15:04:55 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
39 lines
750 B
Go
39 lines
750 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/Jeffail/gabs"
|
|
"github.com/hanzozt/fablab/kernel/model"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func GetEntityId(m *model.Model, entityType string, name string) (string, error) {
|
|
output, err := Exec(m, "edge", "list", entityType, "--output-json",
|
|
fmt.Sprintf(`name="%v" limit none`, name))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
l, err := gabs.ParseJSON([]byte(output))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
data := l.Path("data")
|
|
if data == nil {
|
|
return "", nil
|
|
}
|
|
|
|
entities, err := data.Children()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
for _, entity := range entities {
|
|
return entity.S("id").Data().(string), nil
|
|
}
|
|
|
|
return "", errors.Errorf("no entity of type %v found with name %v", entityType, name)
|
|
}
|