Exemplo n.º 1
0
func (ui *tatui) postHookRunActionOnMessage(action string, msg tat.Message) {
	hook := strings.TrimSpace(viper.GetString("post-hook-run-action"))
	if hook == "" {
		return
	}

	_, err := exec.LookPath(hook)
	if err != nil {
		internal.Exit("Invalid hook path for post-hook-run-action, err: %s", err.Error())
		return
	}

	jsonStr, err := json.Marshal(msg)
	if err != nil {
		internal.Exit("Error while marshalling msg for post-hook-run-action, err: %s", err.Error())
		return
	}

	cmd := exec.Command(hook, action, msg.ID, string(jsonStr))
	if e := cmd.Start(); e != nil {
		internal.Exit("Error with post-hook-run-action, err: %s", err.Error())
		return
	}

	ui.msg.Text = "Waiting " + hook + "for command to finish..."
	err = cmd.Wait()
	ui.msg.Text = fmt.Sprintf("Command finished: %v", err)
}
Exemplo n.º 2
0
Arquivo: update.go Projeto: ovh/tatcli
func doUpdate(baseurl, architecture string) {
	if architecture == "" {
		text := "You seem to have a custom build of tatcli.\n"
		text += "Please download latest release on %s\n"
		internal.Exit(text, urlGitubReleases)
	}

	url := getURLArtifactFromGithub(architecture)
	if internal.Debug {
		fmt.Printf("Url to update tatcli: %s\n", url)
	}

	resp, err := http.Get(url)
	if err != nil {
		internal.Exit("Error when downloading tatcli from url: %s, err:%s\n", url, err.Error())
	}

	if contentType := getContentType(resp); contentType != "application/octet-stream" {
		fmt.Printf("Url: %s\n", url)
		internal.Exit("Invalid Binary (Content-Type: %s). Please try again or download it manually from %s\n", contentType, urlGitubReleases)
	}

	if resp.StatusCode != 200 {
		internal.Exit("Error http code: %d, url called: %s\n", resp.StatusCode, url)
	}

	fmt.Printf("Getting latest release from : %s ...\n", url)
	defer resp.Body.Close()
	if err = update.Apply(resp.Body, update.Options{}); err != nil {
		internal.Exit("Error when updating tatcli from url: %s err:%s\n", url, err.Error())
	}
	fmt.Println("Update done.")
}
Exemplo n.º 3
0
Arquivo: ui.go Projeto: ovh/tatcli
// loadArgs load args form command line and return topic, filter, command
func (ui *tatui) loadArgs(args []string) []string {
	// example :
	// /YourTopic/SubTopic /split label:open label:doing label:done /save
	// /YourTopic/SubTopic /run CD
	// /YourTopic/SubTopic /run CD /save
	// /YourTopic/SubTopic /monitoring /save
	if len(args) < 1 {
		return []string{}
	}

	topicName := ""
	if strings.HasPrefix(args[0], "/") {
		topicName = args[0]
	}
	c := &tat.TopicCriteria{Topic: strings.TrimSpace(topicName)}

	//topicsB, err := internal.Request("GET", 200, topic.TopicsListURL(c), nil)
	topicsJSON, err := internal.Client().TopicList(c)
	if err != nil {
		internal.Exit("Error while loading topic %s error:%s", args[0], err.Error())
	}

	if len(topicsJSON.Topics) != 1 {
		internal.Exit("Args on tatcli ui should begin with topic name. Please check it on %s", args[0])
	}

	ui.currentTopic = topicsJSON.Topics[0]

	commands := []string{}
	cmd := ""
	for i := 1; i < len(args); i++ {
		if strings.HasPrefix(args[i], "/") {
			if cmd != "" {
				commands = append(commands, cmd)
			}
			cmd = args[i]
		} else {
			cmd += " " + args[i]
		}
	}
	if cmd != "" {
		commands = append(commands, cmd)
	}
	return commands
}
Exemplo n.º 4
0
Arquivo: update.go Projeto: ovh/tatcli
func getURLArtifactFromGithub(architecture string) string {
	client := github.NewClient(nil)
	release, resp, err := client.Repositories.GetLatestRelease("ovh", "tatcli")
	if err != nil {
		internal.Exit("Repositories.GetLatestRelease returned error: %v\n%v", err, resp.Body)
	}

	if len(release.Assets) > 0 {
		for _, asset := range release.Assets {
			if *asset.Name == "tatcli-"+architecture {
				return *asset.BrowserDownloadURL
			}
		}
	}

	text := "Invalid Artifacts on latest release. Please try again in few minutes.\n"
	text += "If the problem persists, please open an issue on https://github.com/ovh/tatcli/issues\n"
	internal.Exit(text)
	return ""
}
Exemplo n.º 5
0
Arquivo: config.go Projeto: ovh/tatcli
func (ui *tatui) loadConfig() {
	internal.ReadConfig()
	filters := viper.GetStringSlice("filters")

	// no range to keep order
	for index := 0; index < len(filters); index++ {
		filter := filters[index]
		tuples := strings.Split(filter, " ")
		if len(tuples) <= 2 {
			continue
		}
		topic := tuples[1]
		if _, ok := ui.currentFilterMessages[topic]; !ok {
			ui.currentFilterMessages[topic] = make(map[int]*tat.MessageCriteria)
			ui.currentFilterMessagesText[topic] = make(map[int]string)
		}
		c, criteriaText := ui.prepareFilterMessages(strings.Join(tuples[2:], " "), tuples[0], topic)
		ui.currentFilterMessages[topic][len(ui.currentFilterMessages[topic])] = c
		ui.currentFilterMessagesText[topic][len(ui.currentFilterMessagesText[topic])] = criteriaText
	}

	commands := viper.GetStringSlice("commands")
	// no range to keep order
	for index := 0; index < len(commands); index++ {
		commandsOnTopic := commands[index]
		tuples := strings.Split(strings.TrimSpace(commandsOnTopic), " ")
		if len(tuples) <= 1 {
			continue
		}
		topic := tuples[0]
		ui.uiTopicCommands[topic] = commandsOnTopic[len(topic):]
	}

	var conf config.TemplateJSONType
	err := viper.Unmarshal(&conf)
	if err != nil {
		internal.Exit("unable to decode confif file, err: %v", err)
	}

	ui.hooks = conf.Hooks
}
Exemplo n.º 6
0
package stats

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdStatsDBCollections = &cobra.Command{
	Use:   "dbCollections",
	Short: "DB Stats on each collection: tatcli stats dbCollections",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 1 {
			internal.Exit("Invalid argument: tatcli stats dbCollections --help\n")
			cmd.Usage()
		} else {
			out, err := internal.Client().StatsDBCollections()
			internal.Check(err)
			internal.Print(out)
		}
	},
}
Exemplo n.º 7
0
package topic

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

