Skip to content

Commit

Permalink
Merge pull request #386 from rollbar/pawel/update_packages
Browse files Browse the repository at this point in the history
update packages
  • Loading branch information
pawelsz-rb authored Feb 29, 2024
2 parents ab4f635 + f097dfe commit c2128ac
Show file tree
Hide file tree
Showing 48 changed files with 1,219 additions and 2,093 deletions.
108 changes: 101 additions & 7 deletions .github/workflows/acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:

jobs:

acceptance_tests:
name: Acceptance
acceptance_tests_client:
name: Acceptance Client
runs-on: ubuntu-latest

env:
Expand Down Expand Up @@ -42,25 +42,119 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Run acceptance tests
- name: Acceptance tests
run: make testacc
- name: Acceptance tests client
run: make testacc_client
env:
TERRAFORM_PROVIDER_ROLLBAR_DEBUG: 1
GOMAXPROCS: 8

# Report code coverage
- name: Convert Go coverage file to lcov format
run: |
go get github.com/jandelgado/gcov2lcov
~/go/bin/gcov2lcov -infile coverage.out -outfile lcov.info
go install github.com/jandelgado/gcov2lcov
~/go/bin/gcov2lcov -infile coverage_client.out -outfile lcov_client.info
- uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov.info
path-to-lcov: ./lcov_client.info
- name: Upload coverage data to CodeClimate
uses: paambaati/codeclimate-action@v2.7.4
with:
coverageLocations: |
${{github.workspace}}/*lcov*:lcov
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}

acceptance_tests_rollbar_test1:
name: Acceptance Rollbar Test1
runs-on: ubuntu-latest

env:
ROLLBAR_API_KEY: ${{ secrets.ROLLBAR_API_KEY }}

steps:

# Install Go and Terraform
- uses: actions/setup-go@v2

# Checkout
- uses: actions/checkout@v2

# Restore cache
- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
# Blank version number means latest version of Go.
key: ${{ runner.os }}-go-v-${{ hashFiles('**/go.sum') }}

# Wait for up to ten minutes for previous run to complete; abort if not
# done by then.
- name: Block Concurrent Executions
uses: softprops/turnstyle@v1
with:
poll-interval-seconds: 10
same-branch-only: false
abort-after-seconds: 600
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Run acceptance tests
- name: Acceptance tests rollbar test1
run: make testacc_rollbar_test1
env:
TERRAFORM_PROVIDER_ROLLBAR_DEBUG: 1
GOMAXPROCS: 8
- name: Convert Go coverage file to lcov format
run: |
go get github.com/jandelgado/gcov2lcov
go install github.com/jandelgado/gcov2lcov
~/go/bin/gcov2lcov -infile coverage_test1.out -outfile lcov_test1.info
acceptance_tests_rollbar_test2:
name: Acceptance Rollbar Test2
runs-on: ubuntu-latest

env:
ROLLBAR_API_KEY: ${{ secrets.ROLLBAR_API_KEY }}

steps:

# Install Go and Terraform
- uses: actions/setup-go@v2

# Checkout
- uses: actions/checkout@v2

# Restore cache
- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/.cache/go-build
# Blank version number means latest version of Go.
key: ${{ runner.os }}-go-v-${{ hashFiles('**/go.sum') }}

# Wait for up to ten minutes for previous run to complete; abort if not
# done by then.
- name: Block Concurrent Executions
uses: softprops/turnstyle@v1
with:
poll-interval-seconds: 10
same-branch-only: false
abort-after-seconds: 600
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Run acceptance tests
- name: Acceptance tests rollbar test2
run: make testacc_rollbar_test2
env:
TERRAFORM_PROVIDER_ROLLBAR_DEBUG: 1
GOMAXPROCS: 8
- name: Convert Go coverage file to lcov format
run: |
go get github.com/jandelgado/gcov2lcov
go install github.com/jandelgado/gcov2lcov
~/go/bin/gcov2lcov -infile coverage_test2.out -outfile lcov_test2.info
4 changes: 2 additions & 2 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.16'
go-version: '1.19'
check-latest: false
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.45.2
version: v1.49.0
# Optional: golangci-lint command line arguments.
args: --timeout=5m --tests=false
# Optional: working directory, useful for monorepos
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
matrix:
go:
- "" # Latest
- "1.17"
- "1.16"
- "1.15"
- "1.14"
- "1.22"
- "1.21"
- "1.20"
- "1.19"

