Skip to content

Commit

Permalink
add delete functionality (#425)
Browse files Browse the repository at this point in the history
This is slightly hacky. See https://stackoverflow.com/questions/52339336/removal-of-key-value-pair-from-viper-config-file

> TLDR; This is dangerous and doesn't work. This method doesn't work in tricky ways. If you viper.Set a key at all for the path then the viper.Get will return the map from the override list, which then won't let you delete any keys in the config list. So if your app adds and removes things, you may find it fails to delete with this method. –
[Will Brode](https://stackoverflow.com/users/1139197/will-brode)
 Commented May 11, 2023 at 7:29

In our specific use case, it seems to work just fine.
  • Loading branch information
bitte-ein-bit authored Jul 9, 2024
1 parent b6384b1 commit e08840d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ configured maximum Clisso will fallback to 3600 seconds.

### Deleting Apps

Deleting apps using the `clisso` command isn't currently supported. To delete an app, remove its
configuration from the config file.
For deleteing apps, use the following command:

clisso apps delete my-app

Deletion of an app will remove its configuration from the config file. You can also do it manually
by editing the config file.

### Obtaining Credentials

Expand Down
25 changes: 25 additions & 0 deletions cmd/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func init() {
cmdAppsCreate.AddCommand(cmdAppsCreateOneLogin)
cmdAppsCreate.AddCommand(cmdAppsCreateOkta)
cmdApps.AddCommand(cmdAppsSelect)
cmdApps.AddCommand(cmdAppsDelete)
}

var cmdApps = &cobra.Command{
Expand Down Expand Up @@ -229,3 +230,27 @@ var cmdAppsSelect = &cobra.Command{
}
},
}

var cmdAppsDelete = &cobra.Command{
Use: "delete [app name]",
Short: "Delete an app",
Long: "Delete an app from the config file.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
app := args[0]

if exists := viper.Get("apps." + app); exists == nil {
log.Log.Fatalf("App '%s' doesn't exist", app)
}

// Delete app
delete(viper.Get("apps").(map[string]interface{}), app)

// Write config to file
err := viper.WriteConfig()
if err != nil {
log.Log.Fatalf("Error writing config: %v", err)
}
log.Log.Printf("App '%s' deleted from config file", app)
},
}

0 comments on commit e08840d

Please sign in to comment.