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", Short: "Delete a key",
Long: `Delete a key`, Long: `Delete a key`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if functions.DeleteKey(args[0], args[1]) == nil { functions.DeleteKey(args[0], args[1])
fmt.Println("Success") 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)) log.Fatalf("Error response: %s", string(resBodyBytes))
} }
body := new(T) body := new(T)
if err := json.Unmarshal(resBodyBytes, body); err != nil { if len(resBodyBytes) > 0 {
// log.Printf("Error unmarshalling JSON: %s", err) if err := json.Unmarshal(resBodyBytes, body); err != nil {
return nil log.Printf("Error unmarshalling JSON: %s", err)
}
} }
return body return body
} }

View File

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