Add auth to template for 22_test_configs.sh

This adds the following vairables to be used with the 22_test_configs.sh
script, so that it can generate configs which have access to private
repos.

* AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_TYPE
* AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_KEY_PASSWORD
* AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_KEY_PATH
* AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_HTTP_PASSWORD
* AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_SSH_PASSWORD
* AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_USERNAME

Relates-To: #627

Change-Id: I791e45eb6747e76f0e69a7cdcfde90db570fa1d1
This commit is contained in:
Ian Howell 2021-09-02 12:19:28 -05:00
parent 22de5f130f
commit 1d09fa090c
3 changed files with 14 additions and 3 deletions

View File

@ -34,6 +34,7 @@ const (
SSHAuth = "ssh-key" SSHAuth = "ssh-key"
SSHPass = "ssh-pass" SSHPass = "ssh-pass"
HTTPBasic = "http-basic" HTTPBasic = "http-basic"
NoAuth = "none"
) )
// remoteName is a remote name that airshipctl work with during document pull // remoteName is a remote name that airshipctl work with during document pull
@ -57,7 +58,7 @@ type Repository struct {
// RepoAuth struct describes method of authentication against given repository // RepoAuth struct describes method of authentication against given repository
type RepoAuth struct { type RepoAuth struct {
// Type of authentication method to be used with given repository // Type of authentication method to be used with given repository
// supported types are "ssh-key", "ssh-pass", "http-basic" // supported types are "ssh-key", "ssh-pass", "http-basic", "none"
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
//KeyPassword is a password decrypt ssh private key (used with ssh-key auth type) //KeyPassword is a password decrypt ssh private key (used with ssh-key auth type)
KeyPassword string `json:"keyPass,omitempty"` KeyPassword string `json:"keyPass,omitempty"`
@ -139,7 +140,7 @@ func (rf *RepoFetch) Validate() error {
// RepoAuth methods // RepoAuth methods
var ( var (
AllowedAuthTypes = []string{SSHAuth, SSHPass, HTTPBasic} AllowedAuthTypes = []string{SSHAuth, SSHPass, HTTPBasic, NoAuth}
) )
// String returns repository authentication details in string format // String returns repository authentication details in string format
@ -172,6 +173,8 @@ func (auth *RepoAuth) Validate() error {
if auth.KeyPath != "" || auth.KeyPassword != "" || auth.HTTPPassword != "" { if auth.KeyPath != "" || auth.KeyPassword != "" || auth.HTTPPassword != "" {
return NewErrIncompatibleAuthOptions([]string{"ssh-key, key-pass, http-pass"}, auth.Type) return NewErrIncompatibleAuthOptions([]string{"ssh-key, key-pass, http-pass"}, auth.Type)
} }
case NoAuth:
return nil
} }
return nil return nil
} }
@ -224,7 +227,7 @@ func (repo *Repository) Validate() error {
// ToAuth returns an implementation of transport.AuthMethod for // ToAuth returns an implementation of transport.AuthMethod for
// the given auth type to establish an ssh connection // the given auth type to establish an ssh connection
func (repo *Repository) ToAuth() (transport.AuthMethod, error) { func (repo *Repository) ToAuth() (transport.AuthMethod, error) {
if repo.Auth == nil { if repo.Auth == nil || repo.Auth.Type == NoAuth {
return nil, nil return nil, nil
} }
switch repo.Auth.Type { switch repo.Auth.Type {

View File

@ -39,6 +39,7 @@ export AIRSHIP_CONFIG_PHASE_REPO_BRANCH=${BRANCH:-"master"}
export AIRSHIP_CONFIG_PHASE_REPO_URL=${AIRSHIP_CONFIG_PHASE_REPO_URL:-"https://review.opendev.org/airship/airshipctl"} export AIRSHIP_CONFIG_PHASE_REPO_URL=${AIRSHIP_CONFIG_PHASE_REPO_URL:-"https://review.opendev.org/airship/airshipctl"}
export AIRSHIP_CONFIG_PHASE_REPO_NAME=${AIRSHIP_CONFIG_PHASE_REPO_NAME:-"airshipctl"} export AIRSHIP_CONFIG_PHASE_REPO_NAME=${AIRSHIP_CONFIG_PHASE_REPO_NAME:-"airshipctl"}
export AIRSHIP_CONFIG_MANIFEST_DIRECTORY=${AIRSHIP_CONFIG_MANIFEST_DIRECTORY:-"/tmp/airship"} export AIRSHIP_CONFIG_MANIFEST_DIRECTORY=${AIRSHIP_CONFIG_MANIFEST_DIRECTORY:-"/tmp/airship"}
export AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_TYPE=${AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_TYPE:-"none"}
export EXTERNAL_KUBECONFIG=${EXTERNAL_KUBECONFIG:-""} export EXTERNAL_KUBECONFIG=${EXTERNAL_KUBECONFIG:-""}
# Remove the contents of the .airship folder, preserving the kustomize plugin directory # Remove the contents of the .airship folder, preserving the kustomize plugin directory

View File

@ -26,5 +26,12 @@ manifests:
remoteRef: "" remoteRef: ""
tag: "" tag: ""
url: ${AIRSHIP_CONFIG_PHASE_REPO_URL} url: ${AIRSHIP_CONFIG_PHASE_REPO_URL}
auth:
type: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_TYPE"
keyPass: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_KEY_PASSWORD"
sshKey: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_KEY_PATH"
httpPass: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_HTTP_PASSWORD"
sshPass: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_SSH_PASSWORD"
username: "$AIRSHIP_CONFIG_MANIFEST_REPO_AUTH_USERNAME"
metadataPath: ${AIRSHIP_CONFIG_METADATA_PATH} metadataPath: ${AIRSHIP_CONFIG_METADATA_PATH}
targetPath: ${AIRSHIP_CONFIG_MANIFEST_DIRECTORY} targetPath: ${AIRSHIP_CONFIG_MANIFEST_DIRECTORY}