steps:

Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ test:
go test -covermode=atomic -coverprofile=coverage.out $(TEST) || exit 1
@#echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc:
TF_ACC=1 TERRAFORM_PROVIDER_ROLLBAR_DEBUG=1 go test -covermode=atomic -coverprofile=coverage.out $(TEST) -v $(TESTARGS) -timeout 120m

testacc_client:
TF_ACC=1 TERRAFORM_PROVIDER_ROLLBAR_DEBUG=1 go test -covermode=atomic -coverprofile=coverage_client.out github.com/rollbar/terraform-provider-rollbar/client -v $(TESTARGS) -timeout 10m
testacc_rollbar_test1:
TF_ACC=1 TERRAFORM_PROVIDER_ROLLBAR_DEBUG=1 go test -covermode=atomic -coverprofile=coverage_test1.out github.com/rollbar/terraform-provider-rollbar/rollbar/test1 -v $(TESTARGS) -timeout 120m
testacc_rollbar_test2:
TF_ACC=1 TERRAFORM_PROVIDER_ROLLBAR_DEBUG=1 go test -covermode=atomic -coverprofile=coverage_test2.out github.com/rollbar/terraform-provider-rollbar/rollbar/test2 -v $(TESTARGS) -timeout 120m
slscan:
./.slscan.sh

Expand Down
61 changes: 57 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,65 @@ import (
const DefaultBaseURL = "https://api.rollbar.com"
const Version = "v1.13.1"

var Mutex sync.Mutex

// RollbarAPIClient is a client for the Rollbar API.
type RollbarAPIClient struct {
BaseURL string // Base URL for Rollbar API
Resty *resty.Client

m sync.Mutex
}

// NewTestClient sets up a new Rollbar API test client.
func NewTestClient(baseURL, token string) *RollbarAPIClient {
log.Debug().Msg("Initializing Rollbar client")

// New Resty HTTP client
r := resty.New()

// Use default transport - needed for VCR
r.SetTransport(http.DefaultTransport).
// set timeout on http client
SetTimeout(30 * time.Second).
// Set retry count to 1 (try 2 times before it fails)
SetRetryCount(1).
SetRetryWaitTime(1 * time.Second).
SetRetryMaxWaitTime(5 * time.Second)

// Authentication
if token != "" {
r = r.SetHeaders(map[string]string{
"X-Rollbar-Access-Token": token,
"X-Rollbar-Terraform": "true"})
} else {
log.Warn().Msg("Rollbar API token not set")
}

// Authentication
if baseURL == "" {
log.Error().Msg("Rollbar API base URL not set")
}

// Configure Resty to use Zerolog for logging
r.SetLogger(restyZeroLogger{log.Logger})

// Rollbar client
c := RollbarAPIClient{
Resty: r,
BaseURL: baseURL,
}
return &c
}

func (c *RollbarAPIClient) SetHeaderResource(header string) {
c.m.Lock()
defer c.m.Unlock()
c.Resty.SetHeader("X-Rollbar-Terraform-Resource", header)
}

func (c *RollbarAPIClient) SetHeaderDataSource(header string) {
c.m.Lock()
defer c.m.Unlock()
c.Resty.SetHeader("X-Rollbar-Terraform-DataSource", header)
}

// NewClient sets up a new Rollbar API client.
Expand Down Expand Up @@ -70,7 +123,7 @@ func NewClient(baseURL, token string) *RollbarAPIClient {
r.StatusCode() == http.StatusBadGateway
})
// Authentication
Mutex.Lock()

