Exemplo n.º 1
0
// CertsList lists certs registered with the controller.
func CertsList(results int) error {
	c, err := client.New()

	if err != nil {
		return err
	}

	if results == defaultLimit {
		results = c.ResponseLimit
	}

	certList, _, err := certs.List(c, results)

	if err != nil {
		return err
	}

	if len(certList) == 0 {
		fmt.Println("No certs")
		return nil
	}

	certMap := make(map[string]string)
	nameMax := 0
	expiresMax := 0
	for _, cert := range certList {
		certMap[cert.Name] = cert.Expires

		if len(cert.Name) > nameMax {
			nameMax = len(cert.Name)
		}
		if len(cert.Expires) > nameMax {
			expiresMax = len(cert.Expires)
		}
	}

	nameHeader := "Common Name"
	expiresHeader := "Expires"
	tabSpaces := 5
	bufferSpaces := tabSpaces

	if nameMax < len(nameHeader) {
		tabSpaces += len(nameHeader) - nameMax
		nameMax = len(nameHeader)
	} else {
		bufferSpaces += nameMax - len(nameHeader)
	}

	if expiresMax < len(expiresHeader) {
		expiresMax = len(expiresHeader)
	}

	fmt.Printf("%s%s%s\n", nameHeader, strings.Repeat(" ", bufferSpaces), expiresHeader)
	fmt.Printf("%s%s%s\n", strings.Repeat("-", nameMax), strings.Repeat(" ", 5),
		strings.Repeat("-", expiresMax))
	fmt.Print(prettyprint.PrettyTabs(certMap, tabSpaces))
	return nil
}
Exemplo n.º 2
0
// LimitsList lists an app's limits.
func LimitsList(appID string) error {
	c, appID, err := load(appID)

	if err != nil {
		return err
	}

	config, err := config.List(c, appID)

	fmt.Printf("=== %s Limits\n\n", appID)

	fmt.Println("--- Memory")
	if len(config.Memory) == 0 {
		fmt.Println("Unlimited")
	} else {
		memoryMap := make(map[string]string)

		for key, value := range config.Memory {
			memoryMap[key] = fmt.Sprintf("%v", value)
		}

		fmt.Print(prettyprint.PrettyTabs(memoryMap, 5))
	}

	fmt.Println("\n--- CPU")
	if len(config.CPU) == 0 {
		fmt.Println("Unlimited")
	} else {
		cpuMap := make(map[string]string)

		for key, value := range config.CPU {
			cpuMap[key] = strconv.Itoa(int(value.(float64)))
		}

		fmt.Print(prettyprint.PrettyTabs(cpuMap, 5))
	}

	return nil
}
Exemplo n.º 3
0
// TagsList lists an app's tags.
func TagsList(appID string) error {
	c, appID, err := load(appID)

	if err != nil {
		return err
	}

	config, err := config.List(c, appID)

	fmt.Printf("=== %s Tags\n", appID)

	tagMap := make(map[string]string)

	for key, value := range config.Tags {
		tagMap[key] = fmt.Sprintf("%v", value)
	}

	fmt.Print(prettyprint.PrettyTabs(tagMap, 5))

	return nil
}
Exemplo n.º 4
0
// ConfigList lists an app's config.
func ConfigList(appID string, oneLine bool) error {
	c, appID, err := load(appID)

	if err != nil {
		return err
	}

	config, err := config.List(c, appID)

	if err != nil {
		return err
	}

	var keys []string
	for k := range config.Values {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	if oneLine {
		for _, key := range keys {
			fmt.Printf("%s=%s ", key, config.Values[key])
		}
		fmt.Println()
	} else {
		fmt.Printf("=== %s Config\n", appID)

		configMap := make(map[string]string)

		// config.Values is type interface, so it needs to be converted to a string
		for _, key := range keys {
			configMap[key] = fmt.Sprintf("%v", config.Values[key])
		}

		fmt.Print(prettyprint.PrettyTabs(configMap, 6))
	}

	return nil
}