-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
data-api: Auth provider delete command (#93)
* feat: base cmd * feat: typo in test func name * feat: changie * feat: remove comment
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kind: Added | ||
body: GraphQL Data API authentication provider delete command | ||
time: 2024-11-04T08:08:49.404096+01:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
neo4j-cli/aura/internal/subcommands/dataapi/graphql/authprovider/delete.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package authprovider | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/neo4j/cli/common/clicfg" | ||
"github.com/neo4j/cli/neo4j-cli/aura/internal/api" | ||
"github.com/neo4j/cli/neo4j-cli/aura/internal/output" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewDeleteCmd(cfg *clicfg.Config) *cobra.Command { | ||
var ( | ||
instanceId string | ||
dataApiId string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "delete <id>", | ||
Short: "Delete a GraphQL Data API authentication provider", | ||
Long: "Deletes a GraphQL Data API authentication provider. This action can not be undone.", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.SilenceUsage = true | ||
path := fmt.Sprintf("/instances/%s/data-apis/graphql/%s/auth-providers/%s", instanceId, dataApiId, args[0]) | ||
|
||
resBody, statusCode, err := api.MakeRequest(cfg, path, &api.RequestConfig{ | ||
Method: http.MethodDelete, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// NOTE: delete should not return OK (200), it always returns 202, checking both just in case | ||
if statusCode == http.StatusAccepted || statusCode == http.StatusOK { | ||
output.PrintBody(cmd, cfg, resBody, []string{"id", "name", "type", "enabled", "url"}) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&instanceId, "instance-id", "", "The ID of the instance to delete the Data API for") | ||
cmd.MarkFlagRequired("instance-id") | ||
|
||
cmd.Flags().StringVar(&dataApiId, "data-api-id", "", "The ID of the GraphQL Data API to delete the Authentication provider for") | ||
cmd.MarkFlagRequired("data-api-id") | ||
|
||
return cmd | ||
} |
45 changes: 45 additions & 0 deletions
45
neo4j-cli/aura/internal/subcommands/dataapi/graphql/authprovider/delete_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package authprovider_test | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/neo4j/cli/neo4j-cli/aura/internal/test/testutils" | ||
) | ||
|
||
func TestDeleteAuthProvider(t *testing.T) { | ||
helper := testutils.NewAuraTestHelper(t) | ||
defer helper.Close() | ||
|
||
helper.SetConfigValue("aura.beta-enabled", true) | ||
|
||
instanceId := "2f49c2b3" | ||
dataApiId := "a342b824" | ||
authProviderId := "87d46b4b-3bfb-4ad2-8dac-0e95cf72d39f" | ||
mockHandler := helper.NewRequestHandlerMock(fmt.Sprintf("/v1/instances/%s/data-apis/graphql/%s/auth-providers/%s", instanceId, dataApiId, authProviderId), http.StatusAccepted, `{ | ||
"data": { | ||
"id": "87d46b4b-3bfb-4ad2-8dac-0e95cf72d39f", | ||
"name": "test-key", | ||
"type": "jwks", | ||
"enabled": true, | ||
"url": "https://test.com/.well-known/jwks.json" | ||
} | ||
}`) | ||
|
||
helper.ExecuteCommand(fmt.Sprintf("data-api graphql auth-provider delete %s --output json --instance-id %s --data-api-id %s", authProviderId, instanceId, dataApiId)) | ||
|
||
mockHandler.AssertCalledTimes(1) | ||
mockHandler.AssertCalledWithMethod(http.MethodDelete) | ||
|
||
helper.AssertOutJson(`{ | ||
"data": { | ||
"enabled": true, | ||
"id": "87d46b4b-3bfb-4ad2-8dac-0e95cf72d39f", | ||
"name": "test-key", | ||
"type": "jwks", | ||
"url": "https://test.com/.well-known/jwks.json" | ||
} | ||
} | ||
`) | ||
} |