-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add Project Connection setup for Vault OAuth provider. #91
Open
fatmcgav
wants to merge
5
commits into
cvbarros:master
Choose a base branch
from
fatmcgav:support_vault_oauth_provider
base: master
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1b65e50
Add Project Connection setup for Vault OAuth provider.
ac9db49
Install the Hashicorp Vault support plugin when starting docker conta…
b0a79e3
Expand testing, and refactor existing 'project_feature' tests
6daca58
Add 'LocatorTypeProvider' func and supporting test.
1f636f3
Add 'GetByTypeAndProvider' func and tests
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
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,161 @@ | ||
package teamcity | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
// ConnectionType represents the TeamCity connection type | ||
type ConnectionType string | ||
|
||
const ( | ||
// ConnectionTypeOAuthProvider resprents an OAuth Provider connection type | ||
ConnectionTypeOAuthProvider ConnectionType = "OAuthProvider" | ||
) | ||
|
||
// ConnectionProviderType represents the OAuth provider type | ||
type ConnectionProviderType string | ||
|
||
const ( | ||
// ConnectionProviderTypeVault represents an Hashicorp Vault provider type | ||
ConnectionProviderTypeVault ConnectionProviderType = "teamcity-vault" | ||
) | ||
|
||
// ConnectionProviderVaultAuthMethod represents the Vault auth method | ||
type ConnectionProviderVaultAuthMethod string | ||
|
||
const ( | ||
// ConnectionProviderVaultAuthMethodIAM represents the IAM auth method | ||
ConnectionProviderVaultAuthMethodIAM ConnectionProviderVaultAuthMethod = "iam" | ||
// ConnectionProviderVaultAuthMethodApprole represents the approle auth method | ||
ConnectionProviderVaultAuthMethodApprole ConnectionProviderVaultAuthMethod = "approle" | ||
) | ||
|
||
// ConnectionProviderVaultOptions is the required options for the Vault OAuth provider | ||
type ConnectionProviderVaultOptions struct { | ||
AuthMethod ConnectionProviderVaultAuthMethod | ||
DisplayName string | ||
Endpoint string | ||
FailOnError bool | ||
Namespace string | ||
ProviderType ConnectionProviderType | ||
RoleID string | ||
SecretID string | ||
URL string | ||
VaultNamespace string | ||
} | ||
|
||
// ConnectionProviderVault defines the Vault Connection details | ||
type ConnectionProviderVault struct { | ||
id string | ||
projectID string | ||
|
||
Options ConnectionProviderVaultOptions | ||
} | ||
|
||
// NewProjectConnectionVault creates a new Vault OAuth Provider connection feature | ||
func NewProjectConnectionVault(projectID string, options ConnectionProviderVaultOptions) *ConnectionProviderVault { | ||
return &ConnectionProviderVault{ | ||
projectID: projectID, | ||
Options: options, | ||
} | ||
} | ||
|
||
// ID returns the ID of this project feature | ||
func (f *ConnectionProviderVault) ID() string { | ||
return f.id | ||
} | ||
|
||
// SetID sets the ID of this project feature | ||
func (f *ConnectionProviderVault) SetID(value string) { | ||
f.id = value | ||
} | ||
|
||
// Type represents the type of this project feature as a string | ||
func (f *ConnectionProviderVault) Type() string { | ||
return "OAuthProvider" | ||
} | ||
|
||
// ProjectID represents the ID of the project the project feature is assigned to. | ||
func (f *ConnectionProviderVault) ProjectID() string { | ||
return f.projectID | ||
} | ||
|
||
// SetProjectID sets the ID of the project the project feature is assigned to. | ||
func (f *ConnectionProviderVault) SetProjectID(value string) { | ||
f.projectID = value | ||
} | ||
|
||
// Properties returns all properties for the Vault OAuth Provider project feature | ||
func (f *ConnectionProviderVault) Properties() *Properties { | ||
return NewProperties( | ||
NewProperty("auth-method", string(f.Options.AuthMethod)), | ||
NewProperty("displayName", string(f.Options.DisplayName)), | ||
NewProperty("endpoint", string(f.Options.Endpoint)), | ||
NewProperty("fail-on-error", fmt.Sprintf("%t", f.Options.FailOnError)), | ||
NewProperty("namespace", string(f.Options.Namespace)), | ||
NewProperty("providerType", string(ConnectionProviderTypeVault)), | ||
NewProperty("role-id", string(f.Options.RoleID)), | ||
NewProperty("secure:secret-id", string(f.Options.SecretID)), | ||
NewProperty("url", string(f.Options.URL)), | ||
NewProperty("vault-namespace", string(f.Options.VaultNamespace)), | ||
) | ||
} | ||
|
||
func loadConnectionProviderVault(projectID string, feature projectFeatureJSON) (ProjectFeature, error) { | ||
settings := &ConnectionProviderVault{ | ||
id: feature.ID, | ||
projectID: projectID, | ||
Options: ConnectionProviderVaultOptions{}, | ||
} | ||
|
||
// stringProperties := []string{"displayName", "endpoint", "namespace", "role-id", "url", "vault-namespace"} | ||
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. Are these comments expected? |
||
// for _, property := range stringProperties { | ||
// if encodedValue, ok := feature.Properties.GetOk("displayName"); ok { | ||
// settings.Options.DisplayName = encodedValue | ||
// } | ||
// } | ||
|
||
if encodedValue, ok := feature.Properties.GetOk("displayName"); ok { | ||
settings.Options.DisplayName = encodedValue | ||
} | ||
|
||
if encodedValue, ok := feature.Properties.GetOk("endpoint"); ok { | ||
settings.Options.Endpoint = encodedValue | ||
} | ||
|
||
if encodedValue, ok := feature.Properties.GetOk("namespace"); ok { | ||
settings.Options.Namespace = encodedValue | ||
} | ||
|
||
if encodedValue, ok := feature.Properties.GetOk("role-id"); ok { | ||
settings.Options.RoleID = encodedValue | ||
} | ||
|
||
if encodedValue, ok := feature.Properties.GetOk("url"); ok { | ||
settings.Options.URL = encodedValue | ||
} | ||
|
||
if encodedValue, ok := feature.Properties.GetOk("vault-namespace"); ok { | ||
settings.Options.VaultNamespace = encodedValue | ||
} | ||
|
||
if encodedValue, ok := feature.Properties.GetOk("fail-on-error"); ok { | ||
v, err := strconv.ParseBool(encodedValue) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
settings.Options.FailOnError = v | ||
} | ||
|
||
if encodedValue, ok := feature.Properties.GetOk("auth-method"); ok { | ||
settings.Options.AuthMethod = ConnectionProviderVaultAuthMethod(encodedValue) | ||
} | ||
|
||
if encodedValue, ok := feature.Properties.GetOk("providerType"); ok { | ||
settings.Options.ProviderType = ConnectionProviderType(encodedValue) | ||
} | ||
|
||
return settings, nil | ||
} |
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.
May I suggest we break the
feature_connection
from the specificVault
types here?Perhaps a
project_connection_vault_oauth.go
would be more suitable.