Skip to content

Commit e84e0e5

Browse files
authored
chore: fix golangci-lint issues and switch to Dependabot (#421)
- Fix all golangci-lint errors and warnings - Add doc comments for all exported types and functions - Fix staticcheck deprecated field usage (Hetzner, Scaleway) - Fix gosec integer overflow warnings with nolint comments - Fix errcheck issues in update/server.go - Fix unused parameter warnings in OpenStack callbacks - Fix tagliatelle JSON tag naming in GCE credentials - Rename TemplateName to Name to avoid stuttering - Replace Renovate with Dependabot for dependency updates - Configure weekly updates for Go modules and GitHub Actions Signed-off-by: Engin Diri <engin.diri@ediri.de>
1 parent e9ba233 commit e84e0e5

File tree

25 files changed

+352
-152
lines changed

25 files changed

+352
-152
lines changed

.github/dependabot.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
day: "monday"
8+
labels:
9+
- "dependencies"
10+
commit-message:
11+
prefix: "chore(deps)"
12+
groups:
13+
go-dependencies:
14+
patterns:
15+
- "*"
16+
ignore:
17+
- dependency-name: "github.com/exoscale/egoscale"
18+
19+
- package-ecosystem: "github-actions"
20+
directory: "/"
21+
schedule:
22+
interval: "weekly"
23+
day: "monday"
24+
labels:
25+
- "dependencies"
26+
commit-message:
27+
prefix: "chore(deps)"
28+
groups:
29+
github-actions:
30+
patterns:
31+
- "*"

.github/renovate.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

automation/automation.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// Package automation provides interfaces for cloud automation operations.
12
package automation
23

34
import "github.com/dirien/minectl-sdk/model"
45

6+
// Automation defines the interface for cloud provider operations.
57
type Automation interface {
68
CreateServer(args ServerArgs) (*ResourceResults, error)
79
DeleteServer(id string, args ServerArgs) error
@@ -11,19 +13,22 @@ type Automation interface {
1113
GetServer(id string, args ServerArgs) (*ResourceResults, error)
1214
}
1315

16+
// Rcon represents RCON configuration for server management.
1417
type Rcon struct {
1518
Password string
1619
Enabled bool
1720
Port int
1821
Broadcast bool
1922
}
2023

24+
// ServerArgs contains arguments for server operations.
2125
type ServerArgs struct {
2226
ID string
2327
MinecraftResource *model.MinecraftResource
2428
SSHPrivateKeyPath string
2529
}
2630

31+
// ResourceResults contains the results of a server operation.
2732
type ResourceResults struct {
2833
ID string
2934
Name string

cloud/akamai/akamai.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package akamai implements the Automation interface for Akamai (formerly Linode) cloud provider.
12
package akamai
23

34
import (
@@ -19,11 +20,13 @@ import (
1920
"golang.org/x/oauth2"
2021
)
2122

23+
// Akamai implements the Automation interface for Akamai cloud provider.
2224
type Akamai struct {
2325
client linodego.Client
2426
tmpl *minctlTemplate.Template
2527
}
2628

29+
// NewAkamai creates a new Akamai instance.
2730
func NewAkamai(apiToken string) (*Akamai, error) {
2831
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: apiToken})
2932

@@ -45,6 +48,7 @@ func NewAkamai(apiToken string) (*Akamai, error) {
4548
return linode, nil
4649
}
4750

51+
// CreateServer creates a new Minecraft server on Akamai.
4852
func (l *Akamai) CreateServer(args automation.ServerArgs) (*automation.ResourceResults, error) {
4953
ubuntuImage := "linode/ubuntu22.04"
5054
publicKey, err := cloud.GetSSHPublicKey(args)
@@ -127,6 +131,7 @@ func (l *Akamai) CreateServer(args automation.ServerArgs) (*automation.ResourceR
127131
}, err
128132
}
129133

134+
// DeleteServer deletes a Minecraft server on Akamai.
130135
func (l *Akamai) DeleteServer(id string, args automation.ServerArgs) error {
131136
keys, err := l.client.ListSSHKeys(context.Background(), nil)
132137
if err != nil {
@@ -182,6 +187,7 @@ func (l *Akamai) DeleteServer(id string, args automation.ServerArgs) error {
182187
return nil
183188
}
184189

190+
// ListServer lists all Minecraft servers on Akamai.
185191
func (l *Akamai) ListServer() ([]automation.ResourceResults, error) {
186192
servers, err := l.client.ListInstances(context.Background(), linodego.NewListOptions(0, "{\"tags\":\"minectl\"}"))
187193
if err != nil {
@@ -200,6 +206,7 @@ func (l *Akamai) ListServer() ([]automation.ResourceResults, error) {
200206
return result, nil
201207
}
202208

209+
// UpdateServer updates a Minecraft server on Akamai.
203210
func (l *Akamai) UpdateServer(id string, args automation.ServerArgs) error {
204211
intID, _ := strconv.Atoi(id)
205212
instance, err := l.client.GetInstance(context.Background(), intID)
@@ -215,6 +222,7 @@ func (l *Akamai) UpdateServer(id string, args automation.ServerArgs) error {
215222
return nil
216223
}
217224

225+
// UploadPlugin uploads a plugin to a Minecraft server on Akamai.
218226
func (l *Akamai) UploadPlugin(id string, args automation.ServerArgs, plugin, destination string) error {
219227
intID, _ := strconv.Atoi(id)
220228
instance, err := l.client.GetInstance(context.Background(), intID)
@@ -234,7 +242,8 @@ func (l *Akamai) UploadPlugin(id string, args automation.ServerArgs, plugin, des
234242
return nil
235243
}
236244

237-
func (l *Akamai) GetServer(id string, args automation.ServerArgs) (*automation.ResourceResults, error) {
245+
// GetServer gets a Minecraft server on Akamai.
246+
func (l *Akamai) GetServer(id string, _ automation.ServerArgs) (*automation.ResourceResults, error) {
238247
intID, _ := strconv.Atoi(id)
239248
instance, err := l.client.GetInstance(context.Background(), intID)
240249
if err != nil {

cloud/aws/aws.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package aws implements the Automation interface for Amazon Web Services.
12
package aws
23

34
import (
@@ -25,6 +26,7 @@ import (
2526

2627
const instanceNameTag = "Name"
2728

29+
// Aws implements the Automation interface for AWS.
2830
type Aws struct {
2931
client *ec2.Client
3032
tmpl *minctlTemplate.Template
@@ -56,6 +58,7 @@ func NewAWS(region string) (*Aws, error) {
5658
}, err
5759
}
5860

61+
// ListServer lists all Minecraft servers on AWS.
5962
func (a *Aws) ListServer() ([]automation.ResourceResults, error) {
6063
ctx := context.TODO()
6164
var result []automation.ResourceResults
@@ -121,7 +124,7 @@ func addBlockDevice(volumeSize int) []types.BlockDeviceMapping {
121124
{
122125
DeviceName: aws.String("/dev/sda1"),
123126
Ebs: &types.EbsBlockDevice{
124-
VolumeSize: aws.Int32(int32(volumeSize)),
127+
VolumeSize: aws.Int32(int32(volumeSize)), //nolint:gosec // volumeSize is validated
125128
},
126129
},
127130
}
@@ -204,7 +207,6 @@ func addTagSpecifications(args automation.ServerArgs, resourceType types.Resourc
204207

205208
// CreateServer TODO: https://github.com/dirien/minectl/issues/298
206209
func (a *Aws) CreateServer(args automation.ServerArgs) (*automation.ResourceResults, error) { //nolint: gocyclo
207-
ctx := context.TODO()
208210
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
209211
defer cancel()
210212

@@ -434,6 +436,7 @@ func (a *Aws) CreateServer(args automation.ServerArgs) (*automation.ResourceResu
434436
}
435437
}
436438

439+
// UpdateServer updates a Minecraft server on AWS.
437440
func (a *Aws) UpdateServer(id string, args automation.ServerArgs) error {
438441
ctx := context.TODO()
439442
ids, _, _ := strings.Cut(id, "#")
@@ -453,6 +456,7 @@ func (a *Aws) UpdateServer(id string, args automation.ServerArgs) error {
453456
return nil
454457
}
455458

459+
// DeleteServer deletes a Minecraft server on AWS.
456460
func (a *Aws) DeleteServer(id string, args automation.ServerArgs) error {
457461
ctx := context.TODO()
458462

@@ -593,6 +597,7 @@ func (a *Aws) DeleteServer(id string, args automation.ServerArgs) error {
593597
return nil
594598
}
595599

600+
// UploadPlugin uploads a plugin to a Minecraft server on AWS.
596601
func (a *Aws) UploadPlugin(id string, args automation.ServerArgs, plugin, destination string) error {
597602
ctx := context.TODO()
598603
ids, _, _ := strings.Cut(id, "#")
@@ -618,6 +623,7 @@ func (a *Aws) UploadPlugin(id string, args automation.ServerArgs, plugin, destin
618623
return nil
619624
}
620625

626+
// GetServer gets a Minecraft server on AWS.
621627
func (a *Aws) GetServer(id string, _ automation.ServerArgs) (*automation.ResourceResults, error) {
622628
ctx := context.TODO()
623629
ids, _, _ := strings.Cut(id, "#")
@@ -685,9 +691,9 @@ func (a *Aws) createEC2SecurityGroup(ctx context.Context, vpcID *string, protoco
685691
func (a *Aws) createEC2SecurityGroupRule(ctx context.Context, groupID, protocol string, fromPort, toPort int) error {
686692
_, err := a.client.AuthorizeSecurityGroupIngress(ctx, &ec2.AuthorizeSecurityGroupIngressInput{
687693
CidrIp: aws.String("0.0.0.0/0"),
688-
FromPort: aws.Int32(int32(fromPort)),
694+
FromPort: aws.Int32(int32(fromPort)), //nolint:gosec // port numbers are safe
689695
IpProtocol: aws.String(protocol),
690-
ToPort: aws.Int32(int32(toPort)),
696+
ToPort: aws.Int32(int32(toPort)), //nolint:gosec // port numbers are safe
691697
GroupId: aws.String(groupID),
692698
})
693699
if err != nil {

cloud/azure/azure.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package azure implements the Automation interface for Azure cloud provider.
12
package azure
23

34
import (
@@ -21,6 +22,7 @@ import (
2122
"go.uber.org/zap"
2223
)
2324

25+
// Azure implements the Automation interface for Azure.
2426
type Azure struct {
2527
subscriptionID string
2628
credential *azidentity.DefaultAzureCredential
@@ -69,6 +71,7 @@ func getTagKeys(tags map[string]*string) []string {
6971
return keys
7072
}
7173

74+
// CreateServer creates a new Minecraft server on Azure.
7275
func (a *Azure) CreateServer(args automation.ServerArgs) (*automation.ResourceResults, error) {
7376
ctx := context.Background()
7477
resourceGroupsClient, err := armresources.NewResourceGroupsClient(a.subscriptionID, a.credential, nil)
@@ -201,7 +204,7 @@ func (a *Azure) CreateServer(args automation.ServerArgs) (*automation.ResourceRe
201204
CreationData: &armcompute.CreationData{
202205
CreateOption: to.Ptr(armcompute.DiskCreateOptionEmpty),
203206
},
204-
DiskSizeGB: to.Ptr(int32(args.MinecraftResource.GetVolumeSize())),
207+
DiskSizeGB: to.Ptr(int32(args.MinecraftResource.GetVolumeSize())), //nolint:gosec // volume size is validated
205208
},
206209
}, nil)
207210
if err != nil {
@@ -334,7 +337,8 @@ func (a *Azure) CreateServer(args automation.ServerArgs) (*automation.ResourceRe
334337
}, err
335338
}
336339

337-
func (a *Azure) DeleteServer(id string, args automation.ServerArgs) error {
340+
// DeleteServer deletes a Minecraft server on Azure.
341+
func (a *Azure) DeleteServer(_ string, args automation.ServerArgs) error {
338342
ctx := context.Background()
339343
resourceGroupName := fmt.Sprintf("%s-rg", args.MinecraftResource.GetName())
340344
resourceGroupsClient, err := armresources.NewResourceGroupsClient(a.subscriptionID, a.credential, nil)
@@ -357,6 +361,7 @@ func (a *Azure) DeleteServer(id string, args automation.ServerArgs) error {
357361
return nil
358362
}
359363

364+
// ListServer lists all Minecraft servers on Azure.
360365
func (a *Azure) ListServer() ([]automation.ResourceResults, error) {
361366
ctx := context.Background()
362367
virtualMachinesClient, err := armcompute.NewVirtualMachinesClient(a.subscriptionID, a.credential, nil)
@@ -405,6 +410,7 @@ func (a *Azure) ListServer() ([]automation.ResourceResults, error) {
405410
return result, nil
406411
}
407412

413+
// UpdateServer updates a Minecraft server on Azure.
408414
func (a *Azure) UpdateServer(id string, args automation.ServerArgs) error {
409415
server, err := a.GetServer(id, args)
410416
if err != nil {
@@ -419,6 +425,7 @@ func (a *Azure) UpdateServer(id string, args automation.ServerArgs) error {
419425
return nil
420426
}
421427

428+
// UploadPlugin uploads a plugin to a Minecraft server on Azure.
422429
func (a *Azure) UploadPlugin(id string, args automation.ServerArgs, plugin, destination string) error {
423430
server, err := a.GetServer(id, args)
424431
if err != nil {
@@ -440,6 +447,7 @@ func (a *Azure) UploadPlugin(id string, args automation.ServerArgs, plugin, dest
440447
return nil
441448
}
442449

450+
// GetServer gets a Minecraft server on Azure.
443451
func (a *Azure) GetServer(id string, args automation.ServerArgs) (*automation.ResourceResults, error) {
444452
virtualMachinesClient, err := armcompute.NewVirtualMachinesClient(a.subscriptionID, a.credential, nil)
445453
if err != nil {

cloud/civo/civo.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package civo implements the Automation interface for Civo cloud provider.
12
package civo
23

34
import (
@@ -15,11 +16,13 @@ import (
1516
"go.uber.org/zap"
1617
)
1718

19+
// Civo implements the Automation interface for Civo.
1820
type Civo struct {
1921
client *civogo.Client
2022
tmpl *minctlTemplate.Template
2123
}
2224

25+
// NewCivo creates a new Civo instance.
2326
func NewCivo(apiKey, region string) (*Civo, error) {
2427
client, err := civogo.NewClient(apiKey, region)
2528
if err != nil {
@@ -36,6 +39,7 @@ func NewCivo(apiKey, region string) (*Civo, error) {
3639
return do, nil
3740
}
3841

42+
// CreateServer creates a new Minecraft server on Civo.
3943
func (c *Civo) CreateServer(args automation.ServerArgs) (*automation.ResourceResults, error) {
4044
publicKey, err := cloud.GetSSHPublicKey(args)
4145
if err != nil {
@@ -148,6 +152,7 @@ func (c *Civo) CreateServer(args automation.ServerArgs) (*automation.ResourceRes
148152
}, err
149153
}
150154

155+
// DeleteServer deletes a Minecraft server on Civo.
151156
func (c *Civo) DeleteServer(id string, args automation.ServerArgs) error {
152157
_, err := c.client.DeleteInstance(id)
153158
if err != nil {
@@ -177,6 +182,7 @@ func (c *Civo) DeleteServer(id string, args automation.ServerArgs) error {
177182
return nil
178183
}
179184

185+
// ListServer lists all Minecraft servers on Civo.
180186
func (c *Civo) ListServer() ([]automation.ResourceResults, error) {
181187
var result []automation.ResourceResults
182188
instances, err := c.client.ListAllInstances()
@@ -210,6 +216,7 @@ func (c *Civo) ListServer() ([]automation.ResourceResults, error) {
210216
return result, nil
211217
}
212218

219+
// UpdateServer updates a Minecraft server on Civo.
213220
func (c *Civo) UpdateServer(id string, args automation.ServerArgs) error {
214221
instance, err := c.client.GetInstance(id)
215222
if err != nil {
@@ -225,6 +232,7 @@ func (c *Civo) UpdateServer(id string, args automation.ServerArgs) error {
225232
return nil
226233
}
227234

235+
// UploadPlugin uploads a plugin to a Minecraft server on Civo.
228236
func (c *Civo) UploadPlugin(id string, args automation.ServerArgs, plugin, destination string) error {
229237
instance, err := c.client.GetInstance(id)
230238
if err != nil {
@@ -244,6 +252,7 @@ func (c *Civo) UploadPlugin(id string, args automation.ServerArgs, plugin, desti
244252
return nil
245253
}
246254

255+
// GetServer gets a Minecraft server on Civo.
247256
func (c *Civo) GetServer(id string, _ automation.ServerArgs) (*automation.ResourceResults, error) {
248257
instance, err := c.client.GetInstance(id)
249258
if err != nil {

0 commit comments

Comments
 (0)