Skip to content

Commit

Permalink
chore: Address PR comemnts
Browse files Browse the repository at this point in the history
  • Loading branch information
bakjos committed Jul 4, 2022
1 parent e876028 commit 5069f27
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,19 @@ http_address: 0.0.0.0:8080
# tenant_id: TENANT_ID
# storage_account: STORAGE_ACCOUNT
# container_name: CONTAINER_NAME

# client secret credentials
# auth_method: client_secret
# client_id: APP_ID
# client_secret: APP_SECRET


# client certificate credentials
# auth_method: client_certificate
# cert_path: PATH_TO_CERTS FILE

# default and environment methods don't have any additional parameters
# auth_method: default/environment_credential

# If set to a valid port number, then serve /debug/pprof/* URLs here:
#profile_port: 7070
Expand Down
2 changes: 0 additions & 2 deletions cache/azblobproxy/auth_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const (
AuthMethodClientCertificate = "client_certificate"
AuthMethodClientSecret = "client_secret"
AuthMethodEnvironmentCredential = "environment_credential"
AuthMethodDeviceCode = "device_code"
AuthMethodDefault = "default"
)

Expand All @@ -13,7 +12,6 @@ func GetAuthMethods() []string {
AuthMethodClientCertificate,
AuthMethodClientSecret,
AuthMethodEnvironmentCredential,
AuthMethodDeviceCode,
AuthMethodDefault,
}
}
Expand Down
14 changes: 5 additions & 9 deletions cache/azblobproxy/azblobproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"context"
"errors"
"fmt"
"io"
"log"
"path"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/buchgr/bazel-remote/cache"
"github.com/buchgr/bazel-remote/cache/disk/casblob"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"io"
"log"
"path"
)

