From 62eaf97a1ed07386e5601956e7568713b58b1f6b Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 17 Feb 2022 02:00:26 +0100 Subject: [PATCH] Add APIMeta fields related to SSH keys (#2293) --- github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 10 ++++++++++ github/misc.go | 6 ++++++ github/misc_test.go | 6 +++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 3be5bdd34da..6c13f545cd9 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -316,6 +316,14 @@ func (a *AnalysesListOptions) GetSarifID() string { return *a.SarifID } +// GetSSHKeyFingerprints returns the SSHKeyFingerprints map if it's non-nil, an empty map otherwise. +func (a *APIMeta) GetSSHKeyFingerprints() map[string]string { + if a == nil || a.SSHKeyFingerprints == nil { + return map[string]string{} + } + return a.SSHKeyFingerprints +} + // GetVerifiablePasswordAuthentication returns the VerifiablePasswordAuthentication field if it's non-nil, zero value otherwise. func (a *APIMeta) GetVerifiablePasswordAuthentication() bool { if a == nil || a.VerifiablePasswordAuthentication == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 986b8c7e36b..d06e6356d75 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -348,6 +348,16 @@ func TestAnalysesListOptions_GetSarifID(tt *testing.T) { a.GetSarifID() } +func TestAPIMeta_GetSSHKeyFingerprints(tt *testing.T) { + zeroValue := map[string]string{} + a := &APIMeta{SSHKeyFingerprints: zeroValue} + a.GetSSHKeyFingerprints() + a = &APIMeta{} + a.GetSSHKeyFingerprints() + a = nil + a.GetSSHKeyFingerprints() +} + func TestAPIMeta_GetVerifiablePasswordAuthentication(tt *testing.T) { var zeroValue bool a := &APIMeta{VerifiablePasswordAuthentication: &zeroValue} diff --git a/github/misc.go b/github/misc.go index 1fa6c4e1304..7672e08acc8 100644 --- a/github/misc.go +++ b/github/misc.go @@ -170,6 +170,12 @@ type APIMeta struct { // An array of IP addresses in CIDR format specifying the IP addresses // Dependabot will originate from. Dependabot []string `json:"dependabot,omitempty"` + + // A map of algorithms to SSH key fingerprints. + SSHKeyFingerprints map[string]string `json:"ssh_key_fingerprints,omitempty"` + + // An array of SSH keys. + SSHKeys []string `json:"ssh_keys,omitempty"` } // APIMeta returns information about GitHub.com, the service. Or, if you access diff --git a/github/misc_test.go b/github/misc_test.go index 8b15fd4631d..fc91d712948 100644 --- a/github/misc_test.go +++ b/github/misc_test.go @@ -188,6 +188,8 @@ func TestAPIMeta_Marshal(t *testing.T) { Importer: []string{"i"}, Actions: []string{"a"}, Dependabot: []string{"d"}, + SSHKeyFingerprints: map[string]string{"a": "f"}, + SSHKeys: []string{"k"}, } want := `{ "hooks":["h"], @@ -196,7 +198,9 @@ func TestAPIMeta_Marshal(t *testing.T) { "pages":["p"], "importer":["i"], "actions":["a"], - "dependabot":["d"] + "dependabot":["d"], + "ssh_key_fingerprints":{"a":"f"}, + "ssh_keys":["k"] }` testJSONMarshal(t, a, want)