-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7392c34
commit f3de7b2
Showing
8 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ocmaccess | ||
|
||
import ( | ||
metav1 "ocm.software/ocm/api/ocm/compdesc/meta/v1" | ||
"ocm.software/ocm/api/ocm/cpi" | ||
"ocm.software/ocm/api/ocm/selectors/rscsel" | ||
"ocm.software/ocm/api/utils/blobaccess/ocm" | ||
) | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Component Version | ||
|
||
func ByComponentVersion(cv cpi.ComponentVersionAccess) ocm.ComponentVersionProvider { | ||
return ocm.ByComponentVersion(cv) | ||
} | ||
|
||
func ByResolverAndName(resolver cpi.ComponentVersionResolver, comp, vers string) ocm.ComponentVersionProvider { | ||
return ocm.ByResolverAndName(resolver, comp, vers) | ||
} | ||
|
||
func ByRepositorySpecAndName(ctx cpi.ContextProvider, spec cpi.RepositorySpec, comp, vers string) ocm.ComponentVersionProvider { | ||
return ocm.ByRepositorySpecAndName(ctx, spec, comp, vers) | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Resource | ||
|
||
func ByResourceId(id metav1.Identity) ocm.ResourceProvider { | ||
return ocm.ByResourceId(id) | ||
} | ||
|
||
func ByResourcePath(id metav1.Identity, path ...metav1.Identity) ocm.ResourceProvider { | ||
return ocm.ByResourcePath(id, path...) | ||
} | ||
|
||
func ByResourceSelector(sel ...rscsel.Selector) ocm.ResourceProvider { | ||
return ocm.ByResourceSelector(sel...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ocmaccess | ||
|
||
import ( | ||
"ocm.software/ocm/api/ocm" | ||
"ocm.software/ocm/api/ocm/compdesc" | ||
metav1 "ocm.software/ocm/api/ocm/compdesc/meta/v1" | ||
"ocm.software/ocm/api/ocm/cpi" | ||
"ocm.software/ocm/api/ocm/elements/artifactaccess/genericaccess" | ||
access "ocm.software/ocm/api/ocm/extensions/accessmethods/ocm" | ||
) | ||
|
||
func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, comp, vers string, repo cpi.RepositorySpec, id metav1.Identity, path ...metav1.Identity) (cpi.ArtifactAccess[M], error) { | ||
spec, err := access.New(comp, vers, repo, id, path...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// is global access, must work, otherwise there is an error in the lib. | ||
return genericaccess.MustAccess(ctx, meta, spec), nil | ||
} | ||
|
||
func ResourceAccess(ctx ocm.Context, meta *cpi.ResourceMeta, comp, vers string, repo cpi.RepositorySpec, id metav1.Identity, path ...metav1.Identity) (cpi.ResourceAccess, error) { | ||
return Access(ctx, meta, comp, vers, repo, id, path...) | ||
} | ||
|
||
func SourceAccess(ctx ocm.Context, meta *cpi.SourceMeta, comp, vers string, repo cpi.RepositorySpec, id metav1.Identity, path ...metav1.Identity) (cpi.SourceAccess, error) { | ||
return Access(ctx, meta, comp, vers, repo, id, path...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package ocmblob_test | ||
|
||
import ( | ||
. "github.com/mandelsoft/goutils/testutils" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
. "ocm.software/ocm/api/helper/builder" | ||
|
||
"ocm.software/ocm/api/ocm/elements" | ||
me "ocm.software/ocm/api/ocm/elements/artifactblob/mavenblob" | ||
resourcetypes "ocm.software/ocm/api/ocm/extensions/artifacttypes" | ||
"ocm.software/ocm/api/ocm/extensions/repositories/composition" | ||
"ocm.software/ocm/api/tech/maven" | ||
"ocm.software/ocm/api/tech/maven/maventest" | ||
) | ||
|
||
const ( | ||
MAVEN_PATH = "/testdata/.m2/repository" | ||
FAIL_PATH = "/testdata/.m2/fail" | ||
MAVEN_CENTRAL_ADDRESS = "repo.maven.apache.org:443" | ||
MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" | ||
MAVEN_GROUP_ID = "maven" | ||
MAVEN_ARTIFACT_ID = "maven" | ||
MAVEN_VERSION = "1.1" | ||
) | ||
|
||
var _ = Describe("blobaccess for maven", func() { | ||
Context("maven filesystem repository", func() { | ||
var env *Builder | ||
var repo *maven.Repository | ||
|
||
BeforeEach(func() { | ||
env = NewBuilder(maventest.TestData()) | ||
repo = maven.NewFileRepository(MAVEN_PATH, env.FileSystem()) | ||
}) | ||
|
||
AfterEach(func() { | ||
MustBeSuccessful(env.Cleanup()) | ||
}) | ||
|
||
It("blobaccess for a single file with classifier and extension", func() { | ||
cv := composition.NewComponentVersion(env.OCMContext(), "acme.org/test", "1.0.0") | ||
defer Close(cv) | ||
|
||
coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", | ||
maven.WithClassifier("random-content"), maven.WithExtension("json")) | ||
|
||
a := me.ResourceAccessForMavenCoords(env.OCMContext(), Must(elements.ResourceMeta("mavenblob", resourcetypes.OCM_JSON, elements.WithLocalRelation())), repo, coords, me.WithCachingFileSystem(env.FileSystem())) | ||
Expect(a.ReferenceHint()).To(Equal("")) | ||
b := Must(a.BlobAccess()) | ||
defer Close(b) | ||
Expect(string(Must(b.Get()))).To(Equal(`{"some": "test content"}`)) | ||
|
||
MustBeSuccessful(cv.SetResourceByAccess(a)) | ||
r := Must(cv.GetResourceByIndex(0)) | ||
m := Must(r.AccessMethod()) | ||
defer Close(m) | ||
Expect(string(Must(m.Get()))).To(Equal(`{"some": "test content"}`)) | ||
}) | ||
|
||
It("blobaccess for package", func() { | ||
cv := composition.NewComponentVersion(env.OCMContext(), "acme.org/test", "1.0.0") | ||
defer Close(cv) | ||
|
||
coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") | ||
|
||
a := me.ResourceAccessForMavenCoords(env.OCMContext(), Must(elements.ResourceMeta("mavenblob", resourcetypes.OCM_JSON, elements.WithLocalRelation())), repo, coords, me.WithCachingFileSystem(env.FileSystem())) | ||
Expect(a.ReferenceHint()).To(Equal(coords.GAV())) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ocmblob | ||
|
||
import ( | ||
metav1 "ocm.software/ocm/api/ocm/compdesc/meta/v1" | ||
"ocm.software/ocm/api/ocm/cpi" | ||
"ocm.software/ocm/api/ocm/selectors/rscsel" | ||
"ocm.software/ocm/api/utils/blobaccess/ocm" | ||
) | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Component Version | ||
|
||
func ByComponentVersion(cv cpi.ComponentVersionAccess) ocm.ComponentVersionProvider { | ||
return ocm.ByComponentVersion(cv) | ||
} | ||
|
||
func ByResolverAndName(resolver cpi.ComponentVersionResolver, comp, vers string) ocm.ComponentVersionProvider { | ||
return ocm.ByResolverAndName(resolver, comp, vers) | ||
} | ||
|
||
func ByRepositorySpecAndName(ctx cpi.ContextProvider, spec cpi.RepositorySpec, comp, vers string) ocm.ComponentVersionProvider { | ||
return ocm.ByRepositorySpecAndName(ctx, spec, comp, vers) | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Resource | ||
|
||
func ByResourceId(id metav1.Identity) ocm.ResourceProvider { | ||
return ocm.ByResourceId(id) | ||
} | ||
|
||
func ByResourcePath(id metav1.Identity, path ...metav1.Identity) ocm.ResourceProvider { | ||
return ocm.ByResourcePath(id, path...) | ||
} | ||
|
||
func ByResourceSelector(sel ...rscsel.Selector) ocm.ResourceProvider { | ||
return ocm.ByResourceSelector(sel...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ocmblob | ||
|
||
import ( | ||
"ocm.software/ocm/api/ocm/cpi" | ||
"ocm.software/ocm/api/ocm/elements/artifactblob/api" | ||
) | ||
|
||
type Option = api.Option | ||
|
||
type Options = api.Options | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// General Options | ||
|
||
func WithHint(h string) Option { | ||
return api.WrapHint[Options](h) | ||
} | ||
|
||
func WithGlobalAccess(a cpi.AccessSpec) Option { | ||
return api.WrapGlobalAccess[Options](a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ocmblob | ||
|
||
import ( | ||
"github.com/mandelsoft/goutils/generics" | ||
"github.com/mandelsoft/goutils/optionutils" | ||
|
||
"ocm.software/ocm/api/ocm/compdesc" | ||
"ocm.software/ocm/api/ocm/cpi" | ||
base "ocm.software/ocm/api/utils/blobaccess/ocm" | ||
) | ||
|
||
func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx cpi.Context, meta P, cvp base.ComponentVersionProvider, res base.ResourceProvider, opts ...Option) cpi.ArtifactAccess[M] { | ||
eff := optionutils.EvalOptions(opts...) | ||
blobprov := base.Provider(cvp, res) | ||
accprov := cpi.NewAccessProviderForBlobAccessProvider(ctx, blobprov, eff.Hint, eff.Global) | ||
// strange type cast is required by Go compiler, meta has the correct type. | ||
return cpi.NewArtifactAccessForProvider(generics.Cast[*M](meta), accprov) | ||
} | ||
|
||
func ResourceAccess(ctx cpi.Context, meta *cpi.ResourceMeta, cvp base.ComponentVersionProvider, res base.ResourceProvider, opts ...Option) cpi.ResourceAccess { | ||
return Access(ctx, meta, cvp, res, opts...) | ||
} | ||
|
||
func SourceAccess(ctx cpi.Context, meta *cpi.SourceMeta, cvp base.ComponentVersionProvider, res base.ResourceProvider, opts ...Option) cpi.SourceAccess { | ||
return Access(ctx, meta, cvp, res, opts...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ocmblob_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "OCM Blob Access Test Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters