-
Notifications
You must be signed in to change notification settings - Fork 208
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
Directory Param feature #2251
Open
richbai90
wants to merge
13
commits into
getporter:release/v1
Choose a base branch
from
richbai90:feature/directory_param
base: release/v1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Directory Param feature #2251
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d66127b
Make the bundle user details global to the build package. Required if…
d873618
Revert "Make the bundle user details global to the build package. Req…
a87e7de
Make the bundle user details global to the build package. Required if…
a744f47
Revert "Make the bundle user details global to the build package. Req…
f26bba5
Create a new parameter type, and refactor parameter type checking int…
ee52834
add comments to the helper functions
b1b664e
directory parameter added. TODO: Make customizable
92e5499
Fix the logic of IsDirSource to prevent duplicate mount errors
52ab946
Merge branch 'release/v1' of https://github.com/getporter/porter into…
d8448e2
merge 1.0.0
c04705e
make sure it builds
6099810
merged parameters.go incorrectly, so fixed it
2a2ada8
Cherry pick execute callback in closure
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file not shown.
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,104 @@ | ||
package cnab | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/cnabio/cnab-go/bundle/definition" | ||
"github.com/docker/docker/api/types/mount" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
const ( | ||
DirectoryExtensionShortHand = "directory-parameter" | ||
DirectoryParameterExtensionKey = PorterExtensionsPrefix + DirectoryExtensionShortHand | ||
) | ||
|
||
// DirectoryParameterDefinition represents those parameter options | ||
// That apply exclusively to the directory parameter type | ||
type DirectoryParameterDefinition struct { | ||
Writeable bool `yaml:"writeable,omitempty"` | ||
// UID and GID should be ints, however 0 is the default value for int type | ||
// But is also a realistic value for UID/GID thus we need to make the type interface | ||
// To detect the case that the values weren't set | ||
GID interface{} `yaml:"gid,omitempty" json:"gid,omitempty"` | ||
UID interface{} `yaml:"uid,omitempty" json:"uid,omitempty"` | ||
} | ||
|
||
// MountParameterSource represents a parameter using a docker mount | ||
// As a its source with the provided options | ||
type MountParameterSourceDefn struct { | ||
mount.Mount `yaml:",inline"` | ||
Name string `json:"name,omitempty" yaml:"name,omitempty"` | ||
} | ||
|
||
// DirectorySources represents the sources available to the directory parameter type | ||
// Currently only mount has been specified, but this could change in the future | ||
type DirectorySources struct { | ||
Mount MountParameterSourceDefn `yaml:"mount,omitempty" json:"mount,omitempty"` | ||
} | ||
type DirectoryDetails struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't tried this but here's what I think will fit better with how the CNAB spec and Porter works:
|
||
DirectorySources | ||
DirectoryParameterDefinition | ||
Kind string `json:"kind,omitempty"` | ||
} | ||
|
||
// DirectoryParameterExtension indicates that Directory support is required | ||
var DirectoryParameterExtension = RequiredExtension{ | ||
Shorthand: DirectoryExtensionShortHand, | ||
Key: DirectoryParameterExtensionKey, | ||
Reader: DirectoryParameterReader, | ||
} | ||
|
||
// SupportsDirectoryParameters returns true if the bundle supports the | ||
// Directory parameter extension | ||
func (b ExtendedBundle) SupportsDirectoryParameters() bool { | ||
return b.SupportsExtension(DirectoryParameterExtensionKey) | ||
} | ||
|
||
// IsDirType determines if the parameter/credential is of type "directory". | ||
func (b ExtendedBundle) IsDirType(def *definition.Schema) bool { | ||
return b.SupportsDirectoryParameters() && def.Type == "string" && def.Comment == DirectoryParameterExtensionKey | ||
} | ||
|
||
// DirectoryParameterReader is a Reader for the DirectoryParameterExtension. | ||
// The extension maintains the list of directory parameters in the bundle | ||
func DirectoryParameterReader(b ExtendedBundle) (interface{}, error) { | ||
return b.DirectoryParameterReader() | ||
} | ||
|
||
// DirectoryParameterReader is a Reader for the DirectoryParameterExtension. | ||
// This method generates the list of directory parameter names in the bundle. | ||
// The Directory Parameter extension maintains the list of directory parameters in the bundle | ||
func (b ExtendedBundle) DirectoryParameterReader() (interface{}, error) { | ||
bytes, err := json.Marshal(b.Custom[DirectoryParameterExtensionKey]) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "Failed to marshal custom extension %s", DirectoryParameterExtensionKey) | ||
} | ||
var dd map[string]DirectoryDetails | ||
if err = errors.Wrapf(json.Unmarshal(bytes, &dd), "Failed to unmarshal custom extension %s %s", DirectoryParameterExtensionKey, string(bytes)); err != nil { | ||
return nil, err | ||
} | ||
dirs := make([]DirectoryDetails, len(dd)) | ||
i := 0 | ||
for _, dir := range dd { | ||
dirs[i] = dir | ||
i++ | ||
} | ||
return dirs, nil | ||
} | ||
|
||
// DirectoryParameterSupport checks if the Directory parameter extension is present | ||
func (e ProcessedExtensions) DirectoryParameterSupport() bool { | ||
_, extensionRequired := e[DirectoryParameterExtensionKey] | ||
return extensionRequired | ||
} | ||
|
||
// IDToInt converts an interface to an integer. If the id is coercable to an int, returns the value | ||
// Otherwise returns -1 | ||
func IDToInt(id interface{}) int { | ||
if i, ok := id.(int); ok { | ||
return i | ||
} | ||
|
||
return -1 | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's talk more about this right here. The goal is that the bundle doesn't know or care how the directory got there. Just that it has the access it needs.
Ideally the mount options should all be a concern of just the porter client and how we execute the cnab bundle as a docker image. I may not have been clear in my original comment, but what I was suggesting was that the user could specify the mount options using a docker mount string, either as a --param flag, or via a parameter set:
Then when the docker driver is used, it will use both the docker extension information in addition to the mount string from the parameter, to mount the directory into the container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I can use a string. My idea with using a larger object was so that we didn't have to parse the string, but it should otherwise simplify things a bit so I'll make the change.