-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat(jfrog): support multiple repositories #289
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
31c29fa
Fix check for shell completion
brent-at-aam 646adbc
Support for multiple repos
brent-at-aam 0361847
Fix function syntax
BrentSouza b6c0d58
Update readme and port to jfrog-oauth
brent-at-aam fd5ba0f
Port tests to oauth module and fix errors
brent-at-aam 67c1d63
Fix formatting
brent-at-aam 4b0ac2a
`bun fmt`
matifali d06cd4a
Address review items
brent-at-aam 149cb2f
Remove accidental import
brent-at-aam 70ec87f
Merge branch 'coder:main' into jfrog-enhancements
BrentSouza fb409cf
Merge branch 'main' into jfrog-enhancements
matifali 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
email=${ARTIFACTORY_EMAIL} | ||
%{ for REPO in REPOS ~} | ||
${REPO.SCOPE}registry=${JFROG_URL}/artifactory/api/npm/${REPO.NAME} | ||
//${JFROG_HOST}/artifactory/api/npm/${REPO.NAME}/:_authToken=${ARTIFACTORY_ACCESS_TOKEN} | ||
%{ endfor ~} |
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 |
---|---|---|
@@ -1,19 +1,129 @@ | ||
import { serve } from "bun"; | ||
import { describe } from "bun:test"; | ||
import { describe, expect, it } from "bun:test"; | ||
import { | ||
createJSONResponse, | ||
findResourceInstance, | ||
runTerraformInit, | ||
runTerraformApply, | ||
testRequiredVariables, | ||
} from "../test"; | ||
|
||
describe("jfrog-oauth", async () => { | ||
type TestVariables = { | ||
agent_id: string; | ||
jfrog_url: string; | ||
package_managers: string; | ||
|
||
username_field?: string; | ||
jfrog_server_id?: string; | ||
external_auth_id?: string; | ||
configure_code_server?: boolean; | ||
}; | ||
|
||
await runTerraformInit(import.meta.dir); | ||
|
||
testRequiredVariables(import.meta.dir, { | ||
agent_id: "some-agent-id", | ||
jfrog_url: "http://localhost:8081", | ||
package_managers: "{}", | ||
const fakeFrogApi = "localhost:8081/artifactory/api"; | ||
const fakeFrogUrl = "http://localhost:8081"; | ||
const user = "default"; | ||
|
||
it("can run apply with required variables", async () => { | ||
testRequiredVariables<TestVariables>(import.meta.dir, { | ||
agent_id: "some-agent-id", | ||
jfrog_url: fakeFrogUrl, | ||
package_managers: "{}", | ||
}); | ||
}); | ||
}); | ||
|
||
//TODO add more tests | ||
it("generates an npmrc with scoped repos", async () => { | ||
const state = await runTerraformApply<TestVariables>(import.meta.dir, { | ||
agent_id: "some-agent-id", | ||
jfrog_url: fakeFrogUrl, | ||
package_managers: JSON.stringify({ | ||
npm: ["global", "@foo:foo", "@bar:bar"], | ||
}), | ||
}); | ||
const coderScript = findResourceInstance(state, "coder_script"); | ||
const npmrcStanza = `cat << EOF > ~/.npmrc | ||
email=${user}@example.com | ||
registry=http://${fakeFrogApi}/npm/global | ||
//${fakeFrogApi}/npm/global/:_authToken= | ||
@foo:registry=http://${fakeFrogApi}/npm/foo | ||
//${fakeFrogApi}/npm/foo/:_authToken= | ||
@bar:registry=http://${fakeFrogApi}/npm/bar | ||
//${fakeFrogApi}/npm/bar/:_authToken= | ||
|
||
EOF`; | ||
expect(coderScript.script).toContain(npmrcStanza); | ||
expect(coderScript.script).toContain( | ||
'jf npmc --global --repo-resolve "global"', | ||
); | ||
expect(coderScript.script).toContain( | ||
'if [ -z "YES" ]; then\n not_configured npm', | ||
); | ||
}); | ||
|
||
it("generates a pip config with extra-indexes", async () => { | ||
const state = await runTerraformApply<TestVariables>(import.meta.dir, { | ||
agent_id: "some-agent-id", | ||
jfrog_url: fakeFrogUrl, | ||
package_managers: JSON.stringify({ | ||
pypi: ["global", "foo", "bar"], | ||
}), | ||
}); | ||
const coderScript = findResourceInstance(state, "coder_script"); | ||
const pipStanza = `cat << EOF > ~/.pip/pip.conf | ||
[global] | ||
index-url = https://${user}:@${fakeFrogApi}/pypi/global/simple | ||
extra-index-url = | ||
https://${user}:@${fakeFrogApi}/pypi/foo/simple | ||
https://${user}:@${fakeFrogApi}/pypi/bar/simple | ||
|
||
EOF`; | ||
expect(coderScript.script).toContain(pipStanza); | ||
expect(coderScript.script).toContain( | ||
'jf pipc --global --repo-resolve "global"', | ||
); | ||
expect(coderScript.script).toContain( | ||
'if [ -z "YES" ]; then\n not_configured pypi', | ||
); | ||
}); | ||
|
||
it("registers multiple docker repos", async () => { | ||
const state = await runTerraformApply<TestVariables>(import.meta.dir, { | ||
agent_id: "some-agent-id", | ||
jfrog_url: fakeFrogUrl, | ||
package_managers: JSON.stringify({ | ||
docker: ["foo.jfrog.io", "bar.jfrog.io", "baz.jfrog.io"], | ||
}), | ||
}); | ||
const coderScript = findResourceInstance(state, "coder_script"); | ||
const dockerStanza = ["foo", "bar", "baz"] | ||
.map((r) => `register_docker "${r}.jfrog.io"`) | ||
.join("\n"); | ||
expect(coderScript.script).toContain(dockerStanza); | ||
expect(coderScript.script).toContain( | ||
'if [ -z "YES" ]; then\n not_configured docker', | ||
); | ||
}); | ||
|
||
it("sets goproxy with multiple repos", async () => { | ||
const state = await runTerraformApply<TestVariables>(import.meta.dir, { | ||
agent_id: "some-agent-id", | ||
jfrog_url: fakeFrogUrl, | ||
package_managers: JSON.stringify({ | ||
go: ["foo", "bar", "baz"], | ||
}), | ||
}); | ||
const proxyEnv = findResourceInstance(state, "coder_env", "goproxy"); | ||
const proxies = ["foo", "bar", "baz"] | ||
.map((r) => `https://${user}:@${fakeFrogApi}/go/${r}`) | ||
.join(","); | ||
expect(proxyEnv["value"]).toEqual(proxies); | ||
|
||
const coderScript = findResourceInstance(state, "coder_script"); | ||
expect(coderScript.script).toContain( | ||
'jf goc --global --repo-resolve "foo"', | ||
); | ||
expect(coderScript.script).toContain( | ||
'if [ -z "YES" ]; then\n not_configured go', | ||
); | ||
}); | ||
}); |
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,6 @@ | ||
[global] | ||
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${try(element(REPOS, 0), "")}/simple | ||
extra-index-url = | ||
%{ for REPO in try(slice(REPOS, 1, length(REPOS)), []) ~} | ||
https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPO}/simple | ||
%{ endfor ~} |
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.
This definitely isn't your fault, but I'm making a note so I don't forget: we should update our helper functions so that they support Terraform objects directly