account

package
v0.0.0-...-0f594a8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Modify action.Action = func(ctx context.Context) error {
	l := logger.WithField("func", "Modify")

	l.Info("creating database client")
	dbClient, err := bun.New(ctx)
	if err != nil {
		l.Errorf("db: %s", err.Error())

		return err
	}
	defer func() {
		l.Info("closing database client")
		err := dbClient.Close(ctx)
		if err != nil {
			l.Errorf("closing db: %s", err.Error())
		}
	}()

	accountString := viper.GetString(config.Keys.Account)

	username, domain, err := util.SplitAccount(accountString)
	if err != nil {
		l.Errorf("invalid account %s: %s", accountString, err.Error())

		return err
	}

	instance, err := dbClient.ReadInstanceByDomain(ctx, domain)
	if err != nil {
		l.Errorf("db read %s: %s", domain, err.Error())

		return err
	}
	if instance == nil {
		l.Infof("can't find instance %s", domain)

		return nil
	}
	l.Debugf("found instance %d: %+v", instance.ID, instance)

	account, err := dbClient.ReadAccountByUsername(ctx, username, instance.ID)
	if err != nil {
		l.Errorf("db read %s: %s", username, err.Error())

		return err
	}
	if instance == nil {
		l.Infof("can't find user %s", username)

		return nil
	}
	l.Debugf("found account %d: %+v", account.ID, account)

	for _, addGroup := range viper.GetStringSlice(config.Keys.AccountAddGroup) {
		switch addGroup {
		case "admin":
			account.IsAdmin = true
		default:
			l.Warnf("unknown group %s, skipping", addGroup)
		}
	}

	err = dbClient.UpdateAccount(ctx, account)
	if err != nil {
		l.Errorf("db update: %s", err.Error())

		return err
	}

	return nil
}

Modify runs database migrations.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL