merge main

pull/50/head
Muhammad Atif Ali 2 years ago
commit cd77a5c58b
No known key found for this signature in database

@ -1,18 +1,41 @@
import { describe, expect, it } from "bun:test";
import { serve } from "bun";
import { describe } from "bun:test";
import {
executeScriptInContainer,
runTerraformApply,
createJSONResponse,
runTerraformInit,
testRequiredVariables,
testRequiredVariables
} from "../test";
describe("jfrog", async () => {
await runTerraformInit(import.meta.dir);
// Run a fake JFrog server so the provider can initialize
// correctly. This saves us from having to make remote requests!
const fakeFrogHost = serve({
fetch: (req) => {
const url = new URL(req.url);
// See https://jfrog.com/help/r/jfrog-rest-apis/license-information
if (url.pathname === "/artifactory/api/system/license")
return createJSONResponse({
type: "Commercial",
licensedTo: "JFrog inc.",
validThrough: "May 15, 2036",
});
if (url.pathname === "/access/api/v1/tokens")
return createJSONResponse({
token_id: "xxx",
access_token: "xxx",
scope: "any",
});
return createJSONResponse({});
},
port: 0,
});
testRequiredVariables(import.meta.dir, {
agent_id: "some-agent-id",
jfrog_host: "YYYY.jfrog.io",
jfrog_url: "http://" + fakeFrogHost.hostname + ":" + fakeFrogHost.port,
artifactory_access_token: "XXXX",
package_managers: '',
package_managers: "{}",
});
});

@ -13,9 +13,9 @@ terraform {
}
}
variable "jfrog_host" {
variable "jfrog_url" {
type = string
description = "JFrog instance hostname. e.g. YYY.jfrog.io"
description = "JFrog instance URL. e.g. https://YYY.jfrog.io"
}
variable "artifactory_access_token" {
@ -25,7 +25,7 @@ variable "artifactory_access_token" {
# Configure the Artifactory provider
provider "artifactory" {
url = "https://${var.jfrog_host}/artifactory"
url = join("/", [var.jfrog_url, "artifactory"])
access_token = var.artifactory_access_token
}
resource "artifactory_scoped_token" "me" {
@ -65,7 +65,7 @@ resource "coder_script" "jfrog" {
display_name = "jfrog"
icon = "/icon/jfrog.svg"
script = templatefile("${path.module}/run.sh", {
JFROG_HOST : var.jfrog_host,
JFROG_URL : var.jfrog_url,
ARTIFACTORY_USERNAME : data.coder_workspace.me.owner_email,
ARTIFACTORY_ACCESS_TOKEN : artifactory_scoped_token.me.access_token,
REPOSITORY_NPM : lookup(var.package_managers, "npm", ""),

@ -12,34 +12,19 @@ sudo chmod 755 /usr/local/bin/jf
export CI=true
# Authenticate with the JFrog CLI.
jf c rm 0 || true
echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "https://${JFROG_HOST}" 0
echo "${ARTIFACTORY_ACCESS_TOKEN}" | jf c add --access-token-stdin --url "${JFROG_URL}" 0
# Configure the `npm` CLI to use the Artifactory "npm" repository.
if [ -z "${REPOSITORY_NPM}" ]; then
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
else
# check NPM_PACKAGE_MANAGER==npm value to set the package manager npm otherwise yarn
if [ "${NPM_PACKAGE_MANAGER}" = "npm" ]; then
echo "📦 Configuring npm..."
jf npmc --global --repo-resolve "https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}"
# cat << EOF > ~/.npmrc
# email = ${ARTIFACTORY_USERNAME}
# registry = https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}
# EOF
jf rt curl /api/npm/auth >> ~/.npmrc
else
echo "🧶 Configuring yarn..."
jf yarnc --global --repo-resolve "https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}"
# cat << EOF > ~/.yarnrc
# echo "📦 Configuring npm..."
# jf npmc --global --repo-resolve "https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}"
# cat << EOF > ~/.npmrc
# email = ${ARTIFACTORY_USERNAME}
# registry = https://${JFROG_HOST}/artifactory/api/npm/${REPOSITORY_NPM}
# EOF
# jf rt curl /api/npm/auth >> ~/.npmrc
echo "📦 Configuring npm..."
jf npmc --global --repo-resolve "${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}"
cat << EOF > ~/.npmrc
email = ${ARTIFACTORY_USERNAME}
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}
EOF
jf rt curl /api/npm/auth >> ~/.npmrc
fi
# Configure the `pip` to use the Artifactory "python" repository.
@ -50,7 +35,7 @@ else
mkdir -p ~/.pip
cat << EOF > ~/.pip/pip.conf
[global]
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_URL}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
EOF
fi
@ -59,6 +44,6 @@ if [ -z "${REPOSITORY_GO}" ]; then
echo "🤔 REPOSITORY_GO is not set, skipping go configuration."
else
echo "🐹 Configuring go..."
export GOPROXY="https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/go/${REPOSITORY_GO}"
export GOPROXY="https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_URL}/artifactory/api/go/${REPOSITORY_GO}"
fi
echo "🥳 Configuration complete!"

@ -153,7 +153,7 @@ export const testRequiredVariables = (
await runTerraformApply(dir, localVars);
} catch (ex) {
expect(ex.message).toContain(
`input variable \"${varName}\" is not set, and has no default`,
`input variable \"${varName}\" is not set`,
);
return;
}
@ -180,6 +180,7 @@ export const runTerraformApply = async (
"-input=false",
"-auto-approve",
"-state",
"-no-color",
stateFile,
],
{
@ -210,3 +211,12 @@ export const runTerraformInit = async (dir: string) => {
throw new Error(text);
}
};
export const createJSONResponse = (obj: object, statusCode = 200): Response => {
return new Response(JSON.stringify(obj), {
headers: {
"Content-Type": "application/json",
},
status: statusCode,
})
}
Loading…
Cancel
Save