Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into marten-2024-06-sync…
Browse files Browse the repository at this point in the history
…-with-upstream
  • Loading branch information
martendeng committed Jun 19, 2024
2 parents 163f36c + 954549e commit 0c54a08
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 93 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/google/go-querystring v1.1.0
github.com/peterhellberg/link v1.2.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
1 change: 1 addition & 0 deletions sentry/metric_alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type MetricAlert struct {
TimeWindow *float64 `json:"timeWindow,omitempty"`
ThresholdType *int `json:"thresholdType,omitempty"`
ResolveThreshold *float64 `json:"resolveThreshold,omitempty"`
ComparisonDelta *float64 `json:"comparisonDelta,omitempty"`

Check failure on line 23 in sentry/metric_alerts.go

View workflow job for this annotation

GitHub Actions / build (1.19)

other declaration of ComparisonDelta

Check failure on line 23 in sentry/metric_alerts.go

View workflow job for this annotation

GitHub Actions / build (1.20)

other declaration of ComparisonDelta

Check failure on line 23 in sentry/metric_alerts.go

View workflow job for this annotation

GitHub Actions / build (1.21)

other declaration of ComparisonDelta

Check failure on line 23 in sentry/metric_alerts.go

View workflow job for this annotation

GitHub Actions / build (1.19)

other declaration of ComparisonDelta

Check failure on line 23 in sentry/metric_alerts.go

View workflow job for this annotation

GitHub Actions / build (1.20)

other declaration of ComparisonDelta

Check failure on line 23 in sentry/metric_alerts.go

View workflow job for this annotation

GitHub Actions / build (1.21)

other declaration of ComparisonDelta
Triggers []*MetricAlertTrigger `json:"triggers,omitempty"`
Projects []string `json:"projects,omitempty"`
Owner *string `json:"owner,omitempty"`
Expand Down
15 changes: 8 additions & 7 deletions sentry/organization_integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sentry

import (
"context"
"encoding/json"
"fmt"
"time"
)
Expand All @@ -17,7 +18,7 @@ type OrganizationIntegrationProvider struct {
}

// IntegrationConfigData for defining integration-specific configuration data.
type IntegrationConfigData map[string]interface{}
type IntegrationConfigData map[string]json.RawMessage

// OrganizationIntegration represents an integration added for the organization.
// https://github.com/getsentry/sentry/blob/22.7.0/src/sentry/api/serializers/models/integration.py#L93
Expand All @@ -33,11 +34,11 @@ type OrganizationIntegration struct {
Provider OrganizationIntegrationProvider `json:"provider"`

// https://github.com/getsentry/sentry/blob/22.7.0/src/sentry/api/serializers/models/integration.py#L138
ConfigData *IntegrationConfigData `json:"configData"`
ExternalId string `json:"externalId"`
OrganizationId int `json:"organizationId"`
OrganizationIntegrationStatus string `json:"organizationIntegrationStatus"`
GracePeriodEnd *time.Time `json:"gracePeriodEnd"`
ConfigData json.RawMessage `json:"configData"`
ExternalId string `json:"externalId"`
OrganizationId int `json:"organizationId"`
OrganizationIntegrationStatus string `json:"organizationIntegrationStatus"`
GracePeriodEnd *time.Time `json:"gracePeriodEnd"`
}

// OrganizationIntegrationsService provides methods for accessing Sentry organization integrations API endpoints.
Expand Down Expand Up @@ -88,7 +89,7 @@ func (s *OrganizationIntegrationsService) Get(ctx context.Context, organizationS
return integration, resp, nil
}

type UpdateConfigOrganizationIntegrationsParams = IntegrationConfigData
type UpdateConfigOrganizationIntegrationsParams = json.RawMessage

// UpdateConfig - update configData for organization integration.
// https://github.com/getsentry/sentry/blob/22.7.0/src/sentry/api/endpoints/integrations/organization_integrations/details.py#L94-L102
Expand Down
42 changes: 21 additions & 21 deletions sentry/organization_integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestOrganizationIntegrationsService_List(t *testing.T) {
"stacktrace-link",
},
},
ConfigData: &IntegrationConfigData{},
ConfigData: json.RawMessage("{}"),
ExternalId: "87654321",
OrganizationId: 2,
OrganizationIntegrationStatus: "active",
Expand Down Expand Up @@ -181,15 +181,15 @@ func TestOrganizationIntegrationsService_Get(t *testing.T) {
"incident-management",
},
},
ConfigData: &IntegrationConfigData{
"service_table": []interface{}{
map[string]interface{}{
"service": "testing123",
"integration_key": "abc123xyz",
"id": json.Number("22222"),
},
},
},
ConfigData: json.RawMessage(`{
"service_table": [
{
"service": "testing123",
"integration_key": "abc123xyz",
"id": 22222
}
]
}`),
ExternalId: "999999",
OrganizationId: 2,
OrganizationIntegrationStatus: "active",
Expand All @@ -207,20 +207,20 @@ func TestOrganizationIntegrationsService_UpdateConfig(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
})

