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

First pass of implementation for Aliasable Resources #483

Merged
merged 10 commits into from
Oct 22, 2024
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
4 changes: 4 additions & 0 deletions .changes/unreleased/Feature-20241021-150231.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Feature
body: Add new 'Aliasable' interface for working with resources that are allowed to
have aliases
time: 2024-10-21T15:02:31.932205-05:00
39 changes: 39 additions & 0 deletions aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,47 @@ package opslevel

import (
"errors"
"fmt"
)

type AliasableResourceInterface interface {
GetAliases() []string
ResourceId() ID
AliasableType() AliasOwnerTypeEnum
}

func (client *Client) GetAliasableResource(resourceType AliasOwnerTypeEnum, identifier string) (AliasableResourceInterface, error) {
rocktavious marked this conversation as resolved.
Show resolved Hide resolved
var err error
var aliasableResource AliasableResourceInterface

switch resourceType {
case AliasOwnerTypeEnumService:
if IsID(identifier) {
aliasableResource, err = client.GetService(ID(identifier))
} else {
aliasableResource, err = client.GetServiceWithAlias(identifier)
}
case AliasOwnerTypeEnumTeam:
if IsID(identifier) {
aliasableResource, err = client.GetTeam(ID(identifier))
} else {
aliasableResource, err = client.GetTeamWithAlias(identifier)
}
case AliasOwnerTypeEnumSystem:
aliasableResource, err = client.GetSystem(identifier)
case AliasOwnerTypeEnumDomain:
aliasableResource, err = client.GetDomain(identifier)
case AliasOwnerTypeEnumInfrastructureResource:
aliasableResource, err = client.GetInfrastructure(identifier)
case AliasOwnerTypeEnumScorecard:
aliasableResource, err = client.GetScorecard(identifier)
default:
err = fmt.Errorf("not an aliasable resource type '%s'", resourceType)
}

return aliasableResource, err
}

func (client *Client) CreateAliases(ownerId ID, aliases []string) ([]string, error) {
var output []string
var allErrors error
Expand Down
84 changes: 84 additions & 0 deletions aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,87 @@ func TestDeleteAliasNotFound(t *testing.T) {
t.Error("expected number of errors to be > 1")
}
}

