diff --git a/.tutone.yml b/.tutone.yml index d0d69b15..beef798b 100644 --- a/.tutone.yml +++ b/.tutone.yml @@ -69,6 +69,20 @@ packages: field_type_override: nrtime.TimeWindowInput skip_type_create: true + - name: agent + path: pkg/agent + import_path: github.com/newrelic/newrelic-client-go/v2/pkg/agent + generators: + - typegen + - nerdgraphclient + queries: + - path: [ "docs" ] + endpoints: + - name: currentAgentRelease + max_query_field_depth: 1 + types: + - name: AgentReleasesFilter + - name: agentApplications path: pkg/agentapplications import_path: github.com/newrelic/newrelic-client-go/v2/pkg/agentapplications diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go new file mode 100644 index 00000000..a3dd7c6c --- /dev/null +++ b/pkg/agent/agent.go @@ -0,0 +1,19 @@ +package agent + +import ( + "github.com/newrelic/newrelic-client-go/v2/internal/http" + "github.com/newrelic/newrelic-client-go/v2/pkg/config" + "github.com/newrelic/newrelic-client-go/v2/pkg/logging" +) + +type Agent struct { + client http.Client + logger logging.Logger +} + +func New(config config.Config) Agent { + return Agent{ + client: http.NewClient(config), + logger: config.GetLogger(), + } +} diff --git a/pkg/agent/agent_api.go b/pkg/agent/agent_api.go new file mode 100644 index 00000000..b9ecbf63 --- /dev/null +++ b/pkg/agent/agent_api.go @@ -0,0 +1,46 @@ +// Code generated by tutone: DO NOT EDIT +package agent + +import "context" + +// The current release of the provided Agent +func (a *Agent) GetCurrentAgentRelease( + agentName AgentReleasesFilter, +) (*AgentReleasesAgentRelease, error) { + return a.GetCurrentAgentReleaseWithContext(context.Background(), + agentName, + ) +} + +// The current release of the provided Agent +func (a *Agent) GetCurrentAgentReleaseWithContext( + ctx context.Context, + agentName AgentReleasesFilter, +) (*AgentReleasesAgentRelease, error) { + + resp := currentAgentReleaseResponse{} + vars := map[string]interface{}{ + "agentName": agentName, + } + + if err := a.client.NerdGraphQueryWithContext(ctx, getCurrentAgentReleaseQuery, vars, &resp); err != nil { + return nil, err + } + + return &resp.DocumentationFields.CurrentAgentRelease, nil +} + +const getCurrentAgentReleaseQuery = `query( + $agentName: AgentReleasesFilter!, +) { docs { currentAgentRelease( + agentName: $agentName, +) { + bugs + date + downloadLink + eolDate + features + security + slug + version +} } }` diff --git a/pkg/agent/agent_integration_test.go b/pkg/agent/agent_integration_test.go new file mode 100644 index 00000000..a24e1b4c --- /dev/null +++ b/pkg/agent/agent_integration_test.go @@ -0,0 +1,49 @@ +//go:build integration + +package agent + +import ( + "testing" + + "github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers" + "github.com/stretchr/testify/require" +) + +func newAgentIntegrationTestClient(t *testing.T) Agent { + tc := testhelpers.NewIntegrationTestConfig(t) + + return New(tc) +} + +func TestIntegrationGetCurrentAgentRelease(t *testing.T) { + t.Parallel() + + client := newAgentIntegrationTestClient(t) + + agentName := AgentReleasesFilterTypes.GO + + getResult, err := client.GetCurrentAgentRelease(agentName) + require.NoError(t, err) + require.NotNil(t, getResult) + + require.NotNil(t, getResult.Bugs) + require.NotNil(t, getResult.Date) + require.NotNil(t, getResult.DownloadLink) + require.NotNil(t, getResult.EolDate) + require.NotNil(t, getResult.Features) + require.NotNil(t, getResult.Security) + require.NotNil(t, getResult.Slug) + require.NotNil(t, getResult.Version) +} + +func TestIntegrationGetCurrentAgentRelease_Invalid(t *testing.T) { + t.Parallel() + + client := newAgentIntegrationTestClient(t) + + var agentName AgentReleasesFilter = "ASDF" + + getResult, err := client.GetCurrentAgentRelease(agentName) + require.Error(t, err) + require.Nil(t, getResult) +} diff --git a/pkg/agent/types.go b/pkg/agent/types.go new file mode 100644 index 00000000..bf6df1e8 --- /dev/null +++ b/pkg/agent/types.go @@ -0,0 +1,96 @@ +// Code generated by tutone: DO NOT EDIT +package agent + +// AgentReleasesFilter - Agent Release Filter +type AgentReleasesFilter string + +var AgentReleasesFilterTypes = struct { + // Android agent + ANDROID AgentReleasesFilter + // Browser agent + BROWSER AgentReleasesFilter + // .NET agent + DOTNET AgentReleasesFilter + // Elixir agent + ELIXIR AgentReleasesFilter + // Go agent + GO AgentReleasesFilter + // Infrastructure agent + INFRASTRUCTURE AgentReleasesFilter + // iOS agent + IOS AgentReleasesFilter + // Java agent + JAVA AgentReleasesFilter + // Node.js agent + NODEJS AgentReleasesFilter + // PHP agent + PHP AgentReleasesFilter + // Python agent + PYTHON AgentReleasesFilter + // Ruby agent + RUBY AgentReleasesFilter + // C SDK + SDK AgentReleasesFilter +}{ + // Android agent + ANDROID: "ANDROID", + // Browser agent + BROWSER: "BROWSER", + // .NET agent + DOTNET: "DOTNET", + // Elixir agent + ELIXIR: "ELIXIR", + // Go agent + GO: "GO", + // Infrastructure agent + INFRASTRUCTURE: "INFRASTRUCTURE", + // iOS agent + IOS: "IOS", + // Java agent + JAVA: "JAVA", + // Node.js agent + NODEJS: "NODEJS", + // PHP agent + PHP: "PHP", + // Python agent + PYTHON: "PYTHON", + // Ruby agent + RUBY: "RUBY", + // C SDK + SDK: "SDK", +} + +// AgentReleasesAgentRelease - Information about an Agent release +type AgentReleasesAgentRelease struct { + // Patch for a bug + Bugs []string `json:"bugs,omitempty"` + // The date of the release + Date Date `json:"date,omitempty"` + // Link to agent distribution + DownloadLink string `json:"downloadLink,omitempty"` + // The date the release will reach the end of its life. See [New Relic's EOL Policy](https://docs.newrelic.com/docs/licenses/end-of-life/notification-changes-new-relic-saas-features-distributed-software/) for details + EolDate Date `json:"eolDate,omitempty"` + // New feature or instrumentation + Features []string `json:"features,omitempty"` + // Fix for a security vulnerability + Security []string `json:"security,omitempty"` + // The release note's location on the docs website. The full URL would be prefixed with [https://docs.newrelic.com](https://docs.newrelic.com/) + Slug string `json:"slug,omitempty"` + // The version of the release + Version string `json:"version,omitempty"` +} + +// DocumentationFields - +type DocumentationFields struct { + // View a list of all releases for the provided Agent + AgentReleases []AgentReleasesAgentRelease `json:"agentReleases,omitempty"` + // The current release of the provided Agent + CurrentAgentRelease AgentReleasesAgentRelease `json:"currentAgentRelease,omitempty"` +} + +type currentAgentReleaseResponse struct { + DocumentationFields DocumentationFields `json:"docs"` +} + +// Date - The `Date` scalar represents a date. The `Date` appears as an ISO8601 formatted string. +type Date string