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 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
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
22 changes: 6 additions & 16 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type CustomActionsTriggerDefinitionsConnection struct {

func (client *Client) CreateWebhookAction(input CustomActionsWebhookActionCreateInput) (*CustomActionsExternalAction, error) {
var m struct {
Payload struct {
Payload struct { // TODO: fix this
WebhookAction CustomActionsExternalAction
Errors []Error
} `graphql:"customActionsWebhookActionCreate(input: $input)"`
Expand Down Expand Up @@ -110,7 +110,7 @@ func (client *Client) ListCustomActions(variables *PayloadVariables) (*CustomAct

func (client *Client) UpdateWebhookAction(input CustomActionsWebhookActionUpdateInput) (*CustomActionsExternalAction, error) {
var m struct {
Payload struct {
Payload struct { // TODO: fix this
WebhookAction CustomActionsExternalAction
Errors []Error
} `graphql:"customActionsWebhookActionUpdate(input: $input)"`
Expand All @@ -124,9 +124,7 @@ func (client *Client) UpdateWebhookAction(input CustomActionsWebhookActionUpdate

func (client *Client) DeleteWebhookAction(input string) error {
var m struct {
Payload struct {
Errors []Error `graphql:"errors"`
} `graphql:"customActionsWebhookActionDelete(resource: $input)"`
Payload BasePayload `graphql:"customActionsWebhookActionDelete(resource: $input)"`
}
v := PayloadVariables{
"input": *NewIdentifier(input),
Expand All @@ -137,10 +135,7 @@ func (client *Client) DeleteWebhookAction(input string) error {

func (client *Client) CreateTriggerDefinition(input CustomActionsTriggerDefinitionCreateInput) (*CustomActionsTriggerDefinition, error) {
var m struct {
Payload struct {
TriggerDefinition CustomActionsTriggerDefinition
Errors []Error
} `graphql:"customActionsTriggerDefinitionCreate(input: $input)"`
Payload CustomActionsTriggerDefinitionCreatePayload `graphql:"customActionsTriggerDefinitionCreate(input: $input)"`
}
if input.AccessControl == nil {
input.AccessControl = &CustomActionsTriggerDefinitionAccessControlEnumEveryone
Expand Down Expand Up @@ -198,10 +193,7 @@ func (client *Client) ListTriggerDefinitions(variables *PayloadVariables) (*Cust

func (client *Client) UpdateTriggerDefinition(input CustomActionsTriggerDefinitionUpdateInput) (*CustomActionsTriggerDefinition, error) {
var m struct {
Payload struct {
TriggerDefinition CustomActionsTriggerDefinition
Errors []Error
} `graphql:"customActionsTriggerDefinitionUpdate(input: $input)"`
Payload CustomActionsTriggerDefinitionUpdatePayload `graphql:"customActionsTriggerDefinitionUpdate(input: $input)"`
}
v := PayloadVariables{
"input": input,
Expand All @@ -212,9 +204,7 @@ func (client *Client) UpdateTriggerDefinition(input CustomActionsTriggerDefiniti

func (client *Client) DeleteTriggerDefinition(input string) error {
var m struct {
Payload struct {
Errors []Error `graphql:"errors"`
} `graphql:"customActionsTriggerDefinitionDelete(resource: $input)"`
Payload BasePayload `graphql:"customActionsTriggerDefinitionDelete(resource: $input)"`
}
v := PayloadVariables{
"input": *NewIdentifier(input),
Expand Down
9 changes: 2 additions & 7 deletions alert_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ func NewAlertSource(kind AlertSourceTypeEnum, id string) *AlertSourceExternalIde

func (client *Client) CreateAlertSourceService(input AlertSourceServiceCreateInput) (*AlertSourceService, error) {
var m struct {
Payload struct {
AlertSourceService AlertSourceService
Errors []Error
} `graphql:"alertSourceServiceCreate(input: $input)"`
Payload AlertSourceServiceCreatePayload `graphql:"alertSourceServiceCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
Expand Down Expand Up @@ -56,9 +53,7 @@ func (client *Client) GetAlertSource(id ID) (*AlertSource, error) {

func (client *Client) DeleteAlertSourceService(id ID) error {
var m struct {
Payload struct {
Errors []Error
} `graphql:"alertSourceServiceDelete(input: $input)"`
Payload BasePayload `graphql:"alertSourceServiceDelete(input: $input)"`
}
v := PayloadVariables{
"input": AlertSourceDeleteInput{Id: id},
Expand Down
14 changes: 5 additions & 9 deletions aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (client *Client) GetAliasableResource(resourceType AliasOwnerTypeEnum, iden
switch resourceType {
case AliasOwnerTypeEnumService:
if IsID(identifier) {
aliasableResource, err = client.GetService(ID(identifier))
aliasableResource, err = client.GetService(identifier)
} else {
aliasableResource, err = client.GetServiceWithAlias(identifier)
}
Expand Down Expand Up @@ -61,11 +61,7 @@ func (client *Client) CreateAliases(ownerId ID, aliases []string) ([]string, err

func (client *Client) CreateAlias(input AliasCreateInput) ([]string, error) {
var m struct {
Payload struct {
Aliases []string
OwnerId string
Errors []Error
} `graphql:"aliasCreate(input: $input)"`
Payload AliasCreatePayload `graphql:"aliasCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
Expand Down Expand Up @@ -116,9 +112,9 @@ func (client *Client) DeleteAliases(aliasOwnerType AliasOwnerTypeEnum, aliases [

func (client *Client) DeleteAlias(input AliasDeleteInput) error {
var m struct {
Payload struct {
Alias string `graphql:"deletedAlias"`
Errors []Error
Payload struct { // TODO: we don't need this but removing it breaks alot of tests
Alias string `graphql:"deletedAlias"`
BasePayload
} `graphql:"aliasDelete(input: $input)"`
}
v := PayloadVariables{
Expand Down
16 changes: 5 additions & 11 deletions category.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ func (category *Category) Alias() string {

func (client *Client) CreateCategory(input CategoryCreateInput) (*Category, error) {
var m struct {
Payload struct {
Category Category
Errors []Error
} `graphql:"categoryCreate(input: $input)"`
Payload CategoryCreatePayload `graphql:"categoryCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
Expand Down Expand Up @@ -79,10 +76,7 @@ func (client *Client) ListCategories(variables *PayloadVariables) (*CategoryConn

func (client *Client) UpdateCategory(input CategoryUpdateInput) (*Category, error) {
var m struct {
Payload struct {
Category Category
Errors []Error
} `graphql:"categoryUpdate(input: $input)"`
Payload CategoryUpdatePayload `graphql:"categoryUpdate(input: $input)"`
}
v := PayloadVariables{
"input": input,
Expand All @@ -93,9 +87,9 @@ func (client *Client) UpdateCategory(input CategoryUpdateInput) (*Category, erro

func (client *Client) DeleteCategory(id ID) error {
var m struct {
Payload struct {
Id ID `graphql:"deletedCategoryId"`
Errors []Error
Payload struct { // TODO: we don't need this but removing it breaks alot of tests
Id ID `graphql:"deletedCategoryId"`
BasePayload
} `graphql:"categoryDelete(input: $input)"`
}
v := PayloadVariables{
Expand Down
10 changes: 1 addition & 9 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ func NewCheckUpdateInputTypeOf[T any](checkUpdateInput CheckUpdateInput) *T {
return newCheck
}

// CheckResponsePayload encompasses CheckCreatePayload and CheckUpdatePayload into 1 struct
type CheckResponsePayload struct {
Check Check
Errors []Error
}

func (client *Client) CreateCheck(input any) (*Check, error) {
switch v := input.(type) {
case *CheckAlertSourceUsageCreateInput:
Expand Down Expand Up @@ -265,9 +259,7 @@ func (client *Client) UpdateCheck(input any) (*Check, error) {

func (client *Client) DeleteCheck(id ID) error {
var m struct {
Payload struct {
Errors []Error
} `graphql:"checkDelete(input: $input)"`
Payload BasePayload `graphql:"checkDelete(input: $input)"`
}
v := PayloadVariables{
"input": CheckDeleteInput{Id: RefOf(id)},
Expand Down
46 changes: 35 additions & 11 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 @@ -8,10 +16,7 @@ type ComponentTypeConnection struct {

func (client *Client) CreateComponentType(input ComponentTypeInput) (*ComponentType, error) {
var m struct {
Payload struct {
ComponentType ComponentType
Errors []Error
} `graphql:"componentTypeCreate(input:$input)"`
Payload ComponentTypePayload `graphql:"componentTypeCreate(input:$input)"`
}
v := PayloadVariables{
"input": input,
Expand All @@ -20,6 +25,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 +43,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,12 +73,14 @@ 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 {
ComponentType ComponentType
Errors []Error
} `graphql:"componentTypeUpdate(componentType:$target,input:$input)"`
Payload ComponentTypePayload `graphql:"componentTypeUpdate(componentType:$target,input:$input)"`
}
v := PayloadVariables{
"target": *NewIdentifier(identifier),
Expand All @@ -73,15 +90,22 @@ 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 {
Errors []Error `graphql:"errors"`
} `graphql:"componentTypeDelete(resource:$target)"`
Payload BasePayload `graphql:"componentTypeDelete(resource:$target)"`
}
v := PayloadVariables{
"target": *NewIdentifier(identifier),
}
err := client.Mutate(&d, v, WithName("ComponentTypeDelete"))
return HandleErrors(err, d.Payload.Errors)
}

func (client *Client) DeleteComponent(identifier string) error {
return client.DeleteService(identifier)
}
11 changes: 3 additions & 8 deletions dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ type ServiceDependentsConnection struct {

func (client *Client) CreateServiceDependency(input ServiceDependencyCreateInput) (*ServiceDependency, error) {
var m struct {
Payload struct {
ServiceDependency *ServiceDependency
Errors []Error
} `graphql:"serviceDependencyCreate(inputV2: $input)"`
Payload ServiceDependencyPayload `graphql:"serviceDependencyCreate(inputV2: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("ServiceDependencyCreate"))
return m.Payload.ServiceDependency, HandleErrors(err, m.Payload.Errors)
return &m.Payload.ServiceDependency, HandleErrors(err, m.Payload.Errors)
}

func (service *Service) GetDependencies(client *Client, variables *PayloadVariables) (*ServiceDependenciesConnection, error) {
Expand Down Expand Up @@ -115,9 +112,7 @@ func (service *Service) GetDependents(client *Client, variables *PayloadVariable

func (client *Client) DeleteServiceDependency(id ID) error {
var m struct {
Payload struct {
Errors []Error
} `graphql:"serviceDependencyDelete(input: $input)"`
Payload BasePayload `graphql:"serviceDependencyDelete(input: $input)"`
}
v := PayloadVariables{
"input": DeleteInput{Id: id},
Expand Down
5 changes: 1 addition & 4 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ type ServiceDocumentContent struct {

func (client *Client) ServiceApiDocSettingsUpdate(service string, docPath string, docSource *ApiDocumentSourceEnum) (*Service, error) {
var m struct {
Payload struct {
Service Service
Errors []Error
} `graphql:"serviceApiDocSettingsUpdate(service: $service, apiDocumentPath: $docPath, preferredApiDocumentSource: $docSource)"`
Payload ServiceUpdatePayload `graphql:"serviceApiDocSettingsUpdate(service: $service, apiDocumentPath: $docPath, preferredApiDocumentSource: $docSource)"`
}
v := PayloadVariables{
"service": *NewIdentifier(service),
Expand Down
19 changes: 4 additions & 15 deletions domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ func (domainId *DomainId) ChildSystems(client *Client, variables *PayloadVariabl

func (domainId *DomainId) AssignSystem(client *Client, systems ...string) error {
var m struct {
Payload struct {
Domain Domain
Errors []Error
} `graphql:"domainChildAssign(domain:$domain, childSystems:$childSystems)"`
Payload DomainPayload `graphql:"domainChildAssign(domain:$domain, childSystems:$childSystems)"`
}
v := PayloadVariables{
"domain": *NewIdentifier(string(domainId.Id)),
Expand All @@ -144,10 +141,7 @@ func (domainId *DomainId) AssignSystem(client *Client, systems ...string) error

func (client *Client) CreateDomain(input DomainInput) (*Domain, error) {
var m struct {
Payload struct {
Domain Domain
Errors []Error
} `graphql:"domainCreate(input:$input)"`
Payload DomainPayload `graphql:"domainCreate(input:$input)"`
}
v := PayloadVariables{
"input": input,
Expand Down Expand Up @@ -196,10 +190,7 @@ func (client *Client) ListDomains(variables *PayloadVariables) (*DomainConnectio

func (client *Client) UpdateDomain(identifier string, input DomainInput) (*Domain, error) {
var m struct {
Payload struct {
Domain Domain
Errors []Error
} `graphql:"domainUpdate(domain:$domain,input:$input)"`
Payload DomainPayload `graphql:"domainUpdate(domain:$domain,input:$input)"`
}
v := PayloadVariables{
"domain": *NewIdentifier(identifier),
Expand All @@ -211,9 +202,7 @@ func (client *Client) UpdateDomain(identifier string, input DomainInput) (*Domai

func (client *Client) DeleteDomain(identifier string) error {
var d struct {
Payload struct {
Errors []Error `graphql:"errors"`
} `graphql:"domainDelete(resource: $input)"`
Payload BasePayload `graphql:"domainDelete(resource: $input)"`
}
v := PayloadVariables{
"input": *NewIdentifier(identifier),
Expand Down
Loading
Loading