func init() {
	cmdTopicDeleteParameter.Flags().BoolVarP(&recursive, "recursive", "r", false, "Remove Parameter recursively")
}

var cmdTopicDeleteParameter = &cobra.Command{
	Use:   "deleteParameter",
	Short: "Remove Parameter to a topic: tatcli topic deleteParameter [--recursive] <topic> <key> [<key2>]... ",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			err := internal.Client().TopicDeleteParameters(args[0], args[1:], recursive)
			internal.Check(err)
		} else {
			internal.Exit("Invalid argument: tatcli topic deleteParameter --help\n")
		}
	},
}
Exemplo n.º 8
0
package user

import (
	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdUserSetAdmin = &cobra.Command{
	Use:   "setAdmin",
	Short: "Grant user to Tat admin (admin only): tatcli user setAdmin <username>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().UserSetAdmin(tat.UsernameUserJSON{
				Username: args[0],
			})
			internal.Check(err)
			internal.Print(out)
		} else {
			internal.Exit("Invalid argument: tatcli user setAdmin --help\n")
		}
	},
}
Exemplo n.º 9
0
package message

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdMessageVoteDown = &cobra.Command{
	Use:   "votedown",
	Short: "Vote Down a message: tatcli message votedown <topic> <idMessage>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().MessageVoteDown(args[0], args[1])
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument to votedown a message: tatcli message votedown --help\n")
		}
	},
}
Exemplo n.º 10
0
package user

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdUserDisableNotificationsTopic = &cobra.Command{
	Use:   "disableNotificationsTopic",
	Short: "Disable notifications on a topic: tatcli user disableNotificationsTopic <topicName>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().UserDisableNotificationsTopic(args[0])
			internal.Check(err)
			internal.Print(out)
		} else {
			internal.Exit("Invalid argument: tatcli user disableNotificationsTopic --help\n")
		}
	},
}
Exemplo n.º 11
0
var versionNewLine bool

