2022-02-11 13:07:32 +00:00
|
|
|
package initialise
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2022-02-16 12:30:49 +00:00
|
|
|
_ "embed"
|
|
|
|
"fmt"
|
2022-02-11 13:07:32 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/logging"
|
2022-02-11 13:07:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func newGrant() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "grant",
|
|
|
|
Short: "set ALL grant to user",
|
|
|
|
Long: `Sets ALL grant to the database user.
|
|
|
|
|
|
|
|
Prereqesits:
|
2022-09-05 09:24:31 +00:00
|
|
|
- cockroachDB or postgreSQL
|
2022-02-11 13:07:32 +00:00
|
|
|
`,
|
2022-03-28 08:05:09 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2022-09-07 08:35:12 +00:00
|
|
|
config := MustNewConfig(viper.GetViper())
|
2022-03-28 08:05:09 +00:00
|
|
|
|
2022-07-28 14:25:42 +00:00
|
|
|
err := initialise(config.Database, VerifyGrant(config.Database.Database(), config.Database.Username()))
|
2022-03-28 08:05:09 +00:00
|
|
|
logging.OnError(err).Fatal("unable to set grant")
|
2022-02-11 13:07:32 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-31 07:52:43 +00:00
|
|
|
func VerifyGrant(databaseName, username string) func(*sql.DB) error {
|
2022-02-16 12:30:49 +00:00
|
|
|
return func(db *sql.DB) error {
|
2022-08-31 07:52:43 +00:00
|
|
|
logging.WithFields("user", username, "database", databaseName).Info("verify grant")
|
|
|
|
|
|
|
|
return exec(db, fmt.Sprintf(grantStmt, databaseName, username), nil)
|
2022-02-11 13:07:32 +00:00
|
|
|
}
|
|
|
|
}
|