Beispiel #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)
	})
}
Beispiel #2
0
func cmdAdd(cmd *cobra.Command, args []string) {
	cmdAddBody.ContainerNetwork = make(map[string]map[string][]string)
	cmdAddBody.Links = make(map[string]string)
	cmdAddBody.ContainerPorts = make(map[string][]PortConfig)

	if len(args) > 2 || len(args) < 1 {
		fmt.Fprintln(os.Stderr, cmdAddUsage)
		os.Exit(1)
	}

	// Split namespace and repository
	host, app, repo, tag, err := internal.ParseResourceName(args[0])
	internal.Check(err)
	cmdAddBody.Application = app
	cmdAddBody.Repository = repo
	cmdAddBody.RepositoryTag = tag

	if !internal.CheckHostConsistent(host) {
		fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
		os.Exit(1)
	}

	// Service name
	if len(args) > 1 {
		cmdAddBody.Service = args[1]
	} else {
		cmdAddBody.Service = cmdAddBody.Repository
	}

	// Sanity checks
	err = internal.CheckName(cmdAddBody.Application)
	internal.Check(err)
	err = internal.CheckName(cmdAddBody.Repository)
	internal.Check(err)
	err = internal.CheckName(cmdAddBody.Service)
	internal.Check(err)

	serviceAdd(cmdAddBody)
}
Beispiel #3
0
func serviceList(apps []string) {
	w := tabwriter.NewWriter(os.Stdout, 27, 1, 2, ' ', 0)
	titles := []string{"NAME", "REPOSITORY", "IMAGE ID", "STATE", "CONTAINERS", "CREATED", "NETWORK"}
	fmt.Fprintln(w, strings.Join(titles, "\t"))

	services := []string{}
	var service map[string]interface{}
	for _, app := range apps {
		// Sanity checks
		err := internal.CheckName(app)
		internal.Check(err)

		b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/services", app), nil)
		internal.Check(json.Unmarshal(b, &services))
		for _, serviceID := range services {
			b := internal.ReqWant("GET", http.StatusOK, fmt.Sprintf("/applications/%s/services/%s", app, serviceID), nil)
			internal.Check(json.Unmarshal(b, &service))

			ips := []string{}
			for _, container := range service["containers"].(map[string]interface{}) {
				for name, network := range container.(map[string]interface{})["network"].(map[string]interface{}) {
					ips = append(ips, fmt.Sprintf("%s:%s", name, network.(map[string]interface{})["ip"]))
				}
			}

			fmt.Fprintf(w, "%s/%s\t%s@%s\t%s\t%s\t%d\t%s\t%s\n",
				app, service["name"],
				service["repository"],
				service["repository_tag"],
				service["image"].(string)[:12],
				strings.ToUpper(service["state"].(string)),
				int(service["container_number"].(float64)),
				service["creation_date"].(string)[:19],
				strings.Join(ips, ","))

			w.Flush()
		}
	}
}
Beispiel #4
0
	sail application webhook list
	sail application webhook list my-app
	`,
	Run: func(cmd *cobra.Command, args []string) {
		var applicationName string
		switch len(args) {
		case 0:
			applicationName = internal.GetUserName()
		case 1:
			applicationName = args[0]
		default:
			fmt.Fprintln(os.Stderr, "Invalid usage. Please see sail application webhook list --help")
			return
		}
		// Sanity
		err := internal.CheckName(applicationName)
		internal.Check(err)

		internal.FormatOutputDef(internal.GetWantJSON(fmt.Sprintf("/applications/%s/hook", applicationName)))
	},
}

var cmdApplicationWebhookAdd = &cobra.Command{
	Use:   "add",
	Short: "Add a webhook to an application ; sail application webhook add [<applicationName>] <WebhookURL>",
	Long: `Add a webhook to an application ; sail application webhook add [<applicationName>] <WebhookURL>
example:
	sail application webhook add http://www.endpoint.com/hook
	sail application webhook add my-app http://www.endpoint.com/hook
Endpoint url must accept POST with json body.
		`,
Beispiel #5
0
	Use:     "domain",
	Short:   "Application Domain commands: sail application domain --help",
	Long:    `Application Domain commands: sail application domain <command>`,
	Aliases: []string{"domains"},
}

var cmdApplicationDomainList = &cobra.Command{
	Use:     "list",
	Short:   "List domains and routes on the HTTP load balancer: sail application domain list [applicationName]",
	Aliases: []string{"ls", "ps"},
	Run: func(cmd *cobra.Command, args []string) {
		app := ""

		if len(args) == 1 && args[0] != "" {
			// Sanity
			err := internal.CheckName(args[0])
			internal.Check(err)

			app = args[0]
		} else if len(args) > 1 {
			fmt.Fprintln(os.Stderr, "Invalid usage. Please see sail application domain list --help")
			return
		}

		domainList(app)
	},
}

var cmdApplicationDomainDetach = &cobra.Command{
	Use:     "detach",
	Short:   "Detach a domain from the HTTP load balancer: sail application domain detach <applicationName> <domainName>",