func init() {
	Cmd.Flags().BoolVarP(&versionNewLine, "versionNewLine", "", true, "New line after version number. If true, display Version Engine too")
}

// Cmd version
var Cmd = &cobra.Command{
	Use:     "version",
	Short:   "Display Version of tatcli and tat engine if configured: tatcli version",
	Long:    `tatcli version`,
	Aliases: []string{"v"},
	Run: func(cmd *cobra.Command, args []string) {
		if versionNewLine {
			fmt.Printf("Version tatcli: %s\n", internal.VERSION)

			internal.ReadConfig()
			if viper.GetString("url") == "" {
				internal.Exit("Version Engine: No Engine Configured. See tatcli config --help\n")
			} else {
				out, err := internal.Client().Version()
				internal.Check(err)
				internal.Print(out)
			}
		} else {
			fmt.Print(internal.VERSION)
		}
	},
}
Exemplo n.º 12
0
package group

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdGroupDeleteUser = &cobra.Command{
	Use:   "deleteUser",
	Short: "Delete Users from a group: tacli group deleteUser <groupname> <username1> [<username2> ... ]",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			err := internal.Client().GroupDeleteUsers(args[0], args[1:])
			internal.Check(err)
		} else {
			internal.Exit("Invalid argument: tatcli group deleteUser --help\n")
		}
	},
}
Exemplo n.º 13
0
Arquivo: like.go Projeto: ovh/tatcli
package message

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdMessageLike = &cobra.Command{
	Use:   "like",
	Short: "Like a message: tatcli message like <topic> <idMessage>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 2 {
			out, err := internal.Client().MessageLike(args[0], args[1])
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument to like a message: tatcli message like --help\n")
		}
	},
}
Exemplo n.º 14
0
package topic

import (
	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdTopicTruncateLabels = &cobra.Command{
	Use:   "truncatelabels",
	Short: "Truncate Labels on this topic, only for tat admin and administrators on topic : tatcli topic truncatelabels <topic>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().TopicTruncateLabels(tat.TopicNameJSON{Topic: args[0]})
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument: tatcli topic truncatelabels --help\n")
		}
	},
}
Exemplo n.º 15
0
Arquivo: move.go Projeto: ovh/tatcli
package message

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdMessageMove = &cobra.Command{
	Use:   "move",
	Short: "Move a message: tatcli message move <oldTopic> <idMessage> <newTopic>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 3 {
			out, err := internal.Client().MessageMove(args[0], args[1], args[2])
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument to move a message: tatcli message move --help\n")
		}
	},
}
Exemplo n.º 16
0
Arquivo: create.go Projeto: ovh/tatcli
package topic

import (
	"strings"

	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdTopicCreate = &cobra.Command{
	Use:   "create",
	Short: "Create a new topic: tatcli create <topic> <description of topic>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			description := strings.Join(args[1:], " ")
			topic, err := internal.Client().TopicCreate(tat.TopicCreateJSON{
				Topic:       args[0],
				Description: description,
			})
			internal.Check(err)
			if internal.Verbose {
				internal.Print(topic)
			}
		} else {
			internal.Exit("Invalid argument: tatcli topic create --help\n")
		}
	},
}
Exemplo n.º 17
0
Arquivo: add.go Projeto: ovh/tatcli
package user

