Skip to content

Commit 104b65f

Browse files
chore: regenerate CLI from OpenAPI spec
1 parent e568bd4 commit 104b65f

16 files changed

Lines changed: 1420 additions & 86 deletions

client/client.gen.go

Lines changed: 988 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/agency_hosting/agency_hosting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package agency_hosting
33
import (
44
"github.com/hostinger/api-cli/cmd/agency_hosting/cache"
55
"github.com/hostinger/api-cli/cmd/agency_hosting/cron_jobs"
6+
"github.com/hostinger/api-cli/cmd/agency_hosting/databases"
67
"github.com/hostinger/api-cli/cmd/agency_hosting/datacenters"
78
"github.com/hostinger/api-cli/cmd/agency_hosting/domains"
89
"github.com/hostinger/api-cli/cmd/agency_hosting/files"
@@ -20,6 +21,7 @@ var GroupCmd = &cobra.Command{
2021
func init() {
2122
GroupCmd.AddCommand(cache.GroupCmd)
2223
GroupCmd.AddCommand(cron_jobs.GroupCmd)
24+
GroupCmd.AddCommand(databases.GroupCmd)
2325
GroupCmd.AddCommand(datacenters.GroupCmd)
2426
GroupCmd.AddCommand(domains.GroupCmd)
2527
GroupCmd.AddCommand(files.GroupCmd)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package databases
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"log"
8+
9+
"github.com/hostinger/api-cli/api"
10+
"github.com/hostinger/api-cli/output"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var CreatePlanWebsiteCmd = &cobra.Command{
15+
Use: "create-plan-website <website_uid>",
16+
Short: "Create Agency Plan website database",
17+
Long: "Creates a MySQL database with a dedicated user for an Agency Plan website.\n\nThe database name, username, and password must all be provided by the caller.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(1)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(createPlanWebsiteBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().AgencyHostingCreateAgencyPlanWebsiteDatabaseV1WithBodyWithResponse(context.TODO(), args[0], "application/json", bytes.NewReader(payload))
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
output.Format(cmd, r.Body, r.StatusCode())
30+
},
31+
}
32+
33+
func init() {
34+
CreatePlanWebsiteCmd.Flags().StringP("database-name", "", "", "Database name to create (alphanumeric characters).")
35+
CreatePlanWebsiteCmd.Flags().StringP("database-user", "", "", "Database username to create alongside the database (alphanumeric characters).")
36+
CreatePlanWebsiteCmd.Flags().StringP("password", "", "", "Password for the database user (requires mixed case, letters, and numbers).")
37+
CreatePlanWebsiteCmd.MarkFlagRequired("database-name")
38+
CreatePlanWebsiteCmd.MarkFlagRequired("database-user")
39+
CreatePlanWebsiteCmd.MarkFlagRequired("password")
40+
}
41+
42+
func createPlanWebsiteBody(cmd *cobra.Command) map[string]any {
43+
body := map[string]any{}
44+
databaseNameVal, _ := cmd.Flags().GetString("database-name")
45+
body["database_name"] = databaseNameVal
46+
databaseUserVal, _ := cmd.Flags().GetString("database-user")
47+
body["database_user"] = databaseUserVal
48+
passwordVal, _ := cmd.Flags().GetString("password")
49+
body["password"] = passwordVal
50+
return body
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package databases
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"log"
8+
9+
"github.com/hostinger/api-cli/api"
10+
"github.com/hostinger/api-cli/output"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var CreatePlanWebsiteUserCmd = &cobra.Command{
15+
Use: "create-plan-website-user <website_uid> <database_name>",
16+
Short: "Create Agency Plan website database user",
17+
Long: "Creates a user for an existing database on an Agency Plan website.\n\nEach database supports a single non-system user; creating a user for a database that already has one fails.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(createPlanWebsiteUserBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().AgencyHostingCreateAgencyPlanWebsiteDatabaseUserV1WithBodyWithResponse(context.TODO(), args[0], args[1], "application/json", bytes.NewReader(payload))
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
output.Format(cmd, r.Body, r.StatusCode())
30+
},
31+
}
32+
33+
func init() {
34+
CreatePlanWebsiteUserCmd.Flags().StringP("database-user", "", "", "Database username to create (alphanumeric and underscores).")
35+
CreatePlanWebsiteUserCmd.Flags().StringP("host", "", "", "Host the user connects from (IPv4, IPv6, % wildcard, or localhost). Defaults to localhost.")
36+
CreatePlanWebsiteUserCmd.Flags().StringP("password", "", "", "Password for the database user (requires mixed case, letters, and numbers).")
37+
CreatePlanWebsiteUserCmd.MarkFlagRequired("database-user")
38+
CreatePlanWebsiteUserCmd.MarkFlagRequired("password")
39+
}
40+
41+
func createPlanWebsiteUserBody(cmd *cobra.Command) map[string]any {
42+
body := map[string]any{}
43+
databaseUserVal, _ := cmd.Flags().GetString("database-user")
44+
body["database_user"] = databaseUserVal
45+
if cmd.Flags().Changed("host") {
46+
v, _ := cmd.Flags().GetString("host")
47+
body["host"] = v
48+
}
49+
passwordVal, _ := cmd.Flags().GetString("password")
50+
body["password"] = passwordVal
51+
return body
52+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package databases
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var GroupCmd = &cobra.Command{
8+
Use: "databases",
9+
Short: "Databases commands",
10+
}
11+
12+
func init() {
13+
GroupCmd.AddCommand(CreatePlanWebsiteCmd)
14+
GroupCmd.AddCommand(CreatePlanWebsiteUserCmd)
15+
GroupCmd.AddCommand(DeletePlanWebsiteCmd)
16+
GroupCmd.AddCommand(DeletePlanWebsiteUserCmd)
17+
GroupCmd.AddCommand(ListPlanWebsiteCmd)
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package databases
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/output"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var DeletePlanWebsiteCmd = &cobra.Command{
13+
Use: "delete-plan-website <website_uid> <database_name>",
14+
Short: "Delete Agency Plan website database",
15+
Long: "Permanently deletes a MySQL database and all its data from an Agency Plan website, including its users.\n\nThe operation is idempotent: deleting a database that does not exist succeeds without error.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().AgencyHostingDeleteAgencyPlanWebsiteDatabaseV1WithResponse(context.TODO(), args[0], args[1])
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package databases
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/output"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var DeletePlanWebsiteUserCmd = &cobra.Command{
13+
Use: "delete-plan-website-user <website_uid> <database_name> <database_user_name>",
14+
Short: "Delete Agency Plan website database user",
15+
Long: "Permanently deletes a database user from an Agency Plan website database, revoking all access it had.\n\nThe operation is idempotent: deleting a user that does not exist succeeds without error.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(3)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().AgencyHostingDeleteAgencyPlanWebsiteDatabaseUserV1WithResponse(context.TODO(), args[0], args[1], args[2])
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package databases
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/client"
9+
"github.com/hostinger/api-cli/output"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var ListPlanWebsiteCmd = &cobra.Command{
14+
Use: "list-plan-website <website_uid>",
15+
Short: "List Agency Plan website databases",
16+
Long: "Returns a paginated list of MySQL databases created for an Agency Plan website.\n\nEach entry includes the database's non-system users.",
17+
Args: cobra.MatchAll(cobra.ExactArgs(1)),
18+
Run: func(cmd *cobra.Command, args []string) {
19+
r, err := api.Request().AgencyHostingListAgencyPlanWebsiteDatabasesV1WithResponse(context.TODO(), args[0], listPlanWebsiteParams(cmd))
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
24+
output.Format(cmd, r.Body, r.StatusCode())
25+
},
26+
}
27+
28+
func init() {
29+
ListPlanWebsiteCmd.Flags().IntP("page", "", 0, "Page number")
30+
ListPlanWebsiteCmd.Flags().IntP("per-page", "", 25, "Number of items per page")
31+
}
32+
33+
func listPlanWebsiteParams(cmd *cobra.Command) *client.AgencyHostingListAgencyPlanWebsiteDatabasesV1Params {
34+
params := &client.AgencyHostingListAgencyPlanWebsiteDatabasesV1Params{}
35+
if cmd.Flags().Changed("page") {
36+
v, _ := cmd.Flags().GetInt("page")
37+
params.Page = &v
38+
}
39+
if cmd.Flags().Changed("per-page") {
40+
v, _ := cmd.Flags().GetInt("per-page")
41+
params.PerPage = &v
42+
}
43+
return params
44+
}

docs/hostinger_agency-hosting.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Agency Hosting commands
2020
* [hostinger](hostinger.md) - Hostinger API Command Line Interface
2121
* [hostinger agency-hosting cache](hostinger_agency-hosting_cache.md) - Cache commands
2222
* [hostinger agency-hosting cron-jobs](hostinger_agency-hosting_cron-jobs.md) - Cron Jobs commands
23+
* [hostinger agency-hosting databases](hostinger_agency-hosting_databases.md) - Databases commands
2324
* [hostinger agency-hosting datacenters](hostinger_agency-hosting_datacenters.md) - Datacenters commands
2425
* [hostinger agency-hosting domains](hostinger_agency-hosting_domains.md) - Domains commands
2526
* [hostinger agency-hosting files](hostinger_agency-hosting_files.md) - Files commands
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## hostinger agency-hosting databases
2+
3+
Databases commands
4+
5+
### Options
6+
7+
```
8+
-h, --help help for databases
9+
```
10+
11+
### Options inherited from parent commands
12+
13+
```
14+
--config string Config file (default is $HOME/.hostinger.yaml)
15+
--format string Output format type (json|table|tree), default: table
16+
```
17+
18+
### SEE ALSO
19+
20+
* [hostinger agency-hosting](hostinger_agency-hosting.md) - Agency Hosting commands
21+
* [hostinger agency-hosting databases create-plan-website](hostinger_agency-hosting_databases_create-plan-website.md) - Create Agency Plan website database
22+
* [hostinger agency-hosting databases create-plan-website-user](hostinger_agency-hosting_databases_create-plan-website-user.md) - Create Agency Plan website database user
23+
* [hostinger agency-hosting databases delete-plan-website](hostinger_agency-hosting_databases_delete-plan-website.md) - Delete Agency Plan website database
24+
* [hostinger agency-hosting databases delete-plan-website-user](hostinger_agency-hosting_databases_delete-plan-website-user.md) - Delete Agency Plan website database user
25+
* [hostinger agency-hosting databases list-plan-website](hostinger_agency-hosting_databases_list-plan-website.md) - List Agency Plan website databases
26+

0 commit comments

Comments
 (0)