Skip to content

Commit

Permalink
add more tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanato committed Apr 5, 2019
1 parent a07fc60 commit 695abe2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ workflows:
branches:
ignore: /.*/
- publish-github-release:
context: cpanato-gh-token
requires:
- lint
- test
- build
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
ignore: /.*/
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "com.cpanato.botserver",
"name": "Bot Server",
"description": "This plugin spin an environment to you test your application",
"version": "0.0.5",
"version": "0.0.6",
"server": {
"executables": {
"linux-amd64": "server/dist/plugin-linux-amd64",
Expand Down
29 changes: 24 additions & 5 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
const (
SPIN_ICON_URL = "https://icon-icons.com/icons2/1371/PNG/512/robot01_90832.png"
SPIN_USERNAME = "Bot Server"
BOT_KV_KEY = "_BOTSERVER_"
)

func getCommand() *model.Command {
Expand Down Expand Up @@ -115,8 +116,8 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo
return getCommandResponse(model.COMMAND_RESPONSE_TYPE_EPHEMERAL, "Nothing to destroy."), nil
}
return getCommandResponse(model.COMMAND_RESPONSE_TYPE_EPHEMERAL, "Instance "+info+" destroyed."), nil

case "help":
default:
msg := "run:\n/bot-server spin [flags] to spin a new test server\n/bot-server destroy to destroy the test server"
return getCommandResponse(model.COMMAND_RESPONSE_TYPE_EPHEMERAL, msg), nil
}
Expand Down Expand Up @@ -148,6 +149,13 @@ func (p *Plugin) spinServer(userId, channelId string, parameters []string) (inst
SubnetId: &p.configuration.AWSSubnetId,
}

var userName string
user, errUser := p.API.GetUser(userId)
if errUser != nil {
userName = userId
}
userName = user.Nickname

resp, err := svc.RunInstances(params)
if err != nil {
p.API.LogError("We could not create the aws resource", "user_id", userId, "err", err.Error())
Expand Down Expand Up @@ -175,6 +183,14 @@ func (p *Plugin) spinServer(userId, channelId string, parameters []string) (inst
Key: aws.String("Created"),
Value: aws.String(time.Now().Format("2006-01-02/15:04:05")),
},
{
Key: aws.String("UserName"),
Value: aws.String(userName),
},
{
Key: aws.String("CreatedBy"),
Value: aws.String("BotServer"),
},
},
})
if errtag != nil {
Expand Down Expand Up @@ -250,28 +266,31 @@ func (p *Plugin) sendMessageSpinServer(c *plugin.Context, args *model.CommandArg
}

func (p *Plugin) storeInstanceId(userID, instanceId string) error {
err := p.API.KVSet(userID, []byte(instanceId))
key := fmt.Sprintf("%s%s", BOT_KV_KEY, userID)
err := p.API.KVSet(key, []byte(instanceId))
if err != nil {
return fmt.Errorf("Encountered error saving instanceId mapping")
}
return nil
}

func (p *Plugin) getInstanceId(userID string) string {
instanceId, _ := p.API.KVGet(userID)
key := fmt.Sprintf("%s%s", BOT_KV_KEY, userID)
instanceId, _ := p.API.KVGet(key)
return string(instanceId)
}

func (p *Plugin) deleteInstanceId(userID, PublicIP string) (info string, err *model.AppError) {
instanceId, err := p.API.KVGet(userID)
key := fmt.Sprintf("%s%s", BOT_KV_KEY, userID)
instanceId, err := p.API.KVGet(key)
if err != nil {
return "", err
}
if instanceId == nil {
return "", nil
}

err = p.API.KVDelete(userID)
err = p.API.KVDelete(key)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion server/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ var manifest = struct {
Version string
}{
Id: "com.cpanato.botserver",
Version: "0.0.5",
Version: "0.0.6",
}

0 comments on commit 695abe2

Please sign in to comment.