import (
	"strings"

	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdUserAdd = &cobra.Command{
	Use:   "add",
	Short: "Add a user: tatcli user add <username> <email> <fullname>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 3 {
			out, err := internal.Client().UserAdd(tat.UserCreateJSON{
				Username: args[0],
				Fullname: strings.Join(args[2:], " "),
				Email:    args[1],
				Callback: "tatcli --url=:scheme://:host::port:path user verify --save :username :token",
			})
			internal.Check(err)
			internal.Print(out)
		} else {
			internal.Exit("Invalid argument to add user: tatcli user add --help\n")
		}
	},
}
Exemplo n.º 18
0
Arquivo: delete.go Projeto: ovh/tatcli
package presence

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdPresenceDelete = &cobra.Command{
	Use:   "delete",
	Short: "Delete a user's presence on one topic: tatcli presence delete <topic> <username>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 2 {
			err := internal.Client().PresenceDelete(args[0], args[1])
			internal.Check(err)
		} else {
			internal.Exit("Invalid argument: tatcli presence delete --help\n")
		}
	},
}
Exemplo n.º 19
0
Arquivo: events.go Projeto: ovh/tatcli
func (ui *tatui) initHandles() {
	// Setup handlers
	termui.Handle("/timer/1s", func(e termui.Event) {
		t := e.Data.(termui.EvtTimer)
		ui.draw(int(t.Count))
	})

	termui.Handle("/sys/kbd/C-q", func(termui.Event) {
		termui.StopLoop()
	})

	// Show Home -> C-h, but send <backspace> event
	termui.Handle("/sys/kbd/<backspace>", func(e termui.Event) {
		ui.showHome()
	})

	// C-c is same as /clear
	termui.Handle("/sys/kbd/C-c", func(e termui.Event) {
		ui.clearUI()
	})

	// All topics
	termui.Handle("/sys/kbd/C-b", func(e termui.Event) {
		if ui.current == uiMessage {
			ui.showMessages()
		}
	})

	// All topics
	termui.Handle("/sys/kbd/C-a", func(e termui.Event) {
		ui.current = uiTopics
		ui.onlyFavorites = "false"
		ui.onlyUnread = false
		ui.showTopics()
	})

	// Unread Topics
	termui.Handle("/sys/kbd/C-r", func(e termui.Event) {
		ui.showUnreadTopics()
	})

	// toggle usernames
	termui.Handle("/sys/kbd/C-u", func(e termui.Event) {
		ui.toggleUsernames(false)
	})

	// Favorites Topics
	termui.Handle("/sys/kbd/C-f", func(e termui.Event) {
		ui.showFavoritesTopics()
	})

	termui.Handle("/sys/kbd/<up>", func(e termui.Event) {
		ui.move("up")
	})

	termui.Handle("/sys/kbd/<down>", func(e termui.Event) {
		ui.move("down")
	})

	termui.Handle("/sys/kbd/<enter>", func(e termui.Event) {
		switch ui.selectedPane {
		case uiTopics:
			ui.enterTopic()
			return
		case uiMessages:
			ui.enterMessage()
			return
		case uiActionBox:
			ui.processMsg()
			ui.render()
		}
	})

	termui.Handle("/sys/kbd/<space>", func(e termui.Event) {
		if ui.isOnActionBox() {
			ui.send.Text += " "
		}
		ui.render()
	})

	termui.Handle("/sys/kbd/<tab>", func(e termui.Event) {
		if ui.isOnActionBox() && len(ui.send.Text) > 0 && !strings.HasSuffix(ui.send.Text, " ") {
			ui.autocomplete()
		} else {
			ui.switchBox()
		}
	})

	termui.Handle("/sys/kbd/C-8", func(e termui.Event) {
		if !ui.isOnActionBox() {
			return
		}
		if len(ui.send.Text) > 0 {
			ui.send.Text = ui.send.Text[:len(ui.send.Text)-1]
			ui.render()
		}
	})

	termui.Handle("/sys/kbd/C-k", func(e termui.Event) {
		if ui.currentModeOnTopic[ui.currentTopic.Topic] == "/run" {
			ui.runActionOnMessage(true)
		} else if ui.currentModeOnTopic[ui.currentTopic.Topic] == "/monitoring" {
			ui.monitoringActionOnMessage()
		}
	})

	termui.Handle("/sys/kbd/C-j", func(e termui.Event) {
		if ui.currentModeOnTopic[ui.currentTopic.Topic] == "/run" {
			ui.runActionOnMessage(false)
		} else if ui.currentModeOnTopic[ui.currentTopic.Topic] == "/monitoring" {
			ui.monitoringActionOnMessage()
		}
	})

	termui.Handle("/sys/kbd/C-p", func(e termui.Event) {
		if _, ok := ui.uilists[uiMessages][ui.selectedPaneMessages]; ok {
			ui.openLinksInBrowser()
		}
	})

	termui.Handle("/sys/kbd/C-t", func(e termui.Event) {
		ui.toggleTopMenu(false)
	})

	termui.Handle("/sys/kbd/C-y", func(e termui.Event) {
		ui.toggleActionBox(false)
	})

	termui.Handle("/sys/kbd/C-o", func(e termui.Event) {
		if _, ok := ui.uilists[uiMessages][ui.selectedPaneMessages]; ok {
			ui.openInTatwebui()
		}
	})

	termui.Handle("/sys/kbd", func(e termui.Event) {
		if !ui.isOnActionBox() {
			ui.switchToActionBox()
		}
		ui.send.BorderFg = termui.ColorRed
		if _, ok := ui.uilists[uiActionBox][0]; ok {
			ui.uilists[uiActionBox][0].list.BorderFg = termui.ColorWhite
		}
		char := e.Data.(termui.EvtKbd).KeyStr
		ui.send.Text += char
		ui.render()
	})

	for _, h := range ui.hooks {
		if h.Shortcut == "" {
			continue
		}
		if _, ok := termui.DefaultEvtStream.Handlers["/sys/kbd/"+h.Shortcut]; ok {
			internal.Exit("Shortcut %s is already used in tatcli", h.Shortcut)
		}
		termui.Handle("/sys/kbd/"+h.Shortcut, func(e termui.Event) {
			ui.RunExec(nil, e.Path, "")
		})
	}

}
Exemplo n.º 20
0
package user

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdUserRemoveFavoriteTopic = &cobra.Command{
	Use:   "removeFavoriteTopic",
	Short: "Remove a favorite Topic: tatcli user removeFavoriteTopic <topicName>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().UserRemoveFavoriteTopic(args[0])
			internal.Check(err)
			internal.Print(out)
		} else {
			internal.Exit("Invalid argument: tatcli user removeFavoriteTopic --help\n")
		}
	},
}
Exemplo n.º 21
0
package user

