-
Notifications
You must be signed in to change notification settings - Fork 4
Add user directories commands #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oNaiPs
wants to merge
1
commit into
main
Choose a base branch
from
user_directories
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+854
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| // Package cmd implements access-cli commands | ||
| package cmd | ||
|
|
||
| /* | ||
| Copyright © 2020 Barracuda Networks, Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| api "github.com/barracuda-cloudgen-access/access-cli/client/user_directories" | ||
| "github.com/barracuda-cloudgen-access/access-cli/models" | ||
| ) | ||
|
|
||
| // userDirectoriesAddCmd represents the add command | ||
| var userDirectoriesAddCmd = &cobra.Command{ | ||
| Use: "add", | ||
| Aliases: []string{"create", "new"}, | ||
| Short: "Add user directories", | ||
| PreRunE: func(cmd *cobra.Command, args []string) error { | ||
| err := preRunCheckAuth(cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = preRunFlagChecks(cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| tw := userDirectoryBuildTableWriter() | ||
| createdList := []*models.UserDirectory{} | ||
| total := 0 | ||
|
|
||
| err := forAllInput(cmd, args, true, | ||
| func(values *inputEntry) (interface{}, error) { // do func | ||
| total++ // this is the total of successful+failures, must increment before failure | ||
| userdirectory := &api.CreateUserDirectoryParamsBodyUserDirectory{} | ||
|
|
||
| err := placeInputValues(cmd, values, userdirectory, | ||
| func(s string) { userdirectory.ShortCode = s }, | ||
| func(s string) { userdirectory.Name = s }, | ||
| func(s string) { userdirectory.DirectoryType = s }, | ||
| func(s string) { userdirectory.Notes = s }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| body := api.CreateUserDirectoryBody{UserDirectory: userdirectory} | ||
| params := api.NewCreateUserDirectoryParams() | ||
|
|
||
| setTenant(cmd, params) | ||
| params.SetUserDirectory(body) | ||
|
|
||
| resp, err := global.Client.UserDirectories.CreateUserDirectory(params, global.AuthWriter) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return resp.Payload.UserDirectory, nil | ||
| }, func(data interface{}) { // printSuccess func | ||
| userdirectory := data.(models.UserDirectory) | ||
| createdList = append(createdList, &userdirectory) | ||
| userDirectoryTableWriterAppend(tw, userdirectory) | ||
| }, func(err error, id interface{}) { // doOnError func | ||
| createdList = append(createdList, nil) | ||
| userDirectoryTableWriterAppendError(tw, err, id) | ||
| }) | ||
| return printListOutputAndError(cmd, createdList, tw, total, err) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| settingsUserDirectoryCmd.AddCommand(userDirectoriesAddCmd) | ||
|
|
||
| // Here you will define your flags and configuration settings. | ||
|
|
||
| // Cobra supports Persistent Flags which will work for this command | ||
| // and all subcommands, e.g.: | ||
| // userDirectoriesAddCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
|
||
| // Cobra supports local flags which will only run when this command | ||
| // is called directly, e.g.: | ||
| // userDirectoriesAddCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
|
|
||
| initOutputFlags(userDirectoriesAddCmd) | ||
| initLoopControlFlags(userDirectoriesAddCmd) | ||
| initTenantFlags(userDirectoriesAddCmd) | ||
|
|
||
| initInputFlags(userDirectoriesAddCmd, "userdirectory", | ||
| inputField{ | ||
| Name: "ShortCode", | ||
| FlagName: "shortcode", | ||
| FlagDescription: "specify a shortcode for the directory", | ||
| VarType: "string", | ||
| Mandatory: true, | ||
| DefaultValue: "", | ||
| }, | ||
| inputField{ | ||
| Name: "Name", | ||
| FlagName: "name", | ||
| FlagDescription: "specify the name for the directory", | ||
| VarType: "string", | ||
| Mandatory: true, | ||
| DefaultValue: "", | ||
| MainField: true, | ||
| }, | ||
| inputField{ | ||
| Name: "Type", | ||
| FlagName: "type", | ||
| FlagDescription: "specify source for the user directory", | ||
| VarType: "string", | ||
| Mandatory: true, | ||
| DefaultValue: "", | ||
| }, | ||
| inputField{ | ||
| Name: "Notes", | ||
| FlagName: "notes", | ||
| FlagDescription: "additional notes", | ||
| VarType: "string", | ||
| Mandatory: false, | ||
| DefaultValue: "", | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Package cmd implements access-cli commands | ||
| package cmd | ||
|
|
||
| /* | ||
| Copyright © 2020 Barracuda Networks, Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strconv" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| api "github.com/barracuda-cloudgen-access/access-cli/client/user_directories" | ||
| ) | ||
|
|
||
| // userDirectoryDeleteCmd represents the delete command | ||
| var userDirectoryDeleteCmd = &cobra.Command{ | ||
| Use: "delete [userdirectory ID]", | ||
| Aliases: []string{"remove", "rm"}, | ||
| Short: "Delete user directories", | ||
| PreRunE: func(cmd *cobra.Command, args []string) error { | ||
| err := preRunCheckAuth(cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = preRunFlagChecks(cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if len(args) == 0 && !cmd.Flags().Changed("id") { | ||
| return fmt.Errorf("missing proxy ID argument") | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| var id int64 | ||
| var err error | ||
| if cmd.Flags().Changed("id") { | ||
| id, err = cmd.Flags().GetInt64("id") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| id, err = strconv.ParseInt(args[0], 10, 64) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| params := api.NewDeleteUserDirectoryParams() | ||
| setTenant(cmd, params) | ||
| params.SetID(id) | ||
|
|
||
| tw, j := multiOpBuildTableWriter() | ||
| _, err = global.Client.UserDirectories.DeleteUserDirectory(params, global.AuthWriter) | ||
|
|
||
| var result interface{} | ||
| result = "success" | ||
| if err != nil { | ||
| result = err | ||
| } | ||
| multiOpTableWriterAppend(tw, &j, "*", result) | ||
|
|
||
| return printListOutputAndError(cmd, j, tw, 1, err) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| settingsUserDirectoryCmd.AddCommand(userDirectoryDeleteCmd) | ||
|
|
||
| // Here you will define your flags and configuration settings. | ||
|
|
||
| // Cobra supports Persistent Flags which will work for this command | ||
| // and all subcommands, e.g.: | ||
| // userDirectoryDeleteCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
|
||
| // Cobra supports local flags which will only run when this command | ||
| // is called directly, e.g.: | ||
| // userDirectoryDeleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
|
|
||
| initInputFlags(userDirectoryDeleteCmd, "userdirectory", | ||
| inputField{ | ||
| Name: "ID", | ||
| FlagName: "id", | ||
| FlagDescription: "specify the ID of the user to edit", | ||
| VarType: "int", | ||
| Mandatory: true, | ||
| DefaultValue: 0, | ||
| MainField: true, | ||
| }) | ||
| initOutputFlags(userDirectoryDeleteCmd) | ||
| initLoopControlFlags(userDirectoryDeleteCmd) | ||
| initTenantFlags(userDirectoryDeleteCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| // Package cmd implements access-cli commands | ||
| package cmd | ||
|
|
||
| /* | ||
| Copyright © 2020 Barracuda Networks, Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| api "github.com/barracuda-cloudgen-access/access-cli/client/user_directories" | ||
| "github.com/barracuda-cloudgen-access/access-cli/models" | ||
| ) | ||
|
|
||
| // userDirectoriesEditCmd represents the edit command | ||
| var userDirectoriesEditCmd = &cobra.Command{ | ||
| Use: "edit", | ||
| Short: "Edit user directories", | ||
| PreRunE: func(cmd *cobra.Command, args []string) error { | ||
| err := preRunCheckAuth(cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = preRunFlagChecks(cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| tw := userDirectoryBuildTableWriter() | ||
| createdList := []*models.UserDirectory{} | ||
| total := 0 | ||
|
|
||
| err := forAllInput(cmd, args, false, | ||
| func(values *inputEntry) (interface{}, error) { // do func | ||
| total++ // this is the total of successful+failures, must increment before failure | ||
| params := api.NewEditUserDirectoryParams() | ||
| setTenant(cmd, params) | ||
|
|
||
| userdirectory := &models.UserDirectory{} | ||
|
|
||
| err := placeInputValues(cmd, values, userdirectory, | ||
| func(s int) { userdirectory.ID = int64(s) }, | ||
| func(s string) { userdirectory.ShortCode = s }, | ||
| func(s string) { userdirectory.Name = s }, | ||
| func(s string) { userdirectory.DirectoryType = s }, | ||
| func(s string) { userdirectory.Notes = s }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| // here, map the ID from the "fake request body" to the correct place | ||
| params.SetID(userdirectory.ID) | ||
| body := api.EditUserDirectoryBody{UserDirectory: userdirectory} | ||
|
|
||
| params.SetUserDirectory(body) | ||
|
|
||
| resp, err := global.Client.UserDirectories.EditUserDirectory(params, global.AuthWriter) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return resp.Payload.UserDirectory, nil | ||
| }, func(data interface{}) { // printSuccess func | ||
| userdirectory := data.(models.UserDirectory) | ||
| createdList = append(createdList, &userdirectory) | ||
| userDirectoryTableWriterAppend(tw, userdirectory) | ||
| }, func(err error, id interface{}) { // doOnError func | ||
| createdList = append(createdList, nil) | ||
| userDirectoryTableWriterAppendError(tw, err, id) | ||
| }) | ||
| return printListOutputAndError(cmd, createdList, tw, total, err) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| settingsUserDirectoryCmd.AddCommand(userDirectoriesEditCmd) | ||
|
|
||
| // Here you will define your flags and configuration settings. | ||
|
|
||
| // Cobra supports Persistent Flags which will work for this command | ||
| // and all subcommands, e.g.: | ||
| // userDirectoriesEditCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
|
||
| // Cobra supports local flags which will only run when this command | ||
| // is called directly, e.g.: | ||
| // userDirectoriesEditCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
|
|
||
| initOutputFlags(userDirectoriesEditCmd) | ||
| initLoopControlFlags(userDirectoriesEditCmd) | ||
| initTenantFlags(userDirectoriesEditCmd) | ||
|
|
||
| initInputFlags(userDirectoriesEditCmd, "userdirectory", | ||
| inputField{ | ||
| Name: "ID", | ||
| FlagName: "id", | ||
| FlagDescription: "specify the ID of the user to edit", | ||
| VarType: "int", | ||
| DefaultValue: 0, | ||
| Mandatory: true, | ||
| MainField: true, | ||
| SchemaName: "id", | ||
| }, | ||
| inputField{ | ||
| Name: "ShortCode", | ||
| FlagName: "shortcode", | ||
| FlagDescription: "specify a shortcode for the directory", | ||
| VarType: "string", | ||
| DefaultValue: "", | ||
| }, | ||
| inputField{ | ||
| Name: "Name", | ||
| FlagName: "name", | ||
| FlagDescription: "specify the name for the directory", | ||
| VarType: "string", | ||
| DefaultValue: "", | ||
| MainField: true, | ||
| }, | ||
| inputField{ | ||
| Name: "Type", | ||
| FlagName: "type", | ||
| FlagDescription: "specify source for the user directory", | ||
| VarType: "string", | ||
| DefaultValue: "", | ||
| }, | ||
| inputField{ | ||
| Name: "Notes", | ||
| FlagName: "notes", | ||
| FlagDescription: "additional notes", | ||
| VarType: "string", | ||
| Mandatory: false, | ||
| DefaultValue: "", | ||
| }) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this response has the
enrollment_urlon it that is only returned on creation, I think you should print that separately from the table with a message or something saying "you put this on the connector", whatever we are doing in the proxy add flow (or if we are not doing it there we should also fix that)