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

feat: git Access, AccessMethod through BlobAccess #869

Merged
merged 28 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b21dea4
feat: git based ctf tracking repositories
jakobmoellerdev Aug 10, 2024
554390d
feat: git authentication support
jakobmoellerdev Aug 20, 2024
955c377
DRAFT: git fs support
jakobmoellerdev Aug 20, 2024
f2c76ad
feat: git repo support
jakobmoellerdev Aug 20, 2024
70d59d1
feat: git repo support
jakobmoellerdev Aug 21, 2024
0a844d5
feat: git repo support
jakobmoellerdev Aug 21, 2024
ae82837
feat: git repo support
jakobmoellerdev Sep 25, 2024
8432e5f
feat: git repo support
jakobmoellerdev Sep 25, 2024
66fc603
chore: various pr review adjustments
jakobmoellerdev Oct 2, 2024
7f68c55
chore: imports fix
jakobmoellerdev Oct 2, 2024
6f9fc7d
feat: allow generic blob accessmethod for git
jakobmoellerdev Oct 4, 2024
8b34ef8
chore: make sure creds get read from repo and enforce create in format
jakobmoellerdev Oct 7, 2024
607c3ab
chore: make repo simpler
jakobmoellerdev Oct 7, 2024
9e017de
chore: allow no author
jakobmoellerdev Oct 7, 2024
648e800
chore: implement cli input type
jakobmoellerdev Oct 7, 2024
90f82f5
chore: implement cli input type
jakobmoellerdev Oct 8, 2024
38b3e41
feat: allow access by commit
jakobmoellerdev Oct 9, 2024
067d397
chore: kill the git repository type because its unlikely to be used
jakobmoellerdev Oct 24, 2024
99e94bd
chore: keep up to date
jakobmoellerdev Nov 28, 2024
e5d7e85
chore: pr review
jakobmoellerdev Dec 16, 2024
bfe7443
Merge remote-tracking branch 'upstream/HEAD' into git-ctf
jakobmoellerdev Dec 16, 2024
46a9e2c
chore: cleanup resolver/downloader because no update is needed
jakobmoellerdev Dec 17, 2024
407988a
chore: fixup inconsistent access method
jakobmoellerdev Dec 18, 2024
8665a10
Merge branch 'main' into git-ctf
jakobmoellerdev Dec 18, 2024
678fa26
Merge branch 'main' into git-ctf
jakobmoellerdev Dec 18, 2024
e3acf66
Merge branch 'main' into git-ctf
jakobmoellerdev Dec 18, 2024
47b058a
Merge branch 'main' into git-ctf
jakobmoellerdev Dec 20, 2024
a61ebaf
Merge branch 'main' into git-ctf
jakobmoellerdev Jan 6, 2025
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
1 change: 1 addition & 0 deletions api/credentials/builtin/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package builtin

import (
_ "ocm.software/ocm/api/credentials/builtin/github"
_ "ocm.software/ocm/api/tech/git/identity"
jakobmoellerdev marked this conversation as resolved.
Show resolved Hide resolved
)
12 changes: 6 additions & 6 deletions api/oci/cpi/support/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ func (a *artifactBase) IsReadOnly() bool {
}

func (a *artifactBase) IsIndex() bool {
d := a.state.GetState().(*artdesc.Artifact)
return d.IsIndex()
d, ok := a.state.GetState().(*artdesc.Artifact)
return ok && d.IsIndex()
jakobmoellerdev marked this conversation as resolved.
Show resolved Hide resolved
}

func (a *artifactBase) IsManifest() bool {
d := a.state.GetState().(*artdesc.Artifact)
return d.IsManifest()
d, ok := a.state.GetState().(*artdesc.Artifact)
return ok && d.IsManifest()
}

func (a *artifactBase) IsValid() bool {
d := a.state.GetState().(*artdesc.Artifact)
return d.IsValid()
d, ok := a.state.GetState().(*artdesc.Artifact)
return ok && d.IsValid()
}

