Skip to content

Commit

Permalink
feat: Add support for OCI Registry feeds (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
denys-octopus authored Oct 17, 2024
1 parent 376f033 commit 1d2223a
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/feeds/feed_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ const (
FeedTypeOctopusProject = FeedType("OctopusProject")
FeedTypeArtifactoryGeneric = FeedType("ArtifactoryGeneric")
FeedTypeS3 = FeedType("S3")
FeedTypeOCIRegistry = FeedType("OciRegistry")
)
7 changes: 7 additions & 0 deletions pkg/feeds/feed_utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func ToFeed(feedResource *FeedResource) (IFeed, error) {
return nil, err
}
feed = s3Feed
case FeedTypeOCIRegistry:
ociFeed, err := NewOCIRegistryFeed(feedResource.GetName())
if err != nil {
return nil, err
}
ociFeed.FeedURI = feedResource.FeedURI
feed = ociFeed
default:
return nil, errors.New("unknown feed type: " + fmt.Sprint(feedResource.GetFeedType()))
}
Expand Down
47 changes: 46 additions & 1 deletion pkg/feeds/feed_utilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ func TestMaven(t *testing.T) {
if typedFeed.FeedURI != "http://example.com" {
t.Fatalf("FeedURI does not match")
}

}

func TestNuget(t *testing.T) {
Expand Down Expand Up @@ -543,3 +542,49 @@ func TestS3(t *testing.T) {
t.Fatalf("UseMachineCredentials does not match")
}
}

func TestOCIRegistry(t *testing.T) {
feedResource := FeedResource{
AccessKey: "",
APIVersion: "test",
DeleteUnreleasedPackagesAfterDays: 10,
DownloadAttempts: 5,
DownloadRetryBackoffSeconds: 3,
EnhancedMode: false,
FeedType: FeedTypeOCIRegistry,
FeedURI: "oci://test-registry.docker.io",
IsBuiltInRepoSyncEnabled: true,
Name: "Test Registry",
Password: core.NewSensitiveValue("test-password"),
PackageAcquisitionLocationOptions: nil,
Region: "",
RegistryPath: "",
SecretKey: nil,
SpaceID: "",
Username: "test-username",
LayoutRegex: "",
Repository: "",
UseMachineCredentials: false,
Resource: resources.Resource{},
}

feed, err := ToFeed(&feedResource)

if err != nil {
t.Fatalf("Error should not have been returned. %s", err)
}

typedFeed := feed.(*OCIRegistryFeed)

if typedFeed.Name != "Test Registry" {
t.Fatalf("Name does not match")
}

if typedFeed.FeedURI != "oci://test-registry.docker.io" {
t.Fatalf("FeedURI does not match")
}

if typedFeed.Username != "test-username" {
t.Fatalf("Username does not match")
}
}
42 changes: 42 additions & 0 deletions pkg/feeds/oci_registry_feed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package feeds

import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/go-playground/validator/v10"
"github.com/go-playground/validator/v10/non-standard/validators"
)

// OCIRegistryFeed represents a feed of Open Container Initiative Registry.
type OCIRegistryFeed struct {
FeedURI string `json:"FeedUri,omitempty"`

feed
}

// NewOCIRegistryFeed creates and initializes a OCIRegistry feed.
func NewOCIRegistryFeed(name string) (*OCIRegistryFeed, error) {
if internal.IsEmpty(name) {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("name")
}

feed := OCIRegistryFeed{
FeedURI: "oci://registry-1.docker.io",
feed: *newFeed(name, FeedTypeOCIRegistry),
}

if err := feed.Validate(); err != nil {
return nil, err
}

return &feed, nil
}

// Validate checks the state of this feed and returns an error if invalid.
func (m *OCIRegistryFeed) Validate() error {
v := validator.New()
err := v.RegisterValidation("notblank", validators.NotBlank)
if err != nil {
return err
}
return v.Struct(m)
}

0 comments on commit 1d2223a

Please sign in to comment.