import (
	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdUserResetSystem = &cobra.Command{
	Use:   "resetSystemUser",
	Short: "Reset password for a system user (admin only): tatcli user resetSystemUser <username>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().UserResetSystem(tat.UsernameUserJSON{
				Username: args[0],
			})
			internal.Check(err)
			internal.Print(out)
		} else {
			internal.Exit("Invalid argument: tatcli user resetSystemUser --help\n")
		}
	},
}
Exemplo n.º 22
0
Arquivo: concat.go Projeto: ovh/tatcli
import (
	"strings"

	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdMessageConcat = &cobra.Command{
	Use:   "concat",
	Short: "Update a message (if it's enabled on topic) by adding additional text at the end of message: tatcli message concat <topic> <idMessage> <additional text...>",
	Long: `Update a message:
	It could be used to add tag or text at the end of one message.
	tatcli message concat <topic> <idMessage> <additional text...>
	`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 3 {
			topic := args[0]
			idMessage := args[1]
			addText := strings.Join(args[2:], " ")
			out, err := internal.Client().MessageConcat(topic, idMessage, addText)
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument to update a message: tatcli message concat --help\n")
		}
	},
}
Exemplo n.º 23
0
package topic

import (
	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdTopicComputeTags = &cobra.Command{
	Use:   "computetags",
	Short: "Compute Tags on this topic, only for tat admin and administrators on topic : tatcli topic computetags <topic>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			out, err := internal.Client().TopicComputeTags(tat.TopicNameJSON{Topic: args[0]})
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument: tatcli topic computetags --help\n")
		}
	},
}
Exemplo n.º 24
0
package stats

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdStatsDBReplSetGetConfig = &cobra.Command{
	Use:   "dbReplSetGetConfig",
	Short: "DB Stats: tatcli stats dbReplSetGetConfig",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 1 {
			internal.Exit("Invalid argument: tatcli stats dbReplSetGetConfig --help\n")
			cmd.Usage()
		} else {
			out, err := internal.Client().StatsDBReplSetGetConfig()
			internal.Check(err)
			internal.Print(out)
		}
	},
}
Exemplo n.º 25
0
package topic

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

