cmd

package
v0.0.0-...-9698ad7 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const ETCDTTLDefault = int64(24 * 60 * 60)

ETCDTTLDefault - default ttl - 1day in seconds = 24 hours * 60 minutes * 60 seconds

View Source
const SyncUsersIntervalDefault = int64(5 * 60)

SyncUsersIntervalDefault - default interval between synchronize users - 5 minutes in seconds = 5 minutes * 60 seconds

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "github-authorized-keys",
	Short: "Use GitHub teams to manage system user accounts and authorized_keys",
	Long: `
Use GitHub teams to manage system user accounts and authorized_keys.

Config:
  REQUIRED: Github API token        | flag --github-api-token    OR environment variable GITHUB_API_TOKEN
  REQUIRED: Github organization     | flag --github-organization OR environment variable GITHUB_ORGANIZATION
  REQUIRED: One of
  		   Github team name | flag --github-team    OR environment variable GITHUB_TEAM
  			OR
  		   Github team id   | flag --github-team-id OR Environment variable GITHUB_TEAM_ID
`,
	RunE: func(cmd *cobra.Command, args []string) error {
		logger := log.WithFields(log.Fields{"class": "RootCmd", "method": "RunE"})

		etcdTTL, err := time.ParseDuration(viper.GetString("etcd_ttl") + "s")

		if err != nil {
			return err
		}

		cfg := config.Config{
			GithubAPIToken:     viper.GetString("github_api_token"),
			GithubOrganization: viper.GetString("github_organization"),
			GithubTeamName:     viper.GetString("github_team"),
			GithubTeamID:       viper.GetInt64("github_team_id"),
			GithubURL:          viper.GetString("github_url"),

			EtcdEndpoints: fixStringSlice(viper.GetString("etcd_endpoint")),
			EtcdPrefix:    viper.GetString("etcd_prefix"),
			EtcdTTL:       etcdTTL,

			UserGID:    viper.GetString("sync_users_gid"),
			UserGroups: fixStringSlice(viper.GetString("sync_users_groups")),
			UserShell:  viper.GetString("sync_users_shell"),
			Root:       viper.GetString("sync_users_root"),
			Interval:   uint64(viper.GetInt64("sync_users_interval")),

			IntegrateWithSSH: viper.GetBool("integrate_ssh"),

			Listen: viper.GetString("listen"),
		}

		var githubURL string

		if cfg.GithubURL != "" {
			githubURL = cfg.GithubURL
		} else {
			githubURL = "github.com"
		}

		logger.Infof("Config: GithubAPIToken - %v", mask(cfg.GithubAPIToken))
		logger.Infof("Config: GithubOrganization - %v", mask(cfg.GithubOrganization))
		logger.Infof("Config: GithubURL - %v", githubURL)
		logger.Infof("Config: GithubTeamName - %v", mask(cfg.GithubTeamName))
		logger.Infof("Config: GithubTeamID - %v", mask(fmt.Sprint(cfg.GithubTeamID)))
		logger.Infof("Config: EtcdEndpoints - %v", cfg.EtcdEndpoints)
		logger.Infof("Config: EtcdPrefix - %v", cfg.EtcdPrefix)
		logger.Infof("Config: EtcdTTL - %v seconds", cfg.EtcdTTL)
		logger.Infof("Config: UserGID - %v", cfg.UserGID)
		logger.Infof("Config: UserGroups - %v", cfg.UserGroups)
		logger.Infof("Config: UserShell - %v", cfg.UserShell)
		logger.Infof("Config: Root - %v", cfg.Root)
		logger.Infof("Config: Interval - %v seconds", cfg.Interval)
		logger.Infof("Config: IntegrateWithSSH - %v", cfg.IntegrateWithSSH)
		logger.Infof("Config: Listen - %v", cfg.Listen)

		err = cfg.Validate()

		if err == nil {
			jobs.Run(cfg)
			server.Run(cfg)
		}

		return err
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

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