if token != "" {
r = r.SetHeaders(map[string]string{
"X-Rollbar-Access-Token": token,
Expand All @@ -80,7 +133,7 @@ func NewClient(baseURL, token string) *RollbarAPIClient {
} else {
log.Warn().Msg("Rollbar API token not set")
}
Mutex.Unlock()

// Authentication
if baseURL == "" {
log.Error().Msg("Rollbar API base URL not set")
Expand Down
41 changes: 0 additions & 41 deletions client/client_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ import (
"net/http"
"os"
"testing"
"time"

"github.com/brianvoe/gofakeit/v5"
"github.com/go-resty/resty/v2"
"github.com/jarcoal/httpmock"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -78,45 +76,6 @@ type Suite struct {
client *RollbarAPIClient
}

func NewTestClient(baseURL, token string) *RollbarAPIClient {
log.Debug().Msg("Initializing Rollbar client")

// New Resty HTTP client
r := resty.New()

// Use default transport - needed for VCR
r.SetTransport(http.DefaultTransport).
// set timeout on http client
SetTimeout(30 * time.Second).
// Set retry count to 3 (try 3 times before it fails)
SetRetryCount(2).
SetRetryWaitTime(1 * time.Second).
SetRetryMaxWaitTime(5 * time.Second)

// Authentication
if token != "" {
r = r.SetHeaders(map[string]string{
"X-Rollbar-Access-Token": token,
"X-Rollbar-Terraform": "true"})
} else {
log.Warn().Msg("Rollbar API token not set")
}

// Authentication
if baseURL == "" {
log.Error().Msg("Rollbar API base URL not set")
}

// Configure Resty to use Zerolog for logging
r.SetLogger(restyZeroLogger{log.Logger})

// Rollbar client
c := RollbarAPIClient{
Resty: r,
BaseURL: baseURL,
}
return &c
}
func (s *Suite) SetupSuite() {
// Pretty logging
log.Logger = log.
Expand Down
4 changes: 4 additions & 0 deletions client/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type WebhookIntegration struct {

// UpdateIntegration updates a new Rollbar integration.
func (c *RollbarAPIClient) UpdateIntegration(integration string, bodyMap map[string]interface{}) (interface{}, error) {
c.m.Lock()
defer c.m.Unlock()
u := c.BaseURL + pathIntegration
l := log.With().
Str("integration", integration).
Expand Down Expand Up @@ -112,6 +114,8 @@ func (c *RollbarAPIClient) UpdateIntegration(integration string, bodyMap map[str
// ReadIntegration reads a Rollbar integration from the API. If no matching integration is found,
// returns error ErrNotFound.
func (c *RollbarAPIClient) ReadIntegration(integration string) (interface{}, error) {
c.m.Lock()
defer c.m.Unlock()
u := c.BaseURL + pathIntegration

l := log.With().
Expand Down
12 changes: 10 additions & 2 deletions client/invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type Invitation struct {

// ListAllInvitationsPerEmail lists all invitations for all Rollbar teams.
func (c *RollbarAPIClient) ListAllInvitationsPerEmail(email string) (invs []Invitation, err error) {

c.m.Lock()
defer c.m.Unlock()
hasNextPage := true
page := 1

Expand Down Expand Up @@ -85,7 +86,8 @@ func (c *RollbarAPIClient) ListAllInvitationsPerEmail(email string) (invs []Invi

// ListInvitations lists all invitations for a Rollbar team.
func (c *RollbarAPIClient) ListInvitations(teamID int) (invs []Invitation, err error) {

c.m.Lock()
defer c.m.Unlock()
hasNextPage := true
page := 1

Expand Down Expand Up @@ -171,6 +173,8 @@ func (c *RollbarAPIClient) FindPendingInvitations(email string) ([]Invitation, e

// CreateInvitation sends a Rollbar team invitation to a user.
func (c *RollbarAPIClient) CreateInvitation(teamID int, email string) (Invitation, error) {
c.m.Lock()
defer c.m.Unlock()
l := log.With().
Int("teamID", teamID).
Str("email", email).
Expand Down Expand Up @@ -206,6 +210,8 @@ func (c *RollbarAPIClient) CreateInvitation(teamID int, email string) (Invitatio

// ReadInvitation reads a Rollbar team invitation from the API.
func (c *RollbarAPIClient) ReadInvitation(inviteID int) (inv Invitation, err error) {
c.m.Lock()
defer c.m.Unlock()
l := log.With().
Int("inviteID", inviteID).
Logger()
Expand Down Expand Up @@ -239,6 +245,8 @@ func (c *RollbarAPIClient) DeleteInvitation(id int) (err error) {

// CancelInvitation cancels a Rollbar team invitation.
func (c *RollbarAPIClient) CancelInvitation(id int) (err error) {
c.m.Lock()
defer c.m.Unlock()
l := log.With().Int("id", id).Logger()
l.Debug().Msg("Canceling invitation")

Expand Down
Loading

0 comments on commit c2128ac

Please sign in to comment.