add delete and change error handling
This commit is contained in:
parent
9bc47d40a6
commit
8e742d655d
4 changed files with 83 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -102,3 +102,4 @@ fabric.properties
|
||||||
.idea/
|
.idea/
|
||||||
.env
|
.env
|
||||||
!examples/**
|
!examples/**
|
||||||
|
/ovh-apikey-manager
|
||||||
|
|
31
README.md
31
README.md
|
@ -2,3 +2,34 @@
|
||||||
[![status-badge](https://ci.codeberg.org/api/badges/lauralani/ovh-apikey-manager/status.svg)](https://ci.codeberg.org/lauralani/ovh-apikey-manager)
|
[![status-badge](https://ci.codeberg.org/api/badges/lauralani/ovh-apikey-manager/status.svg)](https://ci.codeberg.org/lauralani/ovh-apikey-manager)
|
||||||
|
|
||||||
A tiny tool to manage your OVH api keys
|
A tiny tool to manage your OVH api keys
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
### Pre-Built Binary
|
||||||
|
To get the binary just download the latest release for your OS/Arch from the
|
||||||
|
[release page](https://codeberg.org/lauralani/ovh-apikey-manager/releases)
|
||||||
|
and put the binary somewhere convenient. The application assumes its config
|
||||||
|
file to be in the same directory as the binary.
|
||||||
|
|
||||||
|
### Compile from Source
|
||||||
|
Requirements:
|
||||||
|
- go1.20+
|
||||||
|
|
||||||
|
First, clone the repository to your local machine
|
||||||
|
```shell
|
||||||
|
git clone https://codeberg.org/lauralani/ovh-apikey-manager
|
||||||
|
|
||||||
|
# or if you want a specific branch:
|
||||||
|
git clone https://codeberg.org/lauralani/ovh-apikey-manager -b x.x.x
|
||||||
|
```
|
||||||
|
|
||||||
|
Then compile the project with
|
||||||
|
```shell
|
||||||
|
go build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
The application assumes the config file `.env`
|
||||||
|
|
||||||
|
```shell
|
||||||
|
|
||||||
|
```
|
44
cmd/delete.go
Normal file
44
cmd/delete.go
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
Copyright © 2023 Laura Kalb <dev@lauka.net>
|
||||||
|
*/
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"codeberg.org/lauralani/ovh-apikey-manager/app"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// deleteCmd represents the delete command
|
||||||
|
var deleteCmd = &cobra.Command{
|
||||||
|
Use: "delete",
|
||||||
|
Short: "Delete API keys",
|
||||||
|
Long: `Delete a single API key by ID`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
client := app.GetOVHClient()
|
||||||
|
id := args[0]
|
||||||
|
|
||||||
|
_, err := strconv.Atoi(id)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Argument must be a valid number\n")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = client.Delete("/me/api/application/"+id, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error deleting application: %q\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Application with id %v was successfully deleted.\n", id)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(deleteCmd)
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +25,8 @@ var listCmd = &cobra.Command{
|
||||||
var appresponselist []int
|
var appresponselist []int
|
||||||
err := client.Get("/me/api/application", &appresponselist)
|
err := client.Get("/me/api/application", &appresponselist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error getting application list: %v", err.Error())
|
log.Printf("Error getting application list: %q\n", err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, appid := range appresponselist {
|
for _, appid := range appresponselist {
|
||||||
|
@ -32,7 +34,8 @@ var listCmd = &cobra.Command{
|
||||||
|
|
||||||
err := client.Get("/me/api/application/"+strconv.Itoa(appid), &application)
|
err := client.Get("/me/api/application/"+strconv.Itoa(appid), &application)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error getting application %v: %v", appid, err.Error())
|
log.Printf("Error getting application %v: %v", appid, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
applist = append(applist, application)
|
applist = append(applist, application)
|
||||||
|
|
Loading…
Reference in a new issue