inventory

package
v0.0.0-...-1e858a6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Inventory ansibleInventory = make(ansibleInventory, 10)

Functions

func GetExampleAnsibleInventory

func GetExampleAnsibleInventory() ([]byte, ansibleInventory)

func GetJumpserverInventory

func GetJumpserverInventory(jms_url string, auth *SigAuth) *ansibleInventory

func GetUserInfo

func GetUserInfo(jms_url string, auth *SigAuth)

Types

type Assets

type Assets struct {
	Id        string   `json:"id"`
	Hostname  string   `json:"hostname"`
	Ip        string   `json:"ip"`
	Protocols []string `json:"protocols"`
	Os        string   `json:"os"`
	Domain    string   `json:"domain"`
	Platform  string   `json:"platform"`
	Comment   string   `json:"comment"`
	Org_id    string   `json:"org_id"`
	Is_active bool     `json:"is_active"`
	Org_name  string   `json:"org_name"`
}

func GetAssetsNodeAssets

func GetAssetsNodeAssets(jms_url string, auth *SigAuth, uuid string) []Assets
func GetAssetsNodePID(jms_url string, auth *SigAuth, nodename string) string {
	var pid string
	node := GetAssetsNode(jms_url, auth, nodename)
	url := jms_url + "/api/v1/perms/users/nodes/tree/"
	gmt_fmt := "Mon, 02 Jan 2006 15:04:05 GMT"
	client := &http.Client{}
	req, err := http.NewRequest("GET", url, nil)
	req.Header.Add("Date", time.Now().Format(gmt_fmt))
	req.Header.Add("Accept", "application/json")
	// req.Header.Add("X-JMS-ORG", "00000000-0000-0000-0000-000000000002")
	if err != nil {
		log.Fatal(err)
	}
	if err := auth.Sign(req); err != nil {
		log.Fatal(err)
	}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	var nodetree []NodeTree
	err = json.Unmarshal(body, &nodetree)
	if err != nil {
		log.Fatalln("error:", err)
	}
	// fmt.Println(nodetree)
	for _, c := range nodetree {
		if c.Id == node.Key {
			pid = c.Id
		}
	}
	return pid
}

type Hostvars

type Hostvars map[string]map[string]string

type NodeTree

type NodeTree struct {
	Id   string `json:"id"`
	Name string `json:"name"`
	Pid  string `json:"pid"`
}

type Nodes

type Nodes struct {
	Id            string `json:"id"`
	Name          string `json:"name"`
	Key           string `json:"key"`
	Value         string `json:"value"`
	Org_id        string `json:"org_id"`
	Assets_amount int    `json:"assets_amount"`
}

func GetAssetsNode

func GetAssetsNode(jms_url string, auth *SigAuth) []Nodes

type SigAuth

type SigAuth struct {
	KeyID    string
	SecretID string
}

func (*SigAuth) Sign

func (auth *SigAuth) Sign(r *http.Request) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL