Skip to content

Commit 10e14dc

Browse files
committed
feat: add ability to check if an app exists
1 parent cd4d721 commit 10e14dc

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ List all apps
3535
dds-client apps:list
3636
```
3737

38+
#### `apps:exists`
39+
40+
Check if an app exists
41+
42+
```shell
43+
dds-client apps:exists --name dopsa
44+
```
45+
3846
#### `apps:create`
3947

4048
Create an app

main.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,42 @@ func basicAuth(username, password string) string {
5555
return base64.StdEncoding.EncodeToString([]byte(auth))
5656
}
5757

58+
func appExists(name string) {
59+
req := graphql.NewRequest(`
60+
query apps($name: String!, $allApps: Boolean!) {
61+
apps(name: $name, allApps: $allApps) {
62+
apps {
63+
name
64+
}
65+
}
66+
}
67+
`)
68+
69+
req.Var("allApps", false)
70+
req.Var("name", name)
71+
72+
req.Header.Set("Cache-Control", "no-cache")
73+
req.Header.Set("Authorization", "Basic "+basicAuth(Username, ApiKey))
74+
75+
ctx := context.Background()
76+
77+
var respData AppsResponse
78+
79+
client, err := graphqlClient()
80+
if err != nil {
81+
log.Fatal(err)
82+
}
83+
if err := client.Run(ctx, req, &respData); err != nil {
84+
log.Fatal(err)
85+
}
86+
for _, app := range respData.AppsWrapper.Apps {
87+
fmt.Printf("%v exists\n", app.Name)
88+
os.Exit(0)
89+
}
90+
fmt.Printf("%v does not exist\n", name)
91+
os.Exit(1)
92+
}
93+
5894
func appsList() {
5995
req := graphql.NewRequest(`
6096
query apps($page: Int!, $allApps: Boolean!) {
@@ -218,6 +254,7 @@ func main() {
218254
appsListCmd := parser.NewCommand("apps:list", "List all apps")
219255
appsCreateCmd := parser.NewCommand("apps:create", "Create an app")
220256
appsDeleteCmd := parser.NewCommand("apps:delete", "Delete an app")
257+
appExistsCmd := parser.NewCommand("apps:exists", "Check if an app exists")
221258
err := parser.Parse(os.Args)
222259
if err != nil {
223260
fmt.Print(parser.Usage(err))
@@ -230,6 +267,8 @@ func main() {
230267
appsCreate(*name)
231268
} else if appsDeleteCmd.Happened() {
232269
appsDelete(*name)
270+
} else if appExistsCmd.Happened() {
271+
appExists(*name)
233272
} else {
234273
err := fmt.Errorf("bad arguments, please check usage")
235274
fmt.Print(parser.Usage(err))

0 commit comments

Comments
 (0)