func init() {
	cmdTopicDeleteAdminGroup.Flags().BoolVarP(&recursive, "recursive", "r", false, "Apply Delete Rights Admin recursively")
}

var cmdTopicDeleteAdminGroup = &cobra.Command{
	Use:   "deleteAdminGroup",
	Short: "Delete Admin Groups from a topic: tatcli topic deleteAdminGroup [--recursive] <topic> <groupname1> [<groupname2>]...",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			err := internal.Client().TopicDeleteAdminGroups(args[0], args[1:], recursive)
			internal.Check(err)
		} else {
			internal.Exit("Invalid argument: tatcli topic deleteAdminGroup --help\n")
		}
	},
}
Exemplo n.º 26
0
package topic

import (
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

func init() {
	cmdTopicAddAdminUser.Flags().BoolVarP(&recursive, "recursive", "r", false, "Apply Rights Admin recursively")
}

var cmdTopicAddAdminUser = &cobra.Command{
	Use:   "addAdminUser",
	Short: "Add Admin Users to a topic: tatcli topic addAdminUser [--recursive] <topic> <username1> [username2]...",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 2 {
			err := internal.Client().TopicAddAdminUsers(args[0], args[1:], recursive)
			internal.Check(err)
		} else {
			internal.Exit("Invalid argument: tatcli topic addAdminUser --help\n")
		}
	},
}
Exemplo n.º 27
0
func (ui *tatui) RunExec(hookIn *config.Hook, pathHook string, sendText string) {

	if ui.current != uiMessage && ui.current != uiMessages {
		return
	}

	if sendText == "" && pathHook == "" {
		return
	}
	if sendText != "" && hookIn == nil {
		return
	}
	var hook *config.Hook
	if pathHook != "" {
		for _, h := range ui.hooks {
			if "/sys/kbd/"+h.Shortcut == pathHook {
				hook = &h
				sendText = ""
				break
			}
		}
	} else {
		hook = hookIn
	}

	userExec := strings.Split(hook.Exec, " ")
	execCMD := strings.TrimSpace(userExec[0])
	if execCMD == "" {
		return
	}

	_, err := exec.LookPath(execCMD)
	if err != nil {
		internal.Exit("Invalid exec path for post-exec-run-action, err: %s", err.Error())
		return
	}

	msg := ui.currentListMessages[ui.selectedPaneMessages][ui.uilists[uiMessages][ui.selectedPaneMessages].position]

	if len(hook.Topics) > 0 && !tat.ArrayContains(hook.Topics, msg.Topic) {
		return
	}

	toExec := strings.Replace(hook.Exec, "$UI_SELECTED_MSG_ID", msg.ID, 1)
	toExec = strings.Replace(toExec, "$UI_SELECTED_MSG_TEXT", msg.Text, 1)
	toExec = strings.Replace(toExec, "$UI_SELECTED_MSG_TOPIC", msg.Topic, 1)
	toExec = strings.Replace(toExec, "$UI_SELECTED_MSG_AUTHOR_USERNAME", msg.Author.Username, 1)
	toExec = strings.Replace(toExec, "$UI_SELECTED_MSG_DATE_CREATION", fmt.Sprintf("%f", msg.DateCreation), 1)
	toExec = strings.Replace(toExec, "$UI_SELECTED_MSG_DATE_UPDATE", fmt.Sprintf("%f", msg.DateUpdate), 1)
	toExec = strings.Replace(toExec, "$UI_CURRENT_USERNAME", viper.GetString("username"), 1)

	if sendText != "" {
		sendTextWithoutCMD := strings.Replace(sendText, hook.Command+" ", "", 1)
		toExec = strings.Replace(toExec, "$UI_ACTION_TEXT", sendTextWithoutCMD, 1)
	}

	args := []string{}
	if len(toExec) > 1 {
		args = strings.Split(toExec, " ")
	}

	cmd := exec.Command(execCMD, args[1:]...)
	if e := cmd.Start(); e != nil {
		internal.Exit("Error with exec hook, err: %s", e.Error())
		return
	}

	ui.msg.Text = "Waiting " + hook.Exec + " for command to finish..."
	err = cmd.Wait()
	if err != nil {
		ui.msg.Text = fmt.Sprintf("Error:%s cmd:%s", err.Error(), strings.Join(cmd.Args, " "))
	} else {
		ui.msg.Text = fmt.Sprintf("Success: %s", strings.Join(cmd.Args, " "))
	}

}
Exemplo n.º 28
0
package message