func (a *artifactBase) blob() (cpi.BlobAccess, error) {
Expand Down
2 changes: 1 addition & 1 deletion api/oci/internal/uniform.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type UniformRepositorySpec struct {
// Host is the hostname of an oci ref.
Host string `json:"host,omitempty"`
// Info is the file path used to host ctf component versions
Info string `json:"filePath,omitempty"`
Info string `json:"info,omitempty"`
jakobmoellerdev marked this conversation as resolved.
Show resolved Hide resolved

// CreateIfMissing indicates whether a file based or dynamic repo should be created if it does not exist
CreateIfMissing bool `json:"createIfMissing,omitempty"`
Expand Down
58 changes: 58 additions & 0 deletions api/ocm/elements/artifactaccess/gitaccess/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package gitaccess

import (
"github.com/mandelsoft/goutils/optionutils"
)

type Option = optionutils.Option[*Options]

type Options struct {
URL string
Ref string
Commit string
}

var _ Option = (*Options)(nil)

func (o *Options) ApplyTo(opts *Options) {
if o.URL != "" {
opts.URL = o.URL
}
}

func (o *Options) Apply(opts ...Option) {
optionutils.ApplyOptions(o, opts...)
}

// //////////////////////////////////////////////////////////////////////////////
// Local options

type url string

func (h url) ApplyTo(opts *Options) {
opts.URL = string(h)
}

func WithURL(h string) Option {
return url(h)
}

type ref string

func (h ref) ApplyTo(opts *Options) {
opts.Ref = string(h)
}

func WithRef(h string) Option {
return ref(h)
}

type commitSpec string

func (h commitSpec) ApplyTo(opts *Options) {
opts.Commit = string(h)
}

func WithCommit(c string) Option {
return commitSpec(c)
}
25 changes: 25 additions & 0 deletions api/ocm/elements/artifactaccess/gitaccess/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gitaccess

import (
"github.com/mandelsoft/goutils/optionutils"

"ocm.software/ocm/api/ocm"
"ocm.software/ocm/api/ocm/compdesc"
"ocm.software/ocm/api/ocm/cpi"
"ocm.software/ocm/api/ocm/elements/artifactaccess/genericaccess"
access "ocm.software/ocm/api/ocm/extensions/accessmethods/git"
resourcetypes "ocm.software/ocm/api/ocm/extensions/artifacttypes"
)

const TYPE = resourcetypes.DIRECTORY_TREE

func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, opts ...Option) cpi.ArtifactAccess[M] {
eff := optionutils.EvalOptions(opts...)
if meta.GetType() == "" {
meta.SetType(TYPE)
}

spec := access.New(eff.URL, access.WithRef(eff.Ref), access.WithCommit(eff.Commit))
// is global access, must work, otherwise there is an error in the lib.
return genericaccess.MustAccess(ctx, meta, spec)
}
93 changes: 93 additions & 0 deletions api/ocm/extensions/accessmethods/git/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

# Access Method `git` - Git Commit Access

## Synopsis

```yaml
type: git/v1
```

Provided blobs use the following media type for: `application/x-tgz`

The artifact content is provided as gnu-zipped tar archive

### Description

This method implements the access of the content of a git commit stored in a
git repository.

Supported specification version is `v1alpha1`

### Specification Versions

#### Version `v1alpha1`

The type specific specification fields are:

- **`repository`** *string*

Repository URL with or without scheme.

- **`ref`** (optional) *string*

Original ref used to get the commit from

- **`commit`** *string*

The sha/id of the git commit

### Go Bindings

The go binding can be found [here](method.go)
jakobmoellerdev marked this conversation as resolved.
Show resolved Hide resolved

#### Example

```go
package main

import (
"archive/tar"
"bytes"
"compress/gzip"
"fmt"
"io"

"ocm.software/ocm/api/ocm"
"ocm.software/ocm/api/ocm/cpi"
me "ocm.software/ocm/api/ocm/extensions/accessmethods/git"
)

func main() {
ctx := ocm.New()
accessSpec := me.New(
"https://github.com/octocat/Hello-World.git",
me.WithRef("refs/heads/master"),
)
method, err := accessSpec.AccessMethod(&cpi.DummyComponentVersionAccess{Context: ctx})
if err != nil {
panic(err)
}
content, err := method.GetContent()
if err != nil {
panic(err)
}
unzippedContent, err := gzip.NewReader(bytes.NewReader(content))

r := tar.NewReader(unzippedContent)

file, err := r.Next()
if err != nil {
panic(err)
}

if file.Name != "README.md" {
panic("Expected README.md")
}

data, err := io.ReadAll(r)
if err != nil {
panic(err)
}
fmt.Println(string(data))
}
```
43 changes: 43 additions & 0 deletions api/ocm/extensions/accessmethods/git/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package git

import (
"ocm.software/ocm/api/ocm/extensions/accessmethods/options"
"ocm.software/ocm/api/utils/cobrautils/flagsets"
)

func ConfigHandler() flagsets.ConfigOptionTypeSetHandler {
return flagsets.NewConfigOptionTypeSetHandler(
Type, AddConfig,
options.RepositoryOption,
options.ReferenceOption,
options.CommitOption,
)
}

func AddConfig(opts flagsets.ConfigOptions, config flagsets.Config) error {
flagsets.AddFieldByOptionP(opts, options.RepositoryOption, config, "repository", "repo", "repoUrl", "repoURL")
flagsets.AddFieldByOptionP(opts, options.CommitOption, config, "commit")
flagsets.AddFieldByOptionP(opts, options.ReferenceOption, config, "ref")
return nil
}

var usage = `
This method implements the access of the content of a git commit stored in a
Git repository.
`

var formatV1 = `
The type specific specification fields are:

- **<code>repoUrl</code>** *string*

Repository URL with or without scheme.

- **<code>ref</code>** (optional) *string*

Original ref used to get the commit from

- **<code>commit</code>** *string*

The sha/id of the git commit
`
Loading
Loading