fix delete key endpoint

This commit is contained in:
Anish Mukherjee
2022-11-21 18:59:14 +05:30
parent aab92ce88d
commit c1f652487c
3 changed files with 8 additions and 8 deletions

View File

@@ -13,9 +13,8 @@ var keysDeleteCmd = &cobra.Command{
Short: "Delete a key",
Long: `Delete a key`,
Run: func(cmd *cobra.Command, args []string) {
if functions.DeleteKey(args[0], args[1]) == nil {
functions.DeleteKey(args[0], args[1])
fmt.Println("Success")
}
},
}

View File

@@ -74,9 +74,10 @@ func request[T any](method, route string, payload any) *T {
log.Fatalf("Error response: %s", string(resBodyBytes))
}
body := new(T)
if len(resBodyBytes) > 0 {
if err := json.Unmarshal(resBodyBytes, body); err != nil {
// log.Printf("Error unmarshalling JSON: %s", err)
return nil
log.Printf("Error unmarshalling JSON: %s", err)
}
}
return body
}

View File

@@ -18,6 +18,6 @@ func CreateKey(networkName string, key *models.AccessKey) *models.AccessKey {
}
// DeleteKey - delete an access key
func DeleteKey(networkName, keyName string) *string {
return request[string](http.MethodDelete, fmt.Sprintf("/api/networks/%s/keys/%s", networkName, keyName), nil)
func DeleteKey(networkName, keyName string) {
request[string](http.MethodDelete, fmt.Sprintf("/api/networks/%s/keys/%s", networkName, keyName), nil)
}