-
Notifications
You must be signed in to change notification settings - Fork 102
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
Adds Agent Pool to OAuth Client API #841
Merged
roleesinhaHC
merged 16 commits into
main
from
rolees/update_params_for_oauth_client_create
Feb 27, 2024
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2351138
Update OAuthClient creation params
roleesinhaHC 38e8bdc
addressing review comments
roleesinhaHC e6117a0
updating agent pool option as relation
roleesinhaHC d40d000
Merge branch 'main' into rolees/update_params_for_oauth_client_create
roleesinhaHC 4dc5c62
fixing test
roleesinhaHC 5ee9c82
fixed lint error
roleesinhaHC 844c00f
Adding intergration tests
roleesinhaHC 7c0fa89
fix linting issue
roleesinhaHC d821010
adding error messages
roleesinhaHC dcb6843
addressing review comments
roleesinhaHC 90f21a2
updated the provider type
roleesinhaHC e68d4a0
Merge branch 'main' into rolees/update_params_for_oauth_client_create
roleesinhaHC 53628c5
fixing intergration test errors
roleesinhaHC cdbca43
Merge branch 'main' into rolees/update_params_for_oauth_client_create
roleesinhaHC eaefd6d
adding code comments
roleesinhaHC b7a0cd0
fixing lint error
roleesinhaHC 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,6 +224,76 @@ func TestOAuthClientsCreate_rsaKeyPair(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestOAuthClientsCreate_agentPool(t *testing.T) { | ||
client := testClient(t) | ||
ctx := context.Background() | ||
|
||
githubToken := os.Getenv("OAUTH_CLIENT_GITHUB_TOKEN") | ||
if githubToken == "" { | ||
t.Skip("Export a valid OAUTH_CLIENT_GITHUB_TOKEN before running this test!") | ||
} | ||
|
||
t.Run("with valid agent pool external id", func(t *testing.T) { | ||
t.Skip() | ||
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. Some comments here would be appropriate |
||
orgTestRead, errOrg := client.Organizations.Read(ctx, "xxxxx") | ||
require.NoError(t, errOrg) | ||
agentPoolTestRead, errAgentPool := client.AgentPools.Read(ctx, "xxxxx") | ||
require.NoError(t, errAgentPool) | ||
options := OAuthClientCreateOptions{ | ||
APIURL: String("https://githubenterprise.xxxxx"), | ||
HTTPURL: String("https://githubenterprise.xxxxx"), | ||
OAuthToken: String(githubToken), | ||
ServiceProvider: ServiceProvider(ServiceProviderGithubEE), | ||
AgentPool: agentPoolTestRead, | ||
} | ||
oc, errCreate := client.OAuthClients.Create(ctx, orgTestRead.Name, options) | ||
require.NoError(t, errCreate) | ||
assert.NotEmpty(t, oc.ID) | ||
assert.Equal(t, "https://githubenterprise.xxxxx", oc.APIURL) | ||
assert.Equal(t, "https://githubenterprise.xxxxx", oc.HTTPURL) | ||
assert.Equal(t, 1, len(oc.OAuthTokens)) | ||
assert.Equal(t, ServiceProviderGithubEE, oc.ServiceProvider) | ||
assert.Equal(t, agentPoolTestRead.ID, oc.AgentPool.ID) | ||
}) | ||
|
||
t.Run("with an invalid agent pool", func(t *testing.T) { | ||
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
agentPoolTest, agentPoolCleanup := createAgentPool(t, client, orgTest) | ||
defer agentPoolCleanup() | ||
agentPoolID := agentPoolTest.ID | ||
agentPoolTest.ID = badIdentifier | ||
options := OAuthClientCreateOptions{ | ||
APIURL: String("https://githubenterprise.xxxxx"), | ||
HTTPURL: String("https://githubenterprise.xxxxx"), | ||
OAuthToken: String(githubToken), | ||
ServiceProvider: ServiceProvider(ServiceProviderGithubEE), | ||
AgentPool: agentPoolTest, | ||
} | ||
_, errCreate := client.OAuthClients.Create(ctx, orgTest.Name, options) | ||
require.Error(t, errCreate) | ||
assert.Contains(t, errCreate.Error(), "the provided agent pool does not exist or you are not authorized to use it") | ||
agentPoolTest.ID = agentPoolID | ||
}) | ||
|
||
t.Run("with no agents connected", func(t *testing.T) { | ||
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
agentPoolTest, agentPoolCleanup := createAgentPool(t, client, orgTest) | ||
defer agentPoolCleanup() | ||
options := OAuthClientCreateOptions{ | ||
APIURL: String("https://githubenterprise.xxxxx"), | ||
HTTPURL: String("https://githubenterprise.xxxxx"), | ||
OAuthToken: String(githubToken), | ||
ServiceProvider: ServiceProvider(ServiceProviderGithubEE), | ||
AgentPool: agentPoolTest, | ||
} | ||
_, errCreate := client.OAuthClients.Create(ctx, orgTest.Name, options) | ||
assert.Contains(t, errCreate.Error(), "the organization does not have private VCS enabled") | ||
require.Error(t, errCreate) | ||
}) | ||
} | ||
|
||
func TestOAuthClientsRead(t *testing.T) { | ||
client := testClient(t) | ||
ctx := context.Background() | ||
|
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.
It appears that you've also added the inverse relationship to the API (each agent pool has_many oauth-clients). What do you think about adding
include_data = false
to that new relationship in the API? Is there a good reason to serialize all of the oauth-clients associated with an agent pool?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.
Agreed, added those changes https://github.com/hashicorp/atlas/pull/18747