Skip to content

Commit

Permalink
Set source_repo_url on catalog types if passed as param
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethMRichardson committed Mar 12, 2024
1 parent ee40d75 commit a969bd8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
11 changes: 10 additions & 1 deletion client/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions client/openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -5660,6 +5660,11 @@
"description": "When this type was last updated",
"example": "2021-08-17T13:28:57.801578Z",
"format": "date-time"
},
"source_repo_url": {
"type": "string",
"description": "The url of the external repository where this type is managed",
"example": "https://github.com/incident-io/catalog-importer"
}
},
"example": {
Expand Down Expand Up @@ -5692,7 +5697,8 @@
},
"semantic_type": "custom",
"type_name": "Custom[\"BackstageGroup\"]",
"updated_at": "2021-08-17T13:28:57.801578Z"
"updated_at": "2021-08-17T13:28:57.801578Z",
"source_repo_url": "https://github.com/incident-io/catalog-importer"
},
"required": [
"id",
Expand Down Expand Up @@ -6567,6 +6573,11 @@
"type": "string",
"description": "The type name of this catalog type, to be used when defining attributes. This is immutable once a CatalogType has been created. For non-externally sync types, it must follow the pattern Custom[\"SomeName \"]",
"example": "Custom[\"BackstageGroup\"]"
},
"source_repo_url": {
"type": "string",
"description": "The url of the external repository where this type is managed",
"example": "https://github.com/incident-io/catalog-importer"
}
},
"example": {
Expand All @@ -6579,7 +6590,8 @@
"name": "Kubernetes Cluster",
"ranked": true,
"semantic_type": "custom",
"type_name": "Custom[\"BackstageGroup\"]"
"type_name": "Custom[\"BackstageGroup\"]",
"source_repo_url": "https://github.com/incident-io/catalog-importer"
},
"required": [
"name",
Expand Down Expand Up @@ -11550,6 +11562,11 @@
"type": "string",
"description": "Semantic type of this resource",
"example": "custom"
},
"source_repo_url": {
"type": "string",
"description": "The url of the external repository where this type is managed",
"example": "https://github.com/incident-io/catalog-importer"
}
},
"example": {
Expand All @@ -11561,7 +11578,8 @@
"icon": "bolt",
"name": "Kubernetes Cluster",
"ranked": true,
"semantic_type": "custom"
"semantic_type": "custom",
"source_repo_url": "https://github.com/incident-io/catalog-importer"
},
"required": [
"name",
Expand Down
33 changes: 20 additions & 13 deletions cmd/catalog-importer/cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type SyncOptions struct {
DryRun bool
Prune bool
AllowDeleteAll bool
SourceRepoUrl string
}

func (opt *SyncOptions) Bind(cmd *kingpin.CmdClause) *SyncOptions {
Expand All @@ -43,6 +44,9 @@ func (opt *SyncOptions) Bind(cmd *kingpin.CmdClause) *SyncOptions {
cmd.Flag("api-key", "API key for incident.io").
Envar("INCIDENT_API_KEY").
StringVar(&opt.APIKey)
cmd.Flag("source-repo-url", "URL of repo where catalog is being managed").
Envar("SOURCE_REPO_URL").
StringVar(&opt.SourceRepoUrl)
cmd.Flag("target", `Restrict running to only these outputs (e.g. Custom["Customer"])`).
StringsVar(&opt.Targets)
cmd.Flag("sample-length", "How many character to sample when logging about invalid source entries (for --debug only)").
Expand Down Expand Up @@ -187,19 +191,21 @@ func (opt *SyncOptions) Run(ctx context.Context, logger kitlog.Logger, cfg *conf
if opt.DryRun {
logger.Log("msg", "catalog type does not already exist, simulating create for --dry-run")
createdCatalogType = client.CatalogTypeV2{
Id: fmt.Sprintf("DRY-RUN-%s", model.TypeName),
Name: model.Name,
Description: model.Description,
TypeName: model.TypeName,
Id: fmt.Sprintf("DRY-RUN-%s", model.TypeName),
Name: model.Name,
Description: model.Description,
TypeName: model.TypeName,
SourceRepoUrl: &opt.SourceRepoUrl,
}
} else {
logger.Log("msg", "catalog type does not already exist, creating")
result, err := cl.CatalogV2CreateTypeWithResponse(ctx, client.CreateTypeRequestBody{
Name: model.Name,
Description: model.Description,
Ranked: &model.Ranked,
TypeName: lo.ToPtr(model.TypeName),
Annotations: lo.ToPtr(getAnnotations(cfg.SyncID)),
Name: model.Name,
Description: model.Description,
Ranked: &model.Ranked,
TypeName: lo.ToPtr(model.TypeName),
Annotations: lo.ToPtr(getAnnotations(cfg.SyncID)),
SourceRepoUrl: &opt.SourceRepoUrl,
})
if err != nil {
return errors.Wrap(err, fmt.Sprintf("creating catalog type with name %s", model.TypeName))
Expand Down Expand Up @@ -263,10 +269,11 @@ func (opt *SyncOptions) Run(ctx context.Context, logger kitlog.Logger, cfg *conf
} else {
logger.Log("msg", "updating catalog type", "catalog_type_id", catalogType.Id)
result, err := cl.CatalogV2UpdateTypeWithResponse(ctx, catalogType.Id, client.CatalogV2UpdateTypeJSONRequestBody{
Name: model.Name,
Description: model.Description,
Ranked: &model.Ranked,
Annotations: lo.ToPtr(getAnnotations(cfg.SyncID)),
Name: model.Name,
Description: model.Description,
Ranked: &model.Ranked,
Annotations: lo.ToPtr(getAnnotations(cfg.SyncID)),
SourceRepoUrl: &opt.SourceRepoUrl,
})
if err != nil {
return errors.Wrap(err, fmt.Sprintf("updating catalog type with name %s", model.TypeName))
Expand Down
1 change: 1 addition & 0 deletions output/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type CatalogTypeModel struct {
Ranked bool
Attributes []client.CatalogTypeAttributePayloadV2
SourceAttribute *Attribute // tracks the origin attribute, if an enum model
SourceRepoUrl string
}

type CatalogEntryModel struct {
Expand Down

0 comments on commit a969bd8

Please sign in to comment.