Skip to content

chore: Add graphql to the config for Github #103

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

Sly1029
Copy link

@Sly1029 Sly1029 commented Dec 10, 2024

We want to start using graphql exclusive Github api features. This will add support for the graphql endpoint at

https://api.github.com/graphql

https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#the-graphql-endpoint

uses:
https://github.com/semgrep/semgrep-app/pull/17492

@Sly1029 Sly1029 requested a review from tpetr as a code owner December 10, 2024 19:43
pkg/config.go Outdated
@@ -517,6 +589,23 @@ func LoadConfig(configFiles []string, deploymentId int) (*Config, error) {
Methods: ParseHttpMethods([]string{"GET", "PUT"}),
SetRequestHeaders: headers,
},
// Graphql API with specific operations
AllowlistItem{
URL: gitHubBaseUrl.JoinPath("/graphql").String(),
Copy link
Author

@Sly1029 Sly1029 Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where can I see what gitHubBaseUrl is usually set to for people's config? Is it something like https://something.com/api or is it https://something.com

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the graphql endpoint doesn't use /api

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is from

gitHubBaseUrl, err := url.Parse(gitHub.BaseURL)
which is from the baseUrl defined in the config:
baseUrl: https://github.example.com/api/v3

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I parsed the url to point it to graphql instead but I am not sure if it is foolproof so let me know

@Sly1029 Sly1029 requested a review from a team December 18, 2024 00:43
@@ -187,6 +258,7 @@ type AllowlistItem struct {
LogRequestHeaders bool `mapstructure:"logRequestHeaders" json:"logRequestHeaders"`
LogResponseBody bool `mapstructure:"logResponseBody" json:"logResponseBody"`
LogResponseHeaders bool `mapstructure:"logResponseHeaders" json:"logResponseHeaders"`
GraphQLData *GraphQLFilter `mapstructure:"githubGraphQL" json:"githubGraphQL"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update the mapstructure and json tags too please?

@@ -79,6 +79,28 @@ func (config *InboundProxyConfig) Start(tnet *netstack.Net) error {
return
}

// Just to make sure validate all three of these things before checking
if allowlistMatch.GraphQLData != nil &&
c.Request.Method == "POST" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will there ever be graphql PUTs or PATCHes? might be safer to do != "GET" instead

@@ -420,6 +492,10 @@ func LoadConfig(configFiles []string, deploymentId int) (*Config, error) {
if err != nil {
return nil, fmt.Errorf("failed to parse github base URL: %v", err)
}
gitHubBaseUrlGraphQL, err := url.Parse(strings.Replace(gitHub.BaseURL, "/api/v3", "/api/graphql", 1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels a bit brittle imo. we've already parsed gitHub.BaseURL into gitHubBaseUrl, so why can't we make a copy and explicitly set foo.Path = "/api/graphql"?

@@ -178,6 +180,75 @@ func httpMethodsDecodeHook(f reflect.Type, t reflect.Type, data interface{}) (in
return ParseHttpMethods(methods), nil
}

type graphQlRequest struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uber nit but let's have this be public like everything else (i.e. capital G)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants