Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
fix tokens handler
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Sep 17, 2022
1 parent abbc603 commit 862c3a7
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 114 deletions.
9 changes: 3 additions & 6 deletions cmd/app/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ func DockerCMD() *cobra.Command {

func DockerBuildCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "build",
Short: "Build your bot docker image",
PreRun: func(cmd *cobra.Command, args []string) {
tools.CheckDir()
tools.SetupTokensInDocker()
},
Use: "build",
Short: "Build your bot docker image",
PreRun: func(cmd *cobra.Command, args []string) { tools.CheckDir() },
Run: func(cmd *cobra.Command, args []string) { build_image.DockerBuildImage() },
PostRun: func(cmd *cobra.Command, args []string) { tools.RemoveConfig() },
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app
import (
"github.com/abdfnx/botway/internal/options"
"github.com/abdfnx/botway/internal/pipes/initx"
"github.com/abdfnx/botway/tools"
"github.com/spf13/cobra"
)

Expand All @@ -19,8 +18,6 @@ func InitCMD() *cobra.Command {
Aliases: []string{"."},
Run: func(cmd *cobra.Command, args []string) {
if opts.Docker {
tools.SetupTokensInDocker()

initx.DockerInit()
} else {
initx.Init()
Expand Down
11 changes: 4 additions & 7 deletions internal/pipes/initx/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,15 @@ func DockerInit() {
bot_token = "TELEGRAM_TOKEN"
}

env := viper.New()
env.SetConfigType("env")

viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+".bot_token", env.GetString(bot_token))
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+".bot_token", os.Getenv(bot_token))
viper.SetDefault("botway.bots_names", []string{botwaygo.GetBotInfo("bot.name")})

if botType != "telegram" {
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+"."+cid, env.GetString(app_token))
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+"."+cid, os.Getenv(app_token))
}

if botType == "slack" {
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+".signing_secret", env.GetString(signing_secret))
viper.SetDefault("botway.bots."+botwaygo.GetBotInfo("bot.name")+".signing_secret", os.Getenv(signing_secret))
}

if botType == "discord" {
Expand All @@ -68,7 +65,7 @@ func DockerInit() {

sgi := strings.ToUpper(server) + "_GUILD_ID"

viper.Set("botway.bots."+botwaygo.GetBotInfo("bot.name")+".guilds."+server+".server_id", env.GetString(sgi))
viper.Set("botway.bots."+botwaygo.GetBotInfo("bot.name")+".guilds."+server+".server_id", os.Getenv(sgi))
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions internal/railway/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/abdfnx/botway/constants"
"github.com/abdfnx/botway/tools"
"github.com/abdfnx/botwaygo"
"github.com/botwayorg/railway-api/entity"
CLIErrors "github.com/botwayorg/railway-api/errors"
Expand All @@ -17,7 +16,6 @@ import (

func (h *Handler) Delpoy(ctx context.Context, req *entity.CommandRequest) error {
CheckBuildKit()
tools.SetupTokensInDocker()

isVerbose, err := req.Cmd.Flags().GetBool("verbose")
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions internal/render/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import (
)

func (m model) Auth() {
if _, err := os.Stat(constants.RenderConfigFile); os.IsNotExist(err) {
renderConfigFile := os.WriteFile(constants.RenderConfigFile, []byte("{}"), 0644)

if renderConfigFile != nil {
log.Fatal(renderConfigFile)
}
}

email := strings.ReplaceAll(m.inputs[1].Value(), "@", "%40")

url := fmt.Sprintf("https://api.render.com/v1/owners?name=%s&email=%s&limit=20", m.inputs[0].Value(), email)
Expand Down
3 changes: 0 additions & 3 deletions internal/render/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import (
"strings"

"github.com/abdfnx/botway/constants"
"github.com/abdfnx/botway/tools"
)

func Deploy() {
tools.SetupTokensInDocker()

UpdateTokens(serviceId)

url := fmt.Sprintf("https://api.render.com/v1/services/%s/deploys", serviceId)
Expand Down
5 changes: 5 additions & 0 deletions tools/check-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tools
import (
"fmt"
"os"
"path/filepath"

"github.com/abdfnx/botway/constants"
)
Expand All @@ -14,3 +15,7 @@ func CheckDir() {
panic(constants.FAIL_FOREGROUND.Render("You need to run this command in your bot directory"))
}
}

func RemoveConfig() {
os.Remove(filepath.Join("config", "botway-tokens.env"))
}
93 changes: 0 additions & 93 deletions tools/setup-tokens-in-docker.go

This file was deleted.

0 comments on commit 862c3a7

Please sign in to comment.