func TestGetAliasableResource(t *testing.T) {
service := autopilot.Register[ol.ServiceId]("example_service",
ol.ServiceId{
Id: id1,
Aliases: []string{alias1, alias2, alias3},
},
)
team := autopilot.Register[ol.Team]("example_team",
ol.Team{
TeamId: ol.TeamId{
Id: id1,
},
Aliases: []string{alias1, alias2, alias4},
},
)
system := autopilot.Register[ol.SystemId]("example_system",
ol.SystemId{
Id: id1,
Aliases: []string{alias3},
})

requests := []autopilot.TestRequest{
autopilot.NewTestRequest(
`query ServiceGet($service:ID!){account{service(id: $service){{ template "service_get" }}}}}`,
`{"service": "{{ template "id1_string" }}"}`,
`{ "data": { "account": {"service": {{ template "example_service" }}}}}`,
),
autopilot.NewTestRequest(
`query ServiceGet($service:String!){account{service(alias: $service){{ template "service_get" }}}}}`,
`{"service": "{{ template "alias1" }}"}`,
`{ "data": { "account": {"service": {{ template "example_service" }}}}}`,
),
autopilot.NewTestRequest(
`query TeamGet($id:ID!){account{team(id: $id){{ template "team_get" }}}}`,
`{"id": "{{ template "id1_string" }}"}`,
`{ "data": { "account": {"team": {{ template "example_team" }}}}}`,
),
autopilot.NewTestRequest(
`query TeamGet($alias:String!){account{team(alias: $alias){{ template "team_get" }}}}`,
`{"alias": "{{ template "alias1" }}"}`,
`{ "data": { "account": {"team": {{ template "example_team" }}}}}`,
),
autopilot.NewTestRequest(
`query SystemGet($input:IdentifierInput!){account{system(input: $input){{ template "system_get" }}}}`,
`{"input": {"alias": "{{ template "alias1" }}"}}`,
`{ "data": { "account": {"system": {{ template "example_system"}}}}}`,
),
autopilot.NewTestRequest(
`{{ template "scorecard_get_request" }}`,
`{{ template "scorecard_get_request_vars" }}`,
`{{ template "scorecard_get_response" }}`,
),
autopilot.NewTestRequest(
`query InfrastructureResourceGet($all:Boolean!$input:IdentifierInput!){account{infrastructureResource(input: $input){{ template "infra_get" }}}}`,
`{"all": true, "input":{ {{ template "id1" }} }}`,
`{"data": { "account": { "infrastructureResource": {{ template "infra_1" }} }}}`,
),
}
client := BestTestClient(t, "tags/get_aliasable_resource", requests...)
// Act
service1, err1 := client.GetAliasableResource(ol.AliasOwnerTypeEnumService, string(id1))
service2, err2 := client.GetAliasableResource(ol.AliasOwnerTypeEnumService, alias1)
team1, err3 := client.GetAliasableResource(ol.AliasOwnerTypeEnumTeam, string(id1))
team2, err4 := client.GetAliasableResource(ol.AliasOwnerTypeEnumTeam, alias1)
system1, err5 := client.GetAliasableResource(ol.AliasOwnerTypeEnumSystem, alias1)
scorecard1, err6 := client.GetAliasableResource(ol.AliasOwnerTypeEnumScorecard, scorecardId)
infra1, err7 := client.GetAliasableResource(ol.AliasOwnerTypeEnumInfrastructureResource, string(id1))
// Assert
autopilot.Ok(t, err1)
autopilot.Equals(t, service.Aliases, service1.GetAliases())
autopilot.Ok(t, err2)
autopilot.Equals(t, service.Aliases, service2.GetAliases())
autopilot.Ok(t, err3)
autopilot.Equals(t, team.Aliases, team1.GetAliases())
autopilot.Ok(t, err4)
autopilot.Equals(t, team.Aliases, team2.GetAliases())
autopilot.Ok(t, err5)
autopilot.Equals(t, system.Aliases, system1.GetAliases())
autopilot.Ok(t, err6)
autopilot.Equals(t, []string{"existing_scorecard"}, scorecard1.GetAliases())
autopilot.Ok(t, err7)
autopilot.Equals(t, []string{}, infra1.GetAliases())
}
15 changes: 15 additions & 0 deletions clientGQL_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ var (
id2 = ol.ID(dataTemplater.ParseValue("id2_string"))
id3 = ol.ID(dataTemplater.ParseValue("id3_string"))
id4 = ol.ID(dataTemplater.ParseValue("id4_string"))
alias1 = dataTemplater.ParseValue("alias1")
alias2 = dataTemplater.ParseValue("alias2")
alias3 = dataTemplater.ParseValue("alias3")
alias4 = dataTemplater.ParseValue("alias4")
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -128,7 +132,18 @@ func (testDataTemplater *TestDataTemplater) ParseTemplatedString(contents string
return strings.TrimSpace(data.String())
}

func stripWhitespace(input string) string {
rocktavious marked this conversation as resolved.
Show resolved Hide resolved
// Remove newlines, tabs, and spaces
input = strings.ReplaceAll(input, "\n", "")
input = strings.ReplaceAll(input, "\t", "")
input = strings.ReplaceAll(input, " ", "")
return input
}

func BestTestClient(t *testing.T, endpoint string, requests ...autopilot.TestRequest) *ol.Client {
for i, request := range requests {
requests[i].Request.Query = stripWhitespace(request.Request.Query)
}
urlToRegister := fmt.Sprintf("/LOCAL_TESTING/%s", endpoint)
registeredUrl := autopilot.RegisterPaginatedEndpoint(t, urlToRegister, requests...)
return ol.NewGQLClient(ol.SetAPIToken("x"), ol.SetMaxRetries(0), ol.SetURL(registeredUrl))
Expand Down
8 changes: 8 additions & 0 deletions domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func (domainId *DomainId) GetTags(client *Client, variables *PayloadVariables) (
return &q.Account.Domain.Tags, nil
}

func (domainId *DomainId) GetAliases() []string {
return domainId.Aliases
}

func (domainId *DomainId) ResourceId() ID {
return domainId.Id
}
Expand All @@ -99,6 +103,10 @@ func (domainId *DomainId) ResourceType() TaggableResource {
return TaggableResourceDomain
}

func (DomainId *DomainId) AliasableType() AliasOwnerTypeEnum {
return AliasOwnerTypeEnumDomain
}

func (domainId *DomainId) ChildSystems(client *Client, variables *PayloadVariables) (*SystemConnection, error) {
var q struct {
Account struct {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/go-playground/validator/v10 v10.22.1
github.com/go-resty/resty/v2 v2.15.3
github.com/gosimple/slug v1.14.0
github.com/graph-gophers/graphql-go v1.5.0
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/hasura/go-graphql-client v0.13.1
github.com/mitchellh/mapstructure v1.5.0
Expand Down
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSC
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
Expand All @@ -17,6 +18,9 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
Expand All @@ -28,6 +32,7 @@ github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaC
github.com/go-resty/resty/v2 v2.15.3 h1:bqff+hcqAflpiF591hhJzNdkRsFhlB96CYfBwSFvql8=
github.com/go-resty/resty/v2 v2.15.3/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand All @@ -36,6 +41,8 @@ github.com/gosimple/slug v1.14.0 h1:RtTL/71mJNDfpUbCOmnf/XFkzKRtD6wL6Uy+3akm4Es=
github.com/gosimple/slug v1.14.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
github.com/graph-gophers/graphql-go v1.5.0 h1:fDqblo50TEpD0LY7RXk/LFVYEVqo3+tXMNMPSVXA1yc=
github.com/graph-gophers/graphql-go v1.5.0/go.mod h1:YtmJZDLbF1YYNrlNAuiO5zAStUWc3XZT07iGsVqe1Os=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
Expand Down Expand Up @@ -64,6 +71,7 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/opslevel/moredefaults v0.0.0-20240112142637-078c8ff8ba9c h1:m4sNHcfkE02xZy1oxF2QVGfhHulamxw9UlzRM7c45QQ=
github.com/opslevel/moredefaults v0.0.0-20240112142637-078c8ff8ba9c/go.mod h1:g2GSXVP6LO+5+AIsnMRPN+BeV86OXuFRTX7HXCDtYeI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -83,8 +91,13 @@ github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.6.3/go.mod h1:7BgNga5fNlF/iZjG06hM3yofffp0ofKCDwSXx1GC4dI=
go.opentelemetry.io/otel/trace v1.6.3/go.mod h1:GNJQusJlUgZl9/TQBPKU/Y/ty+0iVB5fjhKeJGZPGFs=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
Expand All @@ -98,6 +111,8 @@ golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 8 additions & 0 deletions infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func (infrastructureResource *InfrastructureResource) GetTags(client *Client, va
return &q.Account.InfrastructureResource.Tags, nil
}

func (infrastructureResource *InfrastructureResource) GetAliases() []string {
return infrastructureResource.Aliases
}

func (infrastructureResource *InfrastructureResource) ResourceId() ID {
return *NewID(infrastructureResource.Id)
}
Expand All @@ -117,6 +121,10 @@ func (infrastructureResource *InfrastructureResource) ResourceType() TaggableRes
return TaggableResourceInfrastructureresource
}

func (infrastructureResource *InfrastructureResource) AliasableType() AliasOwnerTypeEnum {
return AliasOwnerTypeEnumInfrastructureResource
}

func (client *Client) CreateInfrastructure(input InfraInput) (*InfrastructureResource, error) {
i := InfrastructureResourceInput{
Schema: &InfrastructureResourceSchemaInput{Type: input.Schema},
Expand Down
2 changes: 1 addition & 1 deletion infra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestCreateInfra(t *testing.T) {
func TestGetInfra(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query InfrastructureResourceGet($all:Boolean!$input:IdentifierInput!){account{infrastructureResource(input: $input){id,aliases,name,type @include(if: $all),providerResourceType @include(if: $all),providerData @include(if: $all){accountName,externalUrl,providerName},owner @include(if: $all){... on Team{teamAlias:alias,id}},ownerLocked @include(if: $all),data @include(if: $all),rawData @include(if: $all)}}}`,
`query InfrastructureResourceGet($all:Boolean!$input:IdentifierInput!){account{infrastructureResource(input: $input){{ template "infra_get" }}}}`,
`{"all": true, "input":{ {{ template "id1" }} }}`,
`{"data": { "account": { "infrastructureResource": {{ template "infra_1" }} }}}`,
)
Expand Down
4 changes: 2 additions & 2 deletions scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (id *ID) MarshalJSON() ([]byte, error) {
}

type Identifier struct {
Id ID `graphql:"id"`
Aliases []string `graphql:"aliases"`
Id ID `graphql:"id" json:"id"`
Aliases []string `graphql:"aliases" json:"aliases"`
}

func (identifierInput IdentifierInput) MarshalJSON() ([]byte, error) {
Expand Down
12 changes: 12 additions & 0 deletions scorecards.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ type ScorecardCategoryConnection struct {
TotalCount int `graphql:"totalCount"`
}

func (scorecard *ScorecardId) ResourceId() ID {
return scorecard.Id
}

func (scorecard *ScorecardId) AliasableType() AliasOwnerTypeEnum {
return AliasOwnerTypeEnumScorecard
}

func (scorecard *ScorecardId) GetAliases() []string {
return scorecard.Aliases
}

func (scorecard *ScorecardId) ReconcileAliases(client *Client, aliasesWanted []string) error {
aliasesToCreate, aliasesToDelete := extractAliases(scorecard.Aliases, aliasesWanted)

Expand Down
8 changes: 8 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (service *Service) ResourceType() TaggableResource {
return TaggableResourceService
}

func (service *Service) AliasableType() AliasOwnerTypeEnum {
return AliasOwnerTypeEnumService
}

func (service *Service) HasAlias(alias string) bool {
for _, a := range service.Aliases {
if a == alias {
Expand Down Expand Up @@ -198,6 +202,10 @@ func (service *Service) GetTags(client *Client, variables *PayloadVariables) (*T
return service.Tags, nil
}

func (service *Service) GetAliases() []string {
return service.Aliases
}

func (service *Service) GetTools(client *Client, variables *PayloadVariables) (*ToolConnection, error) {
var q struct {
Account struct {
Expand Down
2 changes: 1 addition & 1 deletion service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func TestGetServiceWithAlias(t *testing.T) {
func TestGetService(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query ServiceGet($service:ID!){account{service(id: $service){apiDocumentPath,description,framework,htmlUrl,id,aliases,language,lifecycle{alias,description,id,index,name},locked,managedAliases,name,note,owner{alias,id},parent{id,aliases},preferredApiDocument{id,htmlUrl,source{... on ApiDocIntegration{id,name,type},... on ServiceRepository{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},timestamps{createdAt,updatedAt}},preferredApiDocumentSource,product,repos{edges{node{id,defaultAlias},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }},totalCount},defaultServiceRepository{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}},tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount},tier{alias,description,id,index,name},timestamps{createdAt,updatedAt},tools{nodes{category,categoryAlias,displayName,environment,id,url,service{id,aliases}},{{ template "pagination_request" }},totalCount}}}}`,
`query ServiceGet($service:ID!){account{service(id: $service){{ template "service_get" }}}}}`,
`{ "service": "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS81MzEx" }`,
`{ "data": {
"account": {
Expand Down
8 changes: 8 additions & 0 deletions system.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (systemId *SystemId) GetTags(client *Client, variables *PayloadVariables) (
return &q.Account.System.Tags, nil
}

func (systemId *SystemId) GetAliases() []string {
return systemId.Aliases
}

func (systemId *SystemId) ResourceId() ID {
return systemId.Id
}
Expand All @@ -70,6 +74,10 @@ func (systemId *SystemId) ResourceType() TaggableResource {
return TaggableResourceSystem
}

func (systemId *SystemId) AliasableType() AliasOwnerTypeEnum {
return AliasOwnerTypeEnumSystem
}

// Returns unique identifiers created by OpsLevel, values in Aliases but not ManagedAliases
func (system *System) UniqueIdentifiers() []string {
uniqueIdentifiers := []string{}
Expand Down
2 changes: 1 addition & 1 deletion system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestSystemAssignService(t *testing.T) {
func TestSystemGetId(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query SystemGet($input:IdentifierInput!){account{system(input: $input){id,aliases,managedAliases,name,description,htmlUrl,owner{... on Team{teamAlias:alias,id}},parent{id,aliases,description,htmlUrl,managedAliases,name,note,owner{... on Team{teamAlias:alias,id}}},note}}}`,
`query SystemGet($input:IdentifierInput!){account{system(input: $input){{ template "system_get" }}}}`,
`{ "input": { {{ template "id1" }} } }`,
`{"data": { "account": { "system": {{ template "system1_response" }} }}}`,
)
Expand Down
Loading
Loading