<commit_before>package main

import (
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"encoding/pem"
	"errors"
	"io/ioutil"
	"log"
	"os"

	"github.com/cybersiddhu/go-micro-auth/service"

	"gopkg.in/codegangsta/cli.v0"
	"gopkg.in/yaml.v1"
)

func main() {
	app := cli.NewApp()
	app.Name = "mauth"
	app.Usage = "App to work with HTTP authentication mircoservice"
	app.Version = "1.0.0"
	app.Flags = []cli.Flag{
		cli.StringFlag{"config", "c", "config.yaml", "Name of the config file"},
	}
	app.Commands = []cli.Command{
		{
			Name:  "server",
			Usage: "Run the HTTP server",
			Action: func(c *cli.Context) {
				config, err := readConfig(c)
				if err != nil {
					log.Fatal(err)
				}
				svc := &service.AuthService{}
				if err = svc.Run(config); err != nil {
					log.Fatal(err)
				}
			},
		},
		{
			Name:   "genkey",
			Usage:  "Generate private key file",
			Action: genPrivateKeyFile,
		},
	}
	app.Run(os.Args)
}

// Generate a 2048 bit RSA private key and write to the file given
// in the config file
func genPrivateKeyFile(c *cli.Context) {<commit_msg>Added another command to create table in the database<commit_after>package main

import (
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"encoding/pem"
	"errors"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
	"runtime"

	"github.com/cybersiddhu/go-micro-auth/service"
	"gopkg.in/codegangsta/cli.v0"
	"gopkg.in/jmoiron/sqlx.v0"
	"gopkg.in/yaml.v1"
)

func main() {
	app := cli.NewApp()
	app.Name = "microauth"
	app.Usage = "App to work with HTTP authentication mircoservice"
	app.Version = "1.0.0"
	app.Flags = []cli.Flag{
		cli.StringFlag{"config", "c", "config.yaml", "Name of the config file"},
	}
	app.Commands = []cli.Command{
		{
			Name:  "server",
			Usage: "Run the HTTP server",
			Action: func(c *cli.Context) {
				config, err := readConfig(c)
				if err != nil {
					log.Fatal(err)
				}
				svc := &service.AuthService{}
				if err = svc.Run(config); err != nil {
					log.Fatal(err)
				}
			},
		},
		{
			Name:   "generate-key",
			Usage:  "Generate private key file",
			Action: genPrivateKeyFile,
		},
		{
			Name:   "create-table",
			Usage:  "Create user table in the database",
			Action: createUserTable,
		},
	}
	app.Run(os.Args)
}

func createUserTable(c *cli.Context) {
	conf, err := readConfig(c)
	if err != nil {
		log.Fatal(err)
	}
	// figure out the schema file
	parentDir, _ := filepath.Split(currSrcDir())
	schema := filepath.Join(parentDir, "db", "user_"+conf.DbDriver+".sql")
	ct, err := ioutil.ReadFile(schema)
	if err != nil {
		log.Fatal(err)
	}
	//connect to database
	dbh, err := sqlx.Connect(conf.DbDriver, conf.DbSource)
	if err != nil {
		log.Fatal(err)
	}
	//load the schema
	tx := dbh.MustBegin()
	_ = tx.MustExec(string(ct))
	err = tx.Commit()
	if err != nil {
		log.Fatal(err)
	}
}

func currSrcDir() string {
	_, filename, _, ok := runtime.Caller(1)
	if !ok {
		log.Fatal("unable to retreive current src file path")
	}
	return filepath.Dir(filename)
}

// Generate a 2048 bit RSA private key and write to the file given
// in the config file
func genPrivateKeyFile(c *cli.Context) {
{'fraction_non_alphanumeric': 0.16029792746113988, 'fraction_numerical': 0.008419689119170985, 'mean_word_length': 3.2084468664850134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5150368', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1220, 'n_words': 284}