Browse Source

fix delete key endpoint

Anish Mukherjee 2 years ago
parent
commit
c1f652487c
3 changed files with 8 additions and 8 deletions
  1. 2 3
      cli/cmd/keys/delete.go
  2. 4 3
      cli/functions/http_client.go
  3. 2 2
      cli/functions/keys.go

+ 2 - 3
cli/cmd/keys/delete.go

@@ -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 {
-			fmt.Println("Success")
-		}
+		functions.DeleteKey(args[0], args[1])
+		fmt.Println("Success")
 	},
 }
 

+ 4 - 3
cli/functions/http_client.go

@@ -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 err := json.Unmarshal(resBodyBytes, body); err != nil {
-		// log.Printf("Error unmarshalling JSON: %s", err)
-		return nil
+	if len(resBodyBytes) > 0 {
+		if err := json.Unmarshal(resBodyBytes, body); err != nil {
+			log.Printf("Error unmarshalling JSON: %s", err)
+		}
 	}
 	return body
 }

+ 2 - 2
cli/functions/keys.go

@@ -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)
 }