Skip to content

Commit

Permalink
feat: spaceID feeds support
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 committed Oct 12, 2023
1 parent dc2c8f5 commit 29f4e11
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_feeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ func dataSourceFeedsRead(ctx context.Context, d *schema.ResourceData, m interfac
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingFeeds, err := client.Feeds.Get(query)
existingFeeds, err := feeds.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
8 changes: 4 additions & 4 deletions octopusdeploy/resource_github_repository_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func resourceGitHubRepositoryFeedCreate(ctx context.Context, d *schema.ResourceD
tflog.Info(ctx, fmt.Sprintf("creating GitHub repository feed, %s", feed.GetName()))

client := m.(*client.Client)
createdGitHubRepositoryFeed, err := client.Feeds.Add(feed)
createdGitHubRepositoryFeed, err := feeds.Add(client, feed)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -52,7 +52,7 @@ func resourceGitHubRepositoryFeedDelete(ctx context.Context, d *schema.ResourceD
tflog.Info(ctx, fmt.Sprintf("deleting GitHub repository feed (%s)", d.Id()))

client := m.(*client.Client)
err := client.Feeds.DeleteByID(d.Id())
err := feeds.DeleteByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -67,7 +67,7 @@ func resourceGitHubRepositoryFeedRead(ctx context.Context, d *schema.ResourceDat
tflog.Info(ctx, fmt.Sprintf("reading GitHub repository feed (%s)", d.Id()))

client := m.(*client.Client)
feed, err := client.Feeds.GetByID(d.Id())
feed, err := feeds.GetByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "GitHub repository feed")
}
Expand All @@ -90,7 +90,7 @@ func resourceGitHubRepositoryFeedUpdate(ctx context.Context, d *schema.ResourceD
tflog.Info(ctx, fmt.Sprintf("updating GitHub repository feed (%s)", feed.GetID()))

client := m.(*client.Client)
updatedFeed, err := client.Feeds.Update(feed)
updatedFeed, err := feeds.Update(client, feed)
if err != nil {
return diag.FromErr(err)
}
Expand Down
8 changes: 4 additions & 4 deletions octopusdeploy/resource_helm_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func resourceHelmFeedCreate(ctx context.Context, d *schema.ResourceData, m inter
tflog.Info(ctx, fmt.Sprintf("creating Helm feed, %s", feed.GetName()))

client := m.(*client.Client)
createdFeed, err := client.Feeds.Add(feed)
createdFeed, err := feeds.Add(client, feed)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -52,7 +52,7 @@ func resourceHelmFeedDelete(ctx context.Context, d *schema.ResourceData, m inter
tflog.Info(ctx, fmt.Sprintf("deleting Helm feed (%s)", d.Id()))

client := m.(*client.Client)
err := client.Feeds.DeleteByID(d.Id())
err := feeds.DeleteByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -67,7 +67,7 @@ func resourceHelmFeedRead(ctx context.Context, d *schema.ResourceData, m interfa
tflog.Info(ctx, fmt.Sprintf("reading Helm feed (%s)", d.Id()))

client := m.(*client.Client)
feed, err := client.Feeds.GetByID(d.Id())
feed, err := feeds.GetByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "Helm feed")
}
Expand All @@ -90,7 +90,7 @@ func resourceHelmFeedUpdate(ctx context.Context, d *schema.ResourceData, m inter
tflog.Info(ctx, fmt.Sprintf("updating Helm feed (%s)", feed.GetID()))

client := m.(*client.Client)
updatedFeed, err := client.Feeds.Update(feed)
updatedFeed, err := feeds.Update(client, feed)
if err != nil {
return diag.FromErr(err)
}
Expand Down
8 changes: 4 additions & 4 deletions octopusdeploy/resource_maven_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func resourceMavenFeedCreate(ctx context.Context, d *schema.ResourceData, m inte
tflog.Info(ctx, fmt.Sprintf("creating Maven feed: %s", mavenFeed.GetName()))

client := m.(*client.Client)
createdFeed, err := client.Feeds.Add(mavenFeed)
createdFeed, err := feeds.Add(client, mavenFeed)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -52,7 +52,7 @@ func resourceMavenFeedDelete(ctx context.Context, d *schema.ResourceData, m inte
tflog.Info(ctx, fmt.Sprintf("deleting Maven feed (%s)", d.Id()))

client := m.(*client.Client)
err := client.Feeds.DeleteByID(d.Id())
err := feeds.DeleteByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -67,7 +67,7 @@ func resourceMavenFeedRead(ctx context.Context, d *schema.ResourceData, m interf
tflog.Info(ctx, fmt.Sprintf("reading Maven feed (%s)", d.Id()))

client := m.(*client.Client)
feed, err := client.Feeds.GetByID(d.Id())
feed, err := feeds.GetByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "Maven feed")
}
Expand All @@ -90,7 +90,7 @@ func resourceMavenFeedUpdate(ctx context.Context, d *schema.ResourceData, m inte
tflog.Info(ctx, fmt.Sprintf("updating Maven feed (%s)", feed.GetID()))

client := m.(*client.Client)
updatedFeed, err := client.Feeds.Update(feed)
updatedFeed, err := feeds.Update(client, feed)
if err != nil {
return diag.FromErr(err)
}
Expand Down
8 changes: 4 additions & 4 deletions octopusdeploy/resource_nuget_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func resourceNuGetFeedCreate(ctx context.Context, d *schema.ResourceData, m inte
tflog.Info(ctx, fmt.Sprintf("creating NuGet feed: %s", feed.GetName()))

client := m.(*client.Client)
createdFeed, err := client.Feeds.Add(feed)
createdFeed, err := feeds.Add(client, feed)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -52,7 +52,7 @@ func resourceNuGetFeedDelete(ctx context.Context, d *schema.ResourceData, m inte
tflog.Info(ctx, fmt.Sprintf("deleting NuGet feed (%s)", d.Id()))

client := m.(*client.Client)
err := client.Feeds.DeleteByID(d.Id())
err := feeds.DeleteByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -67,7 +67,7 @@ func resourceNuGetFeedRead(ctx context.Context, d *schema.ResourceData, m interf
tflog.Info(ctx, fmt.Sprintf("reading NuGet feed (%s)", d.Id()))

client := m.(*client.Client)
feed, err := client.Feeds.GetByID(d.Id())
feed, err := feeds.GetByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "NuGet feed")
}
Expand All @@ -90,7 +90,7 @@ func resourceNuGetFeedUpdate(ctx context.Context, d *schema.ResourceData, m inte
tflog.Info(ctx, fmt.Sprintf("updating NuGet feed (%s)", feed.GetID()))

client := m.(*client.Client)
updatedFeed, err := client.Feeds.Update(feed)
updatedFeed, err := feeds.Update(client, feed)
if err != nil {
return diag.FromErr(err)
}
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy/schema_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func getFeedDataSchema() map[string]*schema.Schema {
"partial_name": getQueryPartialName(),
"skip": getQuerySkip(),
"take": getQueryTake(),
"space_id": getSpaceIDSchema(),
}
}

Expand Down
18 changes: 11 additions & 7 deletions octopusdeploy/schema_helm_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func expandHelmFeed(d *schema.ResourceData) (*feeds.HelmFeed, error) {
helmFeed.Username = v.(string)
}

if v, ok := d.GetOk("space_id"); ok {
helmFeed.SpaceID = v.(string)
}

return helmFeed, nil
}

Expand Down Expand Up @@ -64,17 +68,17 @@ func getHelmFeedSchema() map[string]*schema.Schema {
}
}

func setHelmFeed(ctx context.Context, d *schema.ResourceData, mavenFeed *feeds.HelmFeed) error {
d.Set("feed_uri", mavenFeed.FeedURI)
d.Set("name", mavenFeed.Name)
d.Set("space_id", mavenFeed.SpaceID)
d.Set("username", mavenFeed.Username)
func setHelmFeed(ctx context.Context, d *schema.ResourceData, helmFeed *feeds.HelmFeed) error {
d.Set("feed_uri", helmFeed.FeedURI)
d.Set("name", helmFeed.Name)
d.Set("space_id", helmFeed.SpaceID)
d.Set("username", helmFeed.Username)

if err := d.Set("package_acquisition_location_options", mavenFeed.PackageAcquisitionLocationOptions); err != nil {
if err := d.Set("package_acquisition_location_options", helmFeed.PackageAcquisitionLocationOptions); err != nil {
return fmt.Errorf("error setting package_acquisition_location_options: %s", err)
}

d.SetId(mavenFeed.GetID())
d.SetId(helmFeed.GetID())

return nil
}

0 comments on commit 29f4e11

Please sign in to comment.