Skip to content

Commit

Permalink
Merge pull request #338 from DataDog/paulcacheux/cos-https
Browse files Browse the repository at this point in the history
replace google cloud storage lib by a direct https get
  • Loading branch information
paulcacheux authored Oct 11, 2024
2 parents 52c8328 + 8d245dc commit 61e121e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 166 deletions.
40 changes: 22 additions & 18 deletions cos/cos.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
package cos

import (
"context"
"errors"
"fmt"
"net/http"
"net/url"

"cloud.google.com/go/storage"
"github.com/DataDog/nikos/extract"
"github.com/DataDog/nikos/types"
"google.golang.org/api/option"
)

type Backend struct {
buildID string
logger types.Logger
client *storage.Client
}

const (
kernelHeadersFilename = "kernel-headers.tgz"
bucketName = "cos-tools"
)

func (b *Backend) GetKernelHeaders(directory string) error {
filename := "kernel-headers.tgz"
bucketHandle := b.client.Bucket("cos-tools")
objectHandle := bucketHandle.Object(b.buildID + "/" + filename)
reader, err := objectHandle.NewReader(context.Background())
objectName := url.QueryEscape(fmt.Sprintf("%s/%s", b.buildID, kernelHeadersFilename))
url := fmt.Sprintf("https://storage.googleapis.com/download/storage/v1/b/%s/o/%s?alt=media", bucketName, objectName)

resp, err := http.Get(url)
if err != nil {
return fmt.Errorf("failed to download bucket object: %w", err)
return fmt.Errorf("failed to start download kernel headers from COS bucket: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download kernel headers from COS bucket: %s", resp.Status)
}
defer reader.Close()

extract.ExtractTarball(reader, filename, directory, b.logger)
return err
if err := extract.ExtractTarball(resp.Body, kernelHeadersFilename, directory, b.logger); err != nil {
return fmt.Errorf("failed to extract kernel headers: %w", err)
}

return nil
}

func (b *Backend) Close() {}
Expand All @@ -39,13 +49,7 @@ func NewBackend(target *types.Target, logger types.Logger) (*Backend, error) {
return nil, errors.New("failed to detect COS version, missing BUILD_ID in /etc/os-release")
}

client, err := storage.NewClient(context.Background(), option.WithoutAuthentication())
if err != nil {
return nil, fmt.Errorf("failed to creating COS backend: %w", err)
}

return &Backend{
client: client,
logger: logger,
buildID: buildID,
}, nil
Expand Down
45 changes: 2 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/DataDog/nikos
go 1.21

require (
cloud.google.com/go/storage v1.44.0
github.com/DataDog/aptly v1.5.3
github.com/DataDog/gopsutil v1.2.2
github.com/acobaugh/osrelease v0.1.0
Expand All @@ -18,53 +17,31 @@ require (
github.com/xor-gate/ar v0.0.0-20170530204233-5c72ae81e2b7
golang.org/x/crypto v0.28.0
golang.org/x/sys v0.26.0
google.golang.org/api v0.199.0
gopkg.in/ini.v1 v1.67.0
)

require (
cel.dev/expr v0.16.1 // indirect
cloud.google.com/go v0.115.1 // indirect
cloud.google.com/go/auth v0.9.5 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/compute/metadata v0.5.2 // indirect
cloud.google.com/go/iam v1.2.1 // indirect
cloud.google.com/go/monitoring v1.21.0 // indirect
github.com/AlekSi/pointer v1.2.0 // indirect
github.com/DataDog/zstd v1.5.6 // indirect
github.com/DisposaBoy/JsonConfigReader v0.0.0-20201129172854-99cf318d67e7 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.1 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.1 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/awalterschulze/gographviz v2.0.3+incompatible // indirect
github.com/cavaliergopher/grab/v3 v3.0.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/envoyproxy/go-control-plane v0.13.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jlaffaye/ftp v0.1.0 // indirect
github.com/kjk/lzma v0.0.0-20161016003348-3fd93898850d // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
Expand All @@ -73,9 +50,9 @@ require (
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/rs/zerolog v1.28.0 // indirect
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
Expand All @@ -88,26 +65,8 @@ require (
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.67.0 // indirect
google.golang.org/grpc/stats/opentelemetry v0.0.0-20240907200651-3ffb98b2c93a // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 61e121e

Please sign in to comment.