var (
Expand All @@ -31,7 +32,6 @@ type uploadReq struct {
size int64
kind cache.EntryKind
rc io.ReadCloser
cxt context.Context
}

type azBlobCache struct {
Expand All @@ -58,7 +58,6 @@ func (c *azBlobCache) Put(ctx context.Context, kind cache.EntryKind, hash string
size: size,
kind: kind,
rc: rc,
cxt: context.Background(),
}:
default:
c.errorLogger.Printf("too many uploads queued\n")
Expand All @@ -82,7 +81,6 @@ func (c *azBlobCache) Get(ctx context.Context, kind cache.EntryKind, hash string
resp, err := client.Download(context.Background(), nil)

if err != nil {

cacheMisses.Inc()
logResponse(c.accessLogger, "DOWNLOAD", c.storageAccount, c.container, key, err)
return nil, -1, err
Expand Down Expand Up @@ -131,7 +129,6 @@ func (c *azBlobCache) Contains(ctx context.Context, kind cache.EntryKind, hash s
logResponse(c.accessLogger, "CONTAINS", c.storageAccount, c.container, key, err)

return exists, size

}

func New(
Expand All @@ -142,7 +139,6 @@ func New(
storageMode string, accessLogger cache.Logger,
errorLogger cache.Logger, numUploaders, maxQueuedUploads int,
) cache.Proxy {

url := fmt.Sprintf("https://%s.blob.core.windows.net/", storageAccount)
serviceClient, err := azblob.NewServiceClient(url, creds, nil)
if err != nil {
Expand Down Expand Up @@ -207,7 +203,7 @@ func (c *azBlobCache) uploadFile(item uploadReq) {
return
}

_, err = client.Upload(item.cxt, item.rc.(io.ReadSeekCloser), nil)
_, err = client.Upload(context.Background(), item.rc.(io.ReadSeekCloser), nil)

logResponse(c.accessLogger, "UPLOAD", c.storageAccount, c.container, key, err)

Expand Down
7 changes: 3 additions & 4 deletions config/azblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package config

import (
"fmt"
"log"
"os"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/buchgr/bazel-remote/cache/azblobproxy"
"log"
"os"
)

type AzBlobStorageConfig struct {
Expand Down Expand Up @@ -35,7 +36,6 @@ func (azblobc AzBlobStorageConfig) GetCredentials() (azcore.TokenCredential, err
if err != nil {
return nil, fmt.Errorf(`failed to load certificate from "%s": %v`, azblobc.CertPath, err)
}

return azidentity.NewClientCertificateCredential(azblobc.TenantID, azblobc.ClientID, certs, key, nil)
} else if azblobc.AuthMethod == azblobproxy.AuthMethodClientSecret {
log.Println("AzBlob Credentials: using client secret credentials")
Expand All @@ -46,5 +46,4 @@ func (azblobc AzBlobStorageConfig) GetCredentials() (azcore.TokenCredential, err
}

return nil, fmt.Errorf("invalid azblob.auth_method: %s", azblobc.AuthMethod)

}
15 changes: 8 additions & 7 deletions utils/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package flags

import (
"fmt"
"github.com/buchgr/bazel-remote/cache/azblobproxy"

"math"
"strconv"
"strings"

"github.com/buchgr/bazel-remote/cache/azblobproxy"
"github.com/buchgr/bazel-remote/cache/s3proxy"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -283,28 +284,28 @@ func GetCliFlags() []cli.Flag {
&cli.StringFlag{
Name: "azblob.tenant_id",
Value: "",
Usage: "The AzBlob tenant id to use when using azblob proxy backend.",
Usage: "The AzBlob tenant id to use when using AzBlob proxy backend.",
EnvVars: []string{"BAZEL_REMOTE_AZBLOB_TENANT_ID", "AZURE_TENANT_ID"},
},

&cli.StringFlag{
Name: "azblob.storage_account",
Value: "",
Usage: "The AzBlob storage account to use when using azblob proxy backend.",
Usage: "The AzBlob storage account to use when using AzBlob proxy backend.",
EnvVars: []string{"BAZEL_REMOTE_AZBLOB_STORAGE_ACCOUNT"},
},

&cli.StringFlag{
Name: "azblob.container_name",
Value: "",
Usage: "The AzBlob container name to use when using azblob proxy backend.",
Usage: "The AzBlob container name to use when using AzBlob proxy backend.",
EnvVars: []string{"BAZEL_REMOTE_AZBLOB_CONTAINER_NAME"},
},

&cli.StringFlag{
Name: "azblob.prefix",
Value: "",
Usage: "The AZBLOB object prefix to use when using az blob proxy backend.",
Usage: "The AzBlob object prefix to use when using AzBlob proxy backend.",
EnvVars: []string{"BAZEL_REMOTE_AZBLOB_PREFIX"},
},
&cli.StringFlag{
Expand All @@ -322,13 +323,13 @@ func GetCliFlags() []cli.Flag {
&cli.StringFlag{
Name: "azblob.client_secret",
Value: "",
Usage: "The AzBlob cliensecret key to use when using S3 proxy backend. " + azBlobAuthMsg(azblobproxy.AuthMethodClientSecret),
Usage: "The AzBlob cliensecret key to use when using AzBlob proxy backend. " + azBlobAuthMsg(azblobproxy.AuthMethodClientSecret),
EnvVars: []string{"BAZEL_REMOTE_AZBLOB_SECRET_CLIENT_SECRET", "AZURE_CLIENT_SECRET"},
},
&cli.StringFlag{
Name: "azblob.cert_path",
Value: "",
Usage: "Path to the Certificates filefile. " + azBlobAuthMsg(azblobproxy.AuthMethodClientCertificate),
Usage: "Path to the certificates file. " + azBlobAuthMsg(azblobproxy.AuthMethodClientCertificate),
EnvVars: []string{"BAZEL_REMOTE_AZBLOB_CERT_PATH", "AZURE_CLIENT_CERTIFICATE_PATH"},
},

Expand Down

0 comments on commit 5069f27

Please sign in to comment.