Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Fix meta service domains schema structure #3249

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions github/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,25 @@ type APIMeta struct {
// which serve GitHub APIs.
API []string `json:"api,omitempty"`

// A map of GitHub services and their associated domains. Note that many
// of these domains are represented as wildcards (e.g. "*.github.com").
Domains map[string][]string `json:"domains,omitempty"`
// GitHub services and their associated domains. Note that many of these domains
// are represented as wildcards (e.g. "*.github.com").
Domains *APIMetaDomains `json:"domains,omitempty"`
}

// APIMetaDomains represents the domains associated with GitHub services.
type APIMetaDomains struct {
Website []string `json:"website,omitempty"`
Codespaces []string `json:"codespaces,omitempty"`
Copilot []string `json:"copilot,omitempty"`
Packages []string `json:"packages,omitempty"`
Actions []string `json:"actions,omitempty"`
ArtifactAttestations *APIMetaArtifactAttestations `json:"artifact_attestations,omitempty"`
}

// APIMetaArtifactAttestations represents the artifact attestation services domains.
type APIMetaArtifactAttestations struct {
TrustDomain string `json:"trust_domain,omitempty"`
Services []string `json:"services,omitempty"`
}

// Get returns information about GitHub.com, the service. Or, if you access
Expand Down
42 changes: 36 additions & 6 deletions github/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,23 @@ func TestAPIMeta_Marshal(t *testing.T) {
SSHKeys: []string{"k"},
API: []string{"a"},
Web: []string{"w"},
Domains: map[string][]string{
"example": {"example.com", "*.example.com"},
Domains: &APIMetaDomains{
Website: []string{
"*.github.com",
"*.github.dev",
"*.github.io",
"*.githubassets.com",
"*.githubusercontent.com",
},
ArtifactAttestations: &APIMetaArtifactAttestations{
TrustDomain: "",
Services: []string{
"*.actions.githubusercontent.com",
"tuf-repo.github.com",
"fulcio.githubapp.com",
"timestamp.githubapp.com",
},
},
},
}
want := `{
Expand All @@ -47,7 +62,7 @@ func TestAPIMeta_Marshal(t *testing.T) {
"ssh_keys":["k"],
"api":["a"],
"web":["w"],
"domains":{"example":["example.com","*.example.com"]}
"domains":{"website":["*.github.com","*.github.dev","*.github.io","*.githubassets.com","*.githubusercontent.com"],"artifact_attestations":{"trust_domain":"","services":["*.actions.githubusercontent.com","tuf-repo.github.com","fulcio.githubapp.com","timestamp.githubapp.com"]}}
}`

testJSONMarshal(t, a, want)
Expand All @@ -59,7 +74,7 @@ func TestMetaService_Get(t *testing.T) {

mux.HandleFunc("/meta", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"web":["w"],"api":["a"],"hooks":["h"], "git":["g"], "pages":["p"], "importer":["i"], "github_enterprise_importer": ["gei"], "actions":["a"], "dependabot":["d"], "verifiable_password_authentication": true, "domains":{"example":["example.com","*.example.com"]}}`)
fmt.Fprint(w, `{"web":["w"],"api":["a"],"hooks":["h"], "git":["g"], "pages":["p"], "importer":["i"], "github_enterprise_importer": ["gei"], "actions":["a"], "dependabot":["d"], "verifiable_password_authentication": true, "domains":{"website":["*.github.com","*.github.dev","*.github.io","*.githubassets.com","*.githubusercontent.com"],"artifact_attestations":{"trust_domain":"","services":["*.actions.githubusercontent.com","tuf-repo.github.com","fulcio.githubapp.com","timestamp.githubapp.com"]}}}`)
})

ctx := context.Background()
Expand All @@ -78,8 +93,23 @@ func TestMetaService_Get(t *testing.T) {
Dependabot: []string{"d"},
API: []string{"a"},
Web: []string{"w"},
Domains: map[string][]string{
"example": {"example.com", "*.example.com"},
Domains: &APIMetaDomains{
Website: []string{
"*.github.com",
"*.github.dev",
"*.github.io",
"*.githubassets.com",
"*.githubusercontent.com",
},
ArtifactAttestations: &APIMetaArtifactAttestations{
TrustDomain: "",
Services: []string{
"*.actions.githubusercontent.com",
"tuf-repo.github.com",
"fulcio.githubapp.com",
"timestamp.githubapp.com",
},
},
},

VerifiablePasswordAuthentication: Bool(true),
Expand Down
Loading