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

Add component CRUD functions #511

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20250128-154352.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: Add aliases functions for CRUD components that use the old services CRUD functions
time: 2025-01-28T15:43:52.087885-06:00
4 changes: 4 additions & 0 deletions .changes/unreleased/Refactor-20250128-154312.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Refactor
body: 'BREAKING CHANGE: client.GetService now properly takes in an identifier and
calls the appropreate queries for alias or id'
time: 2025-01-28T15:43:12.187193-06:00
32 changes: 32 additions & 0 deletions component.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package opslevel

type Component Service

type ComponentCreateInput ServiceCreateInput

type ComponentUpdateInput ServiceUpdateInput

type ComponentConnection ServiceConnection

type ComponentTypeConnection struct {
Nodes []ComponentType `json:"nodes"`
PageInfo PageInfo `json:"pageInfo"`
Expand All @@ -20,6 +28,11 @@ func (client *Client) CreateComponentType(input ComponentTypeInput) (*ComponentT
return &m.Payload.ComponentType, HandleErrors(err, m.Payload.Errors)
}

func (client *Client) CreateComponent(input ComponentCreateInput) (*Component, error) {
resource, err := client.CreateService(ServiceCreateInput(input))
return any(resource).(*Component), err
}

func (client *Client) GetComponentType(identifier string) (*ComponentType, error) {
var q struct {
Account struct {
Expand All @@ -33,6 +46,11 @@ func (client *Client) GetComponentType(identifier string) (*ComponentType, error
return &q.Account.ComponentType, HandleErrors(err, nil)
}

func (client *Client) GetComponent(identifier string) (*Component, error) {
resource, err := client.GetService(identifier)
return any(resource).(*Component), err
}

func (client *Client) ListComponentTypes(variables *PayloadVariables) (*ComponentTypeConnection, error) {
var q struct {
Account struct {
Expand All @@ -58,6 +76,11 @@ func (client *Client) ListComponentTypes(variables *PayloadVariables) (*Componen
return &q.Account.ComponentTypes, nil
}

func (client *Client) ListComponents(variables *PayloadVariables) (*ComponentConnection, error) {
resource, err := client.ListServices(variables)
return any(resource).(*ComponentConnection), err
}

func (client *Client) UpdateComponentType(identifier string, input ComponentTypeInput) (*ComponentType, error) {
var m struct {
Payload struct {
Expand All @@ -73,6 +96,11 @@ func (client *Client) UpdateComponentType(identifier string, input ComponentType
return &m.Payload.ComponentType, HandleErrors(err, m.Payload.Errors)
}

func (client *Client) UpdateComponent(input ComponentUpdateInput) (*Component, error) {
resource, err := client.UpdateService(ServiceUpdateInput(input))
return any(resource).(*Component), err
}

func (client *Client) DeleteComponentType(identifier string) error {
var d struct {
Payload struct {
Expand All @@ -85,3 +113,7 @@ func (client *Client) DeleteComponentType(identifier string) error {
err := client.Mutate(&d, v, WithName("ComponentTypeDelete"))
return HandleErrors(err, d.Payload.Errors)
}

func (client *Client) DeleteComponent(identifier string) error {
return client.DeleteService(identifier)
}
12 changes: 10 additions & 2 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (service *Service) ReconcileAliases(client *Client, aliasesWanted []string)
_, createErr := client.CreateAliases(service.Id, aliasesToCreate)

// update service to reflect API updates
updatedService, getErr := client.GetService(service.Id)
updatedService, getErr := client.GetServiceId(service.Id)
if updatedService != nil {
service.Aliases = updatedService.Aliases
service.ManagedAliases = updatedService.ManagedAliases
Expand Down Expand Up @@ -358,7 +358,7 @@ func (client *Client) GetServiceWithAlias(alias string) (*Service, error) {
return &q.Account.Service, nil
}

func (client *Client) GetService(id ID) (*Service, error) {
func (client *Client) GetServiceId(id ID) (*Service, error) {
var q struct {
Account struct {
Service Service `graphql:"service(id: $service)"`
Expand All @@ -376,6 +376,14 @@ func (client *Client) GetService(id ID) (*Service, error) {
return &q.Account.Service, nil
}

func (client *Client) GetService(identifier string) (*Service, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we've been meaning to do this for a LONG time and with the 2025 release emmient - now is a good time to pull the trigger on this breaking change.

For opslevel-go using customers they won't automatically upgrade to this version so it won't break them because the v2025 release is like a "major" version change. So they'll have to explicitly upgrade and even then the go compiler should catch most of these changes

if IsID(identifier) {
return client.GetServiceId(ID(identifier))
} else {
return client.GetServiceWithAlias(identifier)
}
}

func (client *Client) GetServiceCount() (int, error) {
var q struct {
Account struct {
Expand Down
Loading