Skip to content

Commit

Permalink
refactor: remove unused var
Browse files Browse the repository at this point in the history
  • Loading branch information
deejiw committed Jun 6, 2023
1 parent 1452e7f commit 477e9c5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
12 changes: 7 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-fmt
- id: go-lint
- id: go-imports
- id: no-go-testing
- id: golangci-lint
- id: go-unit-tests
- id: go-mod-tidy
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ Then:
```javascript
import { Gcp } from 'k6/x/gcp';

const gcpClient = new Gcp()
const gcp = new Gcp({
scope: ['https://www.googleapis.com/auth/cloud-platform']
})
export default function() {
const accessToken = gcp.getOAuth2AccessToken()
}
```

## Command
GOOGLE_SERVICE_ACCOUNT_KEY=${GOOGLE_SERVICE_ACCOUNT_KEY} k6 run file.js
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/deejiw/xk6-gcp

go 1.19

// replace google.golang.org/grpc => github.com/grpc/grpc-go v1.51.0

require (
cloud.google.com/go/monitoring v1.13.0
github.com/dop251/goja v0.0.0-20230531210528-d7324b2d74f7
Expand Down
8 changes: 4 additions & 4 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ type (
}

Gcp struct {
vu modules.VU
// vu modules.VU
keyByte []byte
scope []string
}

GcpConfig struct {
Scope []string
scope []string
}

ServiceAccountKey struct {
Expand Down Expand Up @@ -90,15 +90,15 @@ func (mi *ModuleInstance) newGcp(c goja.ConstructorCall) *goja.Object {
err = rt.ExportTo(c.Argument(0), &options)
if err != nil {
common.Throw(rt,
fmt.Errorf("Gcp constructor expects Scope as it's argument: %w", err))
fmt.Errorf("Gcp constructor expects scope as it's argument: %w", err))
}

keyByte, _ := json.Marshal(key)

obj := &Gcp{
// vu: mi.vu,
keyByte: keyByte,
scope: options.Scope,
scope: options.scope,
}

return rt.ToValue(obj).ToObject(rt)
Expand Down
4 changes: 2 additions & 2 deletions monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"google.golang.org/api/option"
)

func (r *Gcp) QueryTimeSeries(projectId string, query string) ([]*monitoringpb.TimeSeriesData, error) {
func (g *Gcp) QueryTimeSeries(projectId string, query string) ([]*monitoringpb.TimeSeriesData, error) {
ctx := context.Background()

jwt, err := getJwtConfig(r.keyByte, r.scope)
jwt, err := getJwtConfig(g.keyByte, g.scope)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
// This function is a method of the `Gcp` struct and is used to obtain an OAuth2 access token for a
// given set of scopes. It takes in a variable number of scope strings as arguments and returns an
// `oauth2.Token` and an error.
func (r *Gcp) GetOAuth2AccessToken(scope []string) (*oauth2.Token, error) {
func (g *Gcp) GetOAuth2AccessToken(scope []string) (*oauth2.Token, error) {
ctx := context.Background()

if scope == nil {
scope = r.scope
scope = g.scope
}

jwt, err := getJwtConfig(r.keyByte, r.scope)
jwt, err := getJwtConfig(g.keyByte, g.scope)
if err != nil {
return nil, err
}
Expand All @@ -39,12 +39,12 @@ func (r *Gcp) GetOAuth2AccessToken(scope []string) (*oauth2.Token, error) {
// source with the specified scopes and uses it to obtain the ID token by calling the `Token` method on
// the token source. If there is an error obtaining the token source or the token itself, an error is
// returned.
func (r *Gcp) GetOAuth2IdToken(scope []string) (*oauth2.Token, error) {
func (g *Gcp) GetOAuth2IdToken(scope []string) (*oauth2.Token, error) {
if scope == nil {
scope = r.scope
scope = g.scope
}

ts, err := getTokenSource(r.keyByte, r.scope)
ts, err := getTokenSource(g.keyByte, g.scope)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 477e9c5

Please sign in to comment.