Exemple #1
0
func serviceDomainDetach(serviceID, domain string, args domainStruct) {
	// Split namespace and service
	host, app, service, tag, err := internal.ParseResourceName(serviceID)
	internal.Check(err)

	if !internal.CheckHostConsistent(host) {
		fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
		os.Exit(1)
	} else if len(tag) > 0 {
		fmt.Fprintf(os.Stderr, "Error: Invalid service name. Please see sail service domain detach --help\n")
		os.Exit(1)
	}

	body, err := json.Marshal(args)
	internal.Check(err)

	// Sanity checks
	err = internal.CheckName(domain)
	internal.Check(err)

	path := fmt.Sprintf("/applications/%s/services/%s/attached-routes/%s", app, service, domain)
	data := internal.DeleteBodyWantJSON(path, body)

	internal.FormatOutput(data, func(data []byte) {
		fmt.Fprintf(os.Stderr, "Detached route %s %s%s from service %s/%s\n", args.Method, domain, args.Pattern, app, service)
	})
}
Exemple #2
0
func serviceDelete(namespace string, name string) {
	path := fmt.Sprintf("/applications/%s/services/%s?force=%t", namespace, name, deleteForce)
	data := internal.ReqWant("DELETE", http.StatusOK, path, nil)

	internal.FormatOutput(data, func(data []byte) {
		fmt.Fprintf(os.Stderr, "Deleted service %s/%s\n", namespace, name)
	})
}
Exemple #3
0
func containerLogs(args Logs) {
	queryArgs, err := query.Values(args)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Fatal: %s\n", err)
		return
	}
	path := fmt.Sprintf("/applications/%s/containers/%s/logs?%s", args.Application, args.Container, queryArgs.Encode())

	b := internal.GetWantJSON(path)
	internal.FormatOutput(b, containerLogsFormatter)
}
Exemple #4
0
func repositoryRemove(repositoryID string) {
	// Split namespace and repository
	host, app, repo, tag, err := internal.ParseResourceName(repositoryID)
	internal.Check(err)

	if !internal.CheckHostConsistent(host) {
		fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
		os.Exit(1)
	} else if len(tag) > 0 {
		fmt.Fprintf(os.Stderr, "Error: Invalid repository name. Please see sail repository delete --help\n")
		os.Exit(1)
	}

	path := fmt.Sprintf("/repositories/%s/%s", app, repo)
	data := internal.DeleteWantJSON(path)

	internal.FormatOutput(data, func(data []byte) {
		fmt.Fprintf(os.Stderr, "Deleted repository %s/%s\n", app, repo)
	})
}
Exemple #5
0
package version

import (
	"fmt"
	"os"

	"github.com/spf13/cobra"

	"github.com/runabove/sail/internal"
)

var versionNewLine bool

// Cmd version
var Cmd = &cobra.Command{
	Use:     "version",
	Short:   "Display Version of sail: sail version",
	Long:    `sail version`,
	Aliases: []string{"v"},
	Run: func(cmd *cobra.Command, args []string) {
		version := fmt.Sprintf("\"%s\"", internal.VERSION)
		internal.FormatOutput([]byte(version), prettyFormater)
	},
}

func prettyFormater(data []byte) {
	fmt.Fprintf(os.Stderr, "Version sail: %s\n", internal.VERSION)
	internal.ReadConfig()
}
Exemple #6
0
func domainListService(namespace, service string) {
	b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/services/%s/attached-routes", namespace, service), nil)
	internal.FormatOutput(b, domainListFormatter)
}
Exemple #7
0
func domainListApplication(app string) {
	b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/attached-domains", app), nil)
	internal.FormatOutput(b, domainListFormatter)
}
Exemple #8
0
	Aliases: []string{"add"},
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 2 {
			fmt.Fprintln(os.Stderr, "Invalid usage. Please see sail application domain attach --help")
		} else {
			// Sanity
			err := internal.CheckName(args[0])
			internal.Check(err)
			err = internal.CheckName(args[1])
			internal.Check(err)

			path := fmt.Sprintf("/applications/%s/attached-domains/%s", args[0], args[1])
			data := internal.DeleteWantJSON(path)

			internal.FormatOutput(data, func(data []byte) {
				fmt.Fprintf(os.Stderr, "Detached domain %s from application %s\n", args[1], args[0])
			})
		}
	},
}

func domainList(app string) {
	var apps []string

	// TODO: rewrite whithout the n+1... (needs API)
	if len(app) > 0 {
		apps = append(apps, app)
	} else {
		apps = internal.GetListApplications(nil)
	}