Skip to content

Commit

Permalink
correct var name; refactor boolean expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mskarbe committed Nov 5, 2020
1 parent 122c391 commit 0972782
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
21 changes: 10 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func main() {
impersonatedUserEmail = ""
throttleRequests = 500 * time.Millisecond

splittedConfig = false
userCfg *config.Config
groupCfg *config.Config
orgunitsCfg *config.Config
err error
splitConfig = false
userCfg *config.Config
groupCfg *config.Config
orgunitsCfg *config.Config
err error
)

flag.StringVar(&configFile, "config", configFile, "path to the config.yaml that manages whole organization; cannot be used together with separated config files for users/groups/organizational units")
Expand All @@ -63,22 +63,21 @@ func main() {
return
}

if usersConfigFile != "" || groupsConfigFile != "" || orgunitsConfigFile != "" {
splittedConfig = true
}
if splittedConfig == true && configFile != "" {
splitConfig = usersConfigFile != "" || groupsConfigFile != "" || orgunitsConfigFile != ""

if splitConfig == true && configFile != "" {
log.Print("⚠ General configuration file specified (-config); cannot manage resources in separated files as well (-users-config/-groups-config/-orgunits-config).\n\n")
flag.Usage()
os.Exit(1)
} else if splittedConfig == false && configFile == "" {
} else if splitConfig == false && configFile == "" {
// general config file must be present if no splitted ones are specified
configFile = os.Getenv("GMAN_CONFIG_FILE")
if configFile == "" {
log.Print("⚠ No configuration file(s) specified.\n\n")
flag.Usage()
os.Exit(1)
}
} else if splittedConfig == false && configFile != "" {
} else if splitConfig == false && configFile != "" {
// open one config file
cfg, err := config.LoadFromFile(configFile)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ func SaveToFile(config *Config, filename string) error {

// validateEmailFormat is a helper function that checks for existance of '@' and the length of the address
func validateEmailFormat(email string) bool {
if (strings.Contains(email, "@")) && len(email) < 129 {
return true
} else {
return false
}
return (len(email) < 129 && strings.Contains(email, "@"))
}

func (c *Config) ValidateUsers() []error {
Expand Down
3 changes: 0 additions & 3 deletions pkg/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func ExportUsers(ctx context.Context, clientService *admin.Service, licensingService *glib.LicensingService, cfg *config.Config) error {
//log.Println("⇄ Exporting users from GSuite...")
// get the users array
users, err := glib.GetListOfUsers(*clientService)
if err != nil {
Expand All @@ -37,7 +36,6 @@ func ExportUsers(ctx context.Context, clientService *admin.Service, licensingSer
}

func ExportGroups(ctx context.Context, clientService *admin.Service, groupService *groupssettings.Service, cfg *config.Config) error {
//log.Println("⇄ Exporting groups from GSuite...")
// get the groups array
groups, err := glib.GetListOfGroups(clientService)
if err != nil {
Expand Down Expand Up @@ -70,7 +68,6 @@ func ExportGroups(ctx context.Context, clientService *admin.Service, groupServic
}

func ExportOrgUnits(ctx context.Context, clientService *admin.Service, cfg *config.Config) error {
// log.Println("⇄ Exporting organizational units from GSuite...")
// get the users array
orgUnits, err := glib.GetListOfOrgUnits(clientService)
if err != nil {
Expand Down

0 comments on commit 0972782

Please sign in to comment.