diff --git a/sentry/project_keys.go b/sentry/project_keys.go index 0c3a24b..fd3fae1 100644 --- a/sentry/project_keys.go +++ b/sentry/project_keys.go @@ -76,6 +76,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"` diff --git a/sentry/project_keys_test.go b/sentry/project_keys_test.go index f6687a9..02f8005 100644 --- a/sentry/project_keys_test.go +++ b/sentry/project_keys_test.go @@ -173,6 +173,97 @@ func TestProjectKeysService_List(t *testing.T) { assert.Equal(t, expected, projectKeys) } +func TestProjectKeysService_Get(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/api/0/projects/the-interstellar-jurisdiction/pump-station/keys/60120449b6b1d5e45f75561e6dabd80b/", func(w http.ResponseWriter, r *http.Request) { + assertMethod(t, "GET", r) + w.Header().Set("Content-Type", "application/json") + fmt.Fprint(w, `{ + "id": "60120449b6b1d5e45f75561e6dabd80b", + "name": "Liked Pegasus", + "label": "Liked Pegasus", + "public": "60120449b6b1d5e45f75561e6dabd80b", + "secret": "189485c3b8ccf582bf5e12c530ef8858", + "projectId": 4505281256090153, + "isActive": true, + "rateLimit": { + "window": 7200, + "count": 1000 + }, + "dsn": { + "secret": "https://a785682ddda742d7a8a4088810e67701:bcd99b3790b3441c85ce4b1eaa854f66@o4504765715316736.ingest.sentry.io/4505281256090153", + "public": "https://a785682ddda742d7a8a4088810e67791@o4504765715316736.ingest.sentry.io/4505281256090153", + "csp": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/csp-report/?sentry_key=a785682ddda719b7a8a4011110d75598", + "security": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/security/?sentry_key=a785682ddda719b7a8a4011110d75598", + "minidump": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/minidump/?sentry_key=a785682ddda719b7a8a4011110d75598", + "nel": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/nel/?sentry_key=a785682ddda719b7a8a4011110d75598", + "unreal": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/unreal/a785682ddda719b7a8a4011110d75598/", + "cdn": "https://js.sentry-cdn.com/a785682ddda719b7a8a4011110d75598.min.js", + "crons": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/crons/___MONITOR_SLUG___/a785682ddda719b7a8a4011110d75598/" + }, + "browserSdkVersion": "7.x", + "browserSdk": { + "choices": [ + [ + "latest", + "latest" + ], + [ + "7.x", + "7.x" + ] + ] + }, + "dateCreated": "2023-06-21T19:50:26.036254Z", + "dynamicSdkLoaderOptions": { + "hasReplay": true, + "hasPerformance": true, + "hasDebug": true + } + }`) + }) + + ctx := context.Background() + projectKey, _, err := client.ProjectKeys.Get(ctx, "the-interstellar-jurisdiction", "pump-station", "60120449b6b1d5e45f75561e6dabd80b") + assert.NoError(t, err) + + expected := &ProjectKey{ + ID: "60120449b6b1d5e45f75561e6dabd80b", + Name: "Liked Pegasus", + Label: "Liked Pegasus", + Public: "60120449b6b1d5e45f75561e6dabd80b", + Secret: "189485c3b8ccf582bf5e12c530ef8858", + ProjectID: json.Number("4505281256090153"), + IsActive: true, + RateLimit: &ProjectKeyRateLimit{ + Window: 7200, + Count: 1000, + }, + DSN: ProjectKeyDSN{ + Secret: "https://a785682ddda742d7a8a4088810e67701:bcd99b3790b3441c85ce4b1eaa854f66@o4504765715316736.ingest.sentry.io/4505281256090153", + Public: "https://a785682ddda742d7a8a4088810e67791@o4504765715316736.ingest.sentry.io/4505281256090153", + CSP: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/csp-report/?sentry_key=a785682ddda719b7a8a4011110d75598", + Security: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/security/?sentry_key=a785682ddda719b7a8a4011110d75598", + Minidump: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/minidump/?sentry_key=a785682ddda719b7a8a4011110d75598", + NEL: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/nel/?sentry_key=a785682ddda719b7a8a4011110d75598", + Unreal: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/unreal/a785682ddda719b7a8a4011110d75598/", + CDN: "https://js.sentry-cdn.com/a785682ddda719b7a8a4011110d75598.min.js", + Crons: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/crons/___MONITOR_SLUG___/a785682ddda719b7a8a4011110d75598/", + }, + BrowserSDKVersion: "7.x", + DateCreated: mustParseTime("2023-06-21T19:50:26.036254Z"), + DynamicSDKLoaderOptions: ProjectKeyDynamicSDKLoaderOptions{ + HasReplay: true, + HasPerformance: true, + HasDebugFiles: true, + }, + } + + assert.Equal(t, expected, projectKey) +} + func TestProjectKeysService_Create(t *testing.T) { client, mux, _, teardown := setup() defer teardown()