Skip to content

Commit

Permalink
Delete unused mocks, rename variables and fix imports
Browse files Browse the repository at this point in the history
They were not needed anymore and the linter was complaining.
  • Loading branch information
tobias-hashicorp committed Oct 26, 2023
1 parent f5ee73b commit 74903bf
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 63 deletions.
42 changes: 0 additions & 42 deletions auth/mock.go

This file was deleted.

11 changes: 6 additions & 5 deletions auth/tokencache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package tokencache
import (
"encoding/json"
"fmt"
"golang.org/x/oauth2"
"os"
"path"
"time"

"golang.org/x/oauth2"
)

// cache is used to (un-)marshal the cached tokens from/to JSON.
Expand All @@ -32,13 +33,13 @@ func readCache(cacheFile string) (*cache, error) {
}

// Read the cache information from the file, if it exists
cacheJson, err := os.ReadFile(cacheFile)
cacheJSON, err := os.ReadFile(cacheFile)
if err != nil {
return cachedTokens, fmt.Errorf("failed to read credentials cache from %q: %w", cacheFile, err)
}

// Unmarshal the cached credentials
if err = json.Unmarshal(cacheJson, cachedTokens); err != nil {
if err = json.Unmarshal(cacheJSON, cachedTokens); err != nil {
return cachedTokens, fmt.Errorf("failed to unmarshal cached credentials: %w", err)
}

Expand All @@ -51,7 +52,7 @@ func readCache(cacheFile string) (*cache, error) {
// future (e.g. by -re-reading the content before writing, locking the file or writing cache information to multiple files).
func (c *cache) write(cacheFile string) error {
// Marshal the new tokens
cacheJson, err := json.Marshal(c)
cacheJSON, err := json.Marshal(c)
if err != nil {
return fmt.Errorf("failed to marshal cached tokens: %w", err)
}
Expand All @@ -63,7 +64,7 @@ func (c *cache) write(cacheFile string) error {
}

// Write the file
err = os.WriteFile(cacheFile, cacheJson, os.FileMode(0600))
err = os.WriteFile(cacheFile, cacheJSON, os.FileMode(0600))
if err != nil {
return fmt.Errorf("failed to write cached credentials to file: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion auth/tokencache/cache_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tokencache

import (
"github.com/stretchr/testify/require"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestCache_ExpiredTokenRemoval(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion auth/tokencache/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package tokencache

import (
"fmt"
"golang.org/x/oauth2"
"log"

"golang.org/x/oauth2"
)

// NewLoginTokenSource will create a token source that caches login tokens. Only one login token will be cached at a
Expand Down
1 change: 1 addition & 0 deletions auth/tokencache/oauth2config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tokencache

import (
"context"

"golang.org/x/oauth2"
)

Expand Down
3 changes: 2 additions & 1 deletion auth/tokencache/serviceprincipal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package tokencache

import (
"fmt"
"golang.org/x/oauth2"
"log"

"golang.org/x/oauth2"
)

const sourceTypeServicePrincipal = sourceType("service-principal")
Expand Down
3 changes: 2 additions & 1 deletion auth/tokencache/tokensource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package tokencache
import (
"context"
"fmt"
"golang.org/x/oauth2"
"log"
"time"

"golang.org/x/oauth2"
)

// sourceType identities the type of token source.
Expand Down
5 changes: 3 additions & 2 deletions auth/tokencache/tokensource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package tokencache
import (
"context"
"fmt"
requirepkg "github.com/stretchr/testify/require"
"golang.org/x/oauth2"
"os"
"path"
"testing"
"time"

requirepkg "github.com/stretchr/testify/require"
"golang.org/x/oauth2"
)

type testTokenSource struct {
Expand Down
3 changes: 2 additions & 1 deletion auth/tokencache/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package tokencache

import (
"fmt"
"golang.org/x/oauth2"
"log"

"golang.org/x/oauth2"
)

const sourceTypeWorkload = sourceType("workload")
Expand Down
3 changes: 2 additions & 1 deletion config/hcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package config
import (
"crypto/tls"
"fmt"
"github.com/hashicorp/hcp-sdk-go/auth/workload"
"net/url"

"github.com/hashicorp/hcp-sdk-go/auth/workload"

"github.com/hashicorp/hcp-sdk-go/auth"
"github.com/hashicorp/hcp-sdk-go/profile"
"golang.org/x/oauth2"
Expand Down
5 changes: 3 additions & 2 deletions config/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ package config
import (
"crypto/tls"
"fmt"
"github.com/hashicorp/hcp-sdk-go/profile"
"golang.org/x/oauth2"
"io"
"log"
"net/url"

"github.com/hashicorp/hcp-sdk-go/profile"
"golang.org/x/oauth2"
)

const (
Expand Down
9 changes: 5 additions & 4 deletions config/tokensource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package config
import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"path"

"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/hcp-sdk-go/auth"
"github.com/hashicorp/hcp-sdk-go/auth/tokencache"
"github.com/hashicorp/hcp-sdk-go/auth/workload"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
"net/http"
"net/url"
"os"
"path"
)

type sourceType = string
Expand Down
5 changes: 3 additions & 2 deletions config/tokensource_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package config

import (
"io/ioutil"
"testing"

"github.com/hashicorp/hcp-sdk-go/auth"
"github.com/hashicorp/hcp-sdk-go/auth/workload"
requirepkg "github.com/stretchr/testify/require"
"io/ioutil"
"testing"
)

func TestTokenSource_GetTokenSource_WithClientCredentials(t *testing.T) {
Expand Down

0 comments on commit 74903bf

Please sign in to comment.