Skip to content

Commit 7f50dfa

Browse files
committed
feat: retrieve a client key
1 parent faafbec commit 7f50dfa

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

sentry/project_keys.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ func (s *ProjectKeysService) List(ctx context.Context, organizationSlug string,
7676
return projectKeys, resp, nil
7777
}
7878

79+
// Get details of a client key.
80+
// https://docs.sentry.io/api/projects/retrieve-a-client-key/
81+
func (s *ProjectKeysService) Get(ctx context.Context, organizationSlug string, projectSlug string, id string) (*ProjectKey, *Response, error) {
82+
u := fmt.Sprintf("0/projects/%v/%v/keys/%v/", organizationSlug, projectSlug, id)
83+
req, err := s.client.NewRequest("GET", u, nil)
84+
if err != nil {
85+
return nil, nil, err
86+
}
87+
88+
projectKey := new(ProjectKey)
89+
resp, err := s.client.Do(ctx, req, projectKey)
90+
if err != nil {
91+
return nil, resp, err
92+
}
93+
return projectKey, resp, nil
94+
}
95+
7996
// CreateProjectKeyParams are the parameters for ProjectKeyService.Create.
8097
type CreateProjectKeyParams struct {
8198
Name string `json:"name,omitempty"`

sentry/project_keys_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,97 @@ func TestProjectKeysService_List(t *testing.T) {
173173
assert.Equal(t, expected, projectKeys)
174174
}
175175

176+
func TestProjectKeysService_Get(t *testing.T) {
177+
client, mux, _, teardown := setup()
178+
defer teardown()
179+
180+
mux.HandleFunc("/api/0/projects/the-interstellar-jurisdiction/pump-station/keys/60120449b6b1d5e45f75561e6dabd80b/", func(w http.ResponseWriter, r *http.Request) {
181+
assertMethod(t, "GET", r)
182+
w.Header().Set("Content-Type", "application/json")
183+
fmt.Fprint(w, `{
184+
"id": "60120449b6b1d5e45f75561e6dabd80b",
185+
"name": "Liked Pegasus",
186+
"label": "Liked Pegasus",
187+
"public": "60120449b6b1d5e45f75561e6dabd80b",
188+
"secret": "189485c3b8ccf582bf5e12c530ef8858",
189+
"projectId": 4505281256090153,
190+
"isActive": true,
191+
"rateLimit": {
192+
"window": 7200,
193+
"count": 1000
194+
},
195+
"dsn": {
196+
"secret": "https://a785682ddda742d7a8a4088810e67701:bcd99b3790b3441c85ce4b1eaa854f66@o4504765715316736.ingest.sentry.io/4505281256090153",
197+
"public": "https://a785682ddda742d7a8a4088810e67791@o4504765715316736.ingest.sentry.io/4505281256090153",
198+
"csp": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/csp-report/?sentry_key=a785682ddda719b7a8a4011110d75598",
199+
"security": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/security/?sentry_key=a785682ddda719b7a8a4011110d75598",
200+
"minidump": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/minidump/?sentry_key=a785682ddda719b7a8a4011110d75598",
201+
"nel": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/nel/?sentry_key=a785682ddda719b7a8a4011110d75598",
202+
"unreal": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/unreal/a785682ddda719b7a8a4011110d75598/",
203+
"cdn": "https://js.sentry-cdn.com/a785682ddda719b7a8a4011110d75598.min.js",
204+
"crons": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/crons/___MONITOR_SLUG___/a785682ddda719b7a8a4011110d75598/"
205+
},
206+
"browserSdkVersion": "7.x",
207+
"browserSdk": {
208+
"choices": [
209+
[
210+
"latest",
211+
"latest"
212+
],
213+
[
214+
"7.x",
215+
"7.x"
216+
]
217+
]
218+
},
219+
"dateCreated": "2023-06-21T19:50:26.036254Z",
220+
"dynamicSdkLoaderOptions": {
221+
"hasReplay": true,
222+
"hasPerformance": true,
223+
"hasDebug": true
224+
}
225+
}`)
226+
})
227+
228+
ctx := context.Background()
229+
projectKey, _, err := client.ProjectKeys.Get(ctx, "the-interstellar-jurisdiction", "pump-station", "60120449b6b1d5e45f75561e6dabd80b")
230+
assert.NoError(t, err)
231+
232+
expected := &ProjectKey{
233+
ID: "60120449b6b1d5e45f75561e6dabd80b",
234+
Name: "Liked Pegasus",
235+
Label: "Liked Pegasus",
236+
Public: "60120449b6b1d5e45f75561e6dabd80b",
237+
Secret: "189485c3b8ccf582bf5e12c530ef8858",
238+
ProjectID: json.Number("4505281256090153"),
239+
IsActive: true,
240+
RateLimit: &ProjectKeyRateLimit{
241+
Window: 7200,
242+
Count: 1000,
243+
},
244+
DSN: ProjectKeyDSN{
245+
Secret: "https://a785682ddda742d7a8a4088810e67701:bcd99b3790b3441c85ce4b1eaa854f66@o4504765715316736.ingest.sentry.io/4505281256090153",
246+
Public: "https://a785682ddda742d7a8a4088810e67791@o4504765715316736.ingest.sentry.io/4505281256090153",
247+
CSP: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/csp-report/?sentry_key=a785682ddda719b7a8a4011110d75598",
248+
Security: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/security/?sentry_key=a785682ddda719b7a8a4011110d75598",
249+
Minidump: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/minidump/?sentry_key=a785682ddda719b7a8a4011110d75598",
250+
NEL: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/nel/?sentry_key=a785682ddda719b7a8a4011110d75598",
251+
Unreal: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/unreal/a785682ddda719b7a8a4011110d75598/",
252+
CDN: "https://js.sentry-cdn.com/a785682ddda719b7a8a4011110d75598.min.js",
253+
Crons: "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/crons/___MONITOR_SLUG___/a785682ddda719b7a8a4011110d75598/",
254+
},
255+
BrowserSDKVersion: "7.x",
256+
DateCreated: mustParseTime("2023-06-21T19:50:26.036254Z"),
257+
DynamicSDKLoaderOptions: ProjectKeyDynamicSDKLoaderOptions{
258+
HasReplay: true,
259+
HasPerformance: true,
260+
HasDebugFiles: true,
261+
},
262+
}
263+
264+
assert.Equal(t, expected, projectKey)
265+
}
266+
176267
func TestProjectKeysService_Create(t *testing.T) {
177268
client, mux, _, teardown := setup()
178269
defer teardown()

0 commit comments

Comments
 (0)