package client import ( "fmt" "net/http" "net/url" "time" "github.com/shurcooL/graphql" ) // Option enables options to be set for the Edge Client. type Option = func(c *EdgeClient) // WithGraphqlClient sets the specified GraphQL client for the Edge Client. func WithGraphqlClient(cl *graphql.Client) Option { return func(c *EdgeClient) { c.Client = cl } } // WithHTTPClient sets the specified http client for the Edge Client. // Because this overrides the default http client that Edge Client provides // You will have to also implement and specificy the cookie jar yourself // Example: // // jar, err := cookiejar.New(&cookiejar.Options{}) // &http.Client{ // Jar: c.jar, // } func WithHTTPClient(cl *http.Client) Option { return func(c *EdgeClient) { c.HTTPClient = cl } } // WithUserAgent sets and overrides the default http user agent header for the Edge Client. func WithUserAgent(userAgent string) Option { return func(c *EdgeClient) { c.userAgent = userAgent } } // WithVersion sets the edge version header value for the Edge Client. func WithVersion(version string) Option { return func(c *EdgeClient) { c.version = version } } // WithBaseURL sets the api url for the Edge Client to make requests. // The default value is https://dev1.edge-preprod.dev/api/v2 func WithBaseURL(apiURL string) Option { return func(c *EdgeClient) { baseURL, err := url.Parse(apiURL) if err != nil { panic(err) } c.BaseURL = baseURL } } // WithTotp sets the totp token to use for requests. // It is very discouraged to use multiple authentication methods. func WithTotp(token string) Option { return func(c *EdgeClient) { c.totpToken = token c.headers[authorizationHeader] = fmt.Sprintf("%s %s", totpToken, token) } } // WithBearerToken sets the jwt bearer token to use for requests. // It is very discouraged to use multiple authentication methods. func WithBearerToken(token string) Option { return func(c *EdgeClient) { c.bearerToken = token c.headers[authorizationHeader] = fmt.Sprintf("%s %s", bearerToken, token) } } // WithCredentials sets the username, password and organization to use for the authentication request. // It is very discouraged to use multiple authentication methods. func WithCredentials(username, password, organization string) Option { return func(c *EdgeClient) { c.loginCredentials = &LoginRequest{ Username: username, Password: password, Organization: organization, } } } // WithTimeout sets and overrides the default http timeout for the Edge Client. func WithTimeout(timeout time.Duration) Option { return func(c *EdgeClient) { c.timeout = timeout } }