-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/jfrog-plugin
- Loading branch information
Showing
48 changed files
with
2,550 additions
and
113 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
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
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
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
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,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) | ||
} |
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,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) | ||
} |
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,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) | ||
|
||
#### 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)) | ||
} | ||
``` |
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,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 | ||
` |
Oops, something went wrong.