updateConfigOrganizationIntegrationsParams := UpdateConfigOrganizationIntegrationsParams{
"service_table": []interface{}{
map[string]interface{}{
"service": "testing123",
updateConfigOrganizationIntegrationsParams := UpdateConfigOrganizationIntegrationsParams(`{
"service_table": [
{
"service": "testing123",
"integration_key": "abc123xyz",
"id": json.Number("22222"),
"id": 22222
},
map[string]interface{}{
"service": "testing456",
{
"service": "testing456",
"integration_key": "efg456lmn",
"id": "",
},
},
}
"id": ""
}
]
}`)
ctx := context.Background()
resp, err := client.OrganizationIntegrations.UpdateConfig(ctx, "the-interstellar-jurisdiction", "456789", &updateConfigOrganizationIntegrationsParams)
assert.NoError(t, err)
Expand Down
37 changes: 37 additions & 0 deletions sentry/organization_projects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package sentry

import (
"context"
"fmt"
)

type OrganizationProjectsService service

type ListOrganizationProjectsParams struct {
ListCursorParams

Options string `url:"options,omitempty"`
Query string `url:"query,omitempty"`
}

// List an Organization's Projects
// https://docs.sentry.io/api/organizations/list-an-organizations-projects/
func (s *OrganizationProjectsService) List(ctx context.Context, organizationSlug string, params *ListOrganizationProjectsParams) ([]*Project, *Response, error) {
u := fmt.Sprintf("0/organizations/%v/projects/", organizationSlug)
u, err := addQuery(u, params)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

projects := []*Project{}
resp, err := s.client.Do(ctx, req, &projects)
if err != nil {
return nil, resp, err
}
return projects, resp, nil
}
56 changes: 45 additions & 11 deletions sentry/project_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,49 @@ type ProjectKeyDSN struct {
CSP string `json:"csp"`
Security string `json:"security"`
Minidump string `json:"minidump"`
NEL string `json:"nel"`
Unreal string `json:"unreal"`
CDN string `json:"cdn"`
Crons string `json:"crons"`
}

type ProjectKeyDynamicSDKLoaderOptions struct {
HasReplay bool `json:"hasReplay"`
HasPerformance bool `json:"hasPerformance"`
HasDebugFiles bool `json:"hasDebug"`
}

// ProjectKey represents a client key bound to a project.
// https://github.com/getsentry/sentry/blob/9.0.0/src/sentry/api/serializers/models/project_key.py
type ProjectKey struct {
ID string `json:"id"`
Name string `json:"name"`
Label string `json:"label"`
Public string `json:"public"`
Secret string `json:"secret"`
ProjectID json.Number `json:"projectId"`
IsActive bool `json:"isActive"`
RateLimit *ProjectKeyRateLimit `json:"rateLimit"`
DSN ProjectKeyDSN `json:"dsn"`
DateCreated time.Time `json:"dateCreated"`
ID string `json:"id"`
Name string `json:"name"`
Label string `json:"label"`
Public string `json:"public"`
Secret string `json:"secret"`
ProjectID json.Number `json:"projectId"`
IsActive bool `json:"isActive"`
RateLimit *ProjectKeyRateLimit `json:"rateLimit"`
DSN ProjectKeyDSN `json:"dsn"`
BrowserSDKVersion string `json:"browserSdkVersion"`
DateCreated time.Time `json:"dateCreated"`
DynamicSDKLoaderOptions ProjectKeyDynamicSDKLoaderOptions `json:"dynamicSdkLoaderOptions"`
}

// ProjectKeysService provides methods for accessing Sentry project
// client key API endpoints.
// https://docs.sentry.io/api/projects/
type ProjectKeysService service

type ListProjectKeysParams struct {
ListCursorParams

Status *string `url:"status,omitempty"`
}

// List client keys bound to a project.
// https://docs.sentry.io/api/projects/get-project-keys/
func (s *ProjectKeysService) List(ctx context.Context, organizationSlug string, projectSlug string, params *ListCursorParams) ([]*ProjectKey, *Response, error) {
func (s *ProjectKeysService) List(ctx context.Context, organizationSlug string, projectSlug string, params *ListProjectKeysParams) ([]*ProjectKey, *Response, error) {
u := fmt.Sprintf("0/projects/%v/%v/keys/", organizationSlug, projectSlug)
u, err := addQuery(u, params)
if err != nil {
Expand All @@ -65,6 +82,23 @@ func (s *ProjectKeysService) List(ctx context.Context, organizationSlug string,
return projectKeys, resp, nil
}

// Get details of a client key.
// https://docs.sentry.io/api/projects/retrieve-a-client-key/
func (s *ProjectKeysService) Get(ctx context.Context, organizationSlug string, projectSlug string, id string) (*ProjectKey, *Response, error) {
u := fmt.Sprintf("0/projects/%v/%v/keys/%v/", organizationSlug, projectSlug, id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

projectKey := new(ProjectKey)
resp, err := s.client.Do(ctx, req, projectKey)
if err != nil {
return nil, resp, err
}
return projectKey, resp, nil
}

// CreateProjectKeyParams are the parameters for ProjectKeyService.Create.
type CreateProjectKeyParams struct {
Name string `json:"name,omitempty"`
Expand Down
Loading

0 comments on commit 0c54a08

Please sign in to comment.