Skip to content

Commit

Permalink
Remove unused code (from Fleet's sandbox implementation) (#26645)
Browse files Browse the repository at this point in the history
Removing unused code and APIs (these APIs and code were used by "Fleet
Sandbox" which doesn't exist anymore).
  • Loading branch information
lucasmrod authored Feb 27, 2025
1 parent 67b7276 commit df5461c
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 689 deletions.
10 changes: 0 additions & 10 deletions cmd/fleet/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ the way that the Fleet server works.

var ds fleet.Datastore
var carveStore fleet.CarveStore
var installerStore fleet.InstallerStore

opts := []mysql.DBOption{mysql.Logger(logger), mysql.WithFleetConfig(&config)}
if config.MysqlReadReplica.Address != "" {
Expand Down Expand Up @@ -221,14 +220,6 @@ the way that the Fleet server works.
carveStore = ds
}

if config.Packaging.S3.Bucket != "" {
var err error
installerStore, err = s3.NewInstallerStore(config.Packaging.S3)
if err != nil {
initFatal(err, "initializing S3 installer store")
}
}

migrationStatus, err := ds.MigrationStatus(cmd.Context())
if err != nil {
initFatal(err, "retrieving migration status")
Expand Down Expand Up @@ -733,7 +724,6 @@ the way that the Fleet server works.
ssoSessionStore,
liveQueryStore,
carveStore,
installerStore,
failingPolicySet,
geoIP,
redisWrapperDS,
Expand Down
67 changes: 0 additions & 67 deletions docs/Contributing/API-for-contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3851,73 +3851,6 @@ Body: <blob>

---

## Downloadable installers

These API routes are used by the UI in Fleet Sandbox.

- [Download an installer](#download-an-installer)
- [Check if an installer exists](#check-if-an-installer-exists)

### Download an installer

Downloads a pre-built fleet-osquery installer with the given parameters.

`POST /api/v1/fleet/download_installer/{kind}`

#### Parameters

| Name | Type | In | Description |
| ------------- | ------- | --------------------- | ------------------------------------------------------------------ |
| kind | string | path | The installer kind: pkg, msi, deb or rpm. |
| enroll_secret | string | x-www-form-urlencoded | The global enroll secret. |
| token | string | x-www-form-urlencoded | The authentication token. |
| desktop | boolean | x-www-form-urlencoded | Set to `true` to ask for an installer that includes Fleet Desktop. |

##### Default response

```http
Status: 200
Content-Type: application/octet-stream
Content-Disposition: attachment
Content-Length: <length>
Body: <blob>
```

If an installer with the provided parameters is found, the installer is returned as a binary blob in the body of the response.

##### Installer doesn't exist

`Status: 400`

This error occurs if an installer with the provided parameters doesn't exist.


### Check if an installer exists

Checks if a pre-built fleet-osquery installer with the given parameters exists.

`HEAD /api/v1/fleet/download_installer/{kind}`

#### Parameters

| Name | Type | In | Description |
| ------------- | ------- | ----- | ------------------------------------------------------------------ |
| kind | string | path | The installer kind: pkg, msi, deb or rpm. |
| enroll_secret | string | query | The global enroll secret. |
| desktop | boolean | query | Set to `true` to ask for an installer that includes Fleet Desktop. |

##### Default response

`Status: 200`

If an installer with the provided parameters is found.

##### Installer doesn't exist

`Status: 400`

If an installer with the provided parameters doesn't exist.

## Setup

Sets up a new Fleet instance with the given parameters.
Expand Down
1 change: 0 additions & 1 deletion ee/server/service/mdm_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func setupMockDatastorePremiumService(t testing.TB) (*mock.Store, *eeservice.Ser
nil,
ds,
nil,
nil,
&fleet.NoOpGeoIP{},
nil,
depStorage,
Expand Down
102 changes: 0 additions & 102 deletions server/datastore/s3/installer.go

This file was deleted.

75 changes: 0 additions & 75 deletions server/datastore/s3/installer_test.go

This file was deleted.

13 changes: 13 additions & 0 deletions server/datastore/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/fleetdm/fleet/v4/server/config"
"github.com/fleetdm/fleet/v4/server/fleet"
)

const awsRegionHint = "us-east-1"
Expand All @@ -23,6 +24,18 @@ type s3store struct {
cloudFrontConfig *config.S3CloudFrontConfig
}

type installerNotFoundError struct{}

var _ fleet.NotFoundError = (*installerNotFoundError)(nil)

func (p installerNotFoundError) Error() string {
return "installer not found"
}

func (p installerNotFoundError) IsNotFound() bool {
return true
}

// newS3store initializes an S3 Datastore
func newS3store(config config.S3ConfigInternal) (*s3store, error) {
conf := &aws.Config{}
Expand Down
50 changes: 3 additions & 47 deletions server/datastore/s3/testing_utils.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package s3

import (
"context"
"os"
"strings"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/fleetdm/fleet/v4/server/config"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/stretchr/testify/require"
)

const (
accessKeyID = "minio"
secretAccessKey = "minio123!"
testEndpoint = "localhost:9000"
mockInstallerContents = "mock"
accessKeyID = "minio"
secretAccessKey = "minio123!"
testEndpoint = "localhost:9000"
)

func SetupTestSoftwareInstallerStore(tb testing.TB, bucket, prefix string) *SoftwareInstallerStore {
Expand All @@ -33,14 +28,6 @@ func SetupTestBootstrapPackageStore(tb testing.TB, bucket, prefix string) *Boots
return store
}

// SetupTestInstallerStore creates a new store with minio as a back-end
// for local testing
func SetupTestInstallerStore(tb testing.TB, bucket, prefix string) *InstallerStore {
store := setupTestStore(tb, bucket, prefix, NewInstallerStore)
tb.Cleanup(func() { cleanupStore(tb, store.s3store) })
return store
}

type testBucketCreator interface {
CreateTestBucket(name string) error
}
Expand Down Expand Up @@ -75,37 +62,6 @@ func setupTestStore[T testBucketCreator](tb testing.TB, bucket, prefix string, n
return store
}

// SeedTestInstallerStore adds mock installers to the given store
func SeedTestInstallerStore(tb testing.TB, store *InstallerStore, enrollSecret string) []fleet.Installer {
checkEnv(tb)
installers := []fleet.Installer{
mockInstaller(enrollSecret, "pkg", true),
mockInstaller(enrollSecret, "msi", true),
mockInstaller(enrollSecret, "deb", true),
mockInstaller(enrollSecret, "rpm", true),
mockInstaller(enrollSecret, "pkg", false),
mockInstaller(enrollSecret, "msi", false),
mockInstaller(enrollSecret, "deb", false),
mockInstaller(enrollSecret, "rpm", false),
}

for _, i := range installers {
_, err := store.Put(context.Background(), i)
require.NoError(tb, err)
}

return installers
}

func mockInstaller(secret, kind string, desktop bool) fleet.Installer {
return fleet.Installer{
EnrollSecret: secret,
Kind: kind,
Desktop: desktop,
Content: aws.ReadSeekCloser(strings.NewReader(mockInstallerContents)),
}
}

func cleanupStore(tb testing.TB, store *s3store) {
checkEnv(tb)

Expand Down
Loading

0 comments on commit df5461c

Please sign in to comment.