Skip to content

Commit 3a5e3aa

Browse files
committed
feat: first commit
0 parents  commit 3a5e3aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+16114
-0
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "gomod"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/hapi

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @hostinger/vps-team-dev

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright © 2025 Hostinger <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

api/request.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package api
2+
3+
import (
4+
"github.com/hostinger/api-cli/client"
5+
"github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider"
6+
"github.com/spf13/viper"
7+
"log"
8+
)
9+
10+
func Request() client.ClientWithResponsesInterface {
11+
bearerToken, err := securityprovider.NewSecurityProviderBearerToken(viper.GetString("api_token"))
12+
if err != nil {
13+
panic(err)
14+
}
15+
16+
var apiUrl = viper.GetString("api_url")
17+
if apiUrl == "" {
18+
apiUrl = "https://developers.hostinger.com"
19+
}
20+
21+
c, err := client.NewClientWithResponses(apiUrl, client.WithRequestEditorFn(bearerToken.Intercept))
22+
if err != nil {
23+
log.Fatal(err)
24+
}
25+
26+
return c
27+
}

client/cfg.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package: client
2+
output: client.gen.go
3+
generate:
4+
models: true
5+
client: true

client/client.gen.go

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

client/generate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package client
2+
3+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml https://raw.githubusercontent.com/hostinger/api/refs/heads/main/openapi.json

cmd/root.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/hostinger/api-cli/cmd/vps"
6+
"os"
7+
8+
"github.com/spf13/cobra"
9+
"github.com/spf13/viper"
10+
)
11+
12+
var cfgFile string
13+
14+
var (
15+
OutputFormat string
16+
validFormats = []string{"json", "table", "tree"}
17+
)
18+
19+
var RootCmd = &cobra.Command{
20+
Use: "hapi",
21+
Short: "Hostinger API Command Line Interface",
22+
Long: ``,
23+
}
24+
25+
// Execute adds all child commands to the root command and sets flags appropriately.
26+
// This is called by main.main(). It only needs to happen once to the rootCmd.
27+
func Execute() {
28+
err := RootCmd.Execute()
29+
if err != nil {
30+
os.Exit(1)
31+
}
32+
}
33+
34+
func init() {
35+
cobra.OnInitialize(initConfig)
36+
37+
RootCmd.DisableAutoGenTag = true
38+
39+
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "Config file (default is $HOME/.hapi.yaml)")
40+
RootCmd.PersistentFlags().StringVar(&OutputFormat, "format", "", "Output format type (json|table|tree), default: table")
41+
42+
RootCmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
43+
return validFormats, cobra.ShellCompDirectiveNoFileComp
44+
})
45+
46+
RootCmd.AddCommand(vps.VpsGroupCmd)
47+
}
48+
49+
func initConfig() {
50+
if cfgFile != "" {
51+
viper.SetConfigFile(cfgFile)
52+
} else {
53+
home, err := os.UserHomeDir()
54+
cobra.CheckErr(err)
55+
56+
viper.AddConfigPath(home)
57+
viper.SetConfigType("yaml")
58+
viper.SetConfigName(".hapi")
59+
}
60+
61+
viper.AutomaticEnv() // read in environment variables that match
62+
if err := viper.ReadInConfig(); err == nil {
63+
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
64+
}
65+
}

cmd/vps/actions/actions.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package actions
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var GroupCmd = &cobra.Command{
8+
Use: "actions",
9+
Short: "VM actions information",
10+
Long: `Track and review operations performed on your virtual machines. These endpoints provide details about specific actions—such as start, stop, or restart—including timestamps and statuses.`,
11+
}
12+
13+
func init() {
14+
GroupCmd.AddCommand(GetCmd)
15+
GroupCmd.AddCommand(ListCmd)
16+
}

0 commit comments

Comments
 (0)