import (
	"strings"

	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdMessageUnlabel = &cobra.Command{
	Use:   "unlabel",
	Short: "Remove a label from a message: tatcli message unlabel <topic> <idMessage> <my Label>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) >= 3 {
			label := strings.Join(args[2:], " ")
			out, err := internal.Client().MessageUnlabel(args[0], args[1], label)
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument to unlabel a message: tatcli message unlabel --help\n")
		}
	},
}
Exemplo n.º 29
0
	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

func init() {
	cmdTopicParameter.Flags().BoolVarP(&recursive, "recursive", "r", false, "Update param topic recursively")
}

var cmdTopicParameter = &cobra.Command{
	Use:     "parameter",
	Short:   "Update param on one topic: tatcli topic param [--recursive] <topic> <maxLength> <canForceDate> <canUpdateMsg> <canDeleteMsg> <canUpdateAllMsg> <canDeleteAllMsg> <adminCanUpdateAllMsg> <adminCanDeleteAllMsg> <isAutoComputeTags> <isAutoComputeLabels>",
	Aliases: []string{"param"},
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 11 {
			internal.Exit("Invalid parameter to tatcli topic param. See tatcli topic param --help\n")
		}

		var err error

		p := tat.TopicParameters{
			Topic: args[0],
		}

		p.MaxLength, err = strconv.Atoi(args[1])
		internal.Check(err)
		p.CanForceDate, err = strconv.ParseBool(args[2])
		internal.Check(err)
		p.CanUpdateMsg, err = strconv.ParseBool(args[3])
		internal.Check(err)
		p.CanDeleteMsg, err = strconv.ParseBool(args[4])
Exemplo n.º 30
0
package topic

import (
	"github.com/ovh/tat"
	"github.com/ovh/tatcli/internal"
	"github.com/spf13/cobra"
)

var cmdTopicAllSetParam = &cobra.Command{
	Use:   "allsetparam",
	Short: "Set a param for all topics, only for tat admin : tatcli topic allsetparam <paramName> <paramValue>",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 2 {
			out, err := internal.Client().TopicAllSetParam(tat.ParamJSON{ParamName: args[0], ParamValue: args[1]})
			internal.Check(err)
			if internal.Verbose {
				internal.Print(out)
			}
		} else {
			internal.Exit("Invalid argument: tatcli topic allsetparam --help\n")
		}
	},
}