Skip to content

Commit

Permalink
fix linting errors, unit tests, shellchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpinjarkar committed Nov 5, 2024
1 parent 9517ad2 commit 92f3583
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion data/data/agent/files/usr/local/bin/start-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ INFRA_ENV_ID=""
until [[ $INFRA_ENV_ID != "" && $INFRA_ENV_ID != "null" ]]; do
sleep 5
>&2 echo "Querying assisted-service for infra-env-id..."
INFRA_ENV_ID=$(curl_assisted_service "/infra-envs" GET $USER_AUTH_TOKEN | jq -r '.[0].id')
INFRA_ENV_ID=$(curl_assisted_service "/infra-envs" GET "$USER_AUTH_TOKEN" | jq -r '.[0].id')
done
echo "Fetched infra-env-id and found: $INFRA_ENV_ID"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cluster_id=""
while [[ "${cluster_id}" = "" ]]
do
# Get cluster id
cluster_id=$(curl_assisted_service "/clusters" GET $USER_AUTH_TOKEN | jq -r .[].id)
cluster_id=$(curl_assisted_service "/clusters" GET "$USER_AUTH_TOKEN" | jq -r .[].id)
if [[ "${cluster_id}" = "" ]]; then
sleep 2
fi
Expand All @@ -28,7 +28,7 @@ status_issue="90_start-install"
num_known_hosts() {
local known_hosts=0
local insufficient_hosts=0
host_status=$(curl_assisted_service "/infra-envs/${INFRA_ENV_ID}/hosts" GET $USER_AUTH_TOKEN | jq -r .[].status)
host_status=$(curl_assisted_service "/infra-envs/${INFRA_ENV_ID}/hosts" GET "$USER_AUTH_TOKEN" | jq -r .[].status)
if [[ -n ${host_status} ]]; then
for status in ${host_status}; do
if [[ "${status}" == "known" ]]; then
Expand Down Expand Up @@ -58,15 +58,15 @@ clear_issue "${status_issue}"
while [[ "${cluster_status}" != "installed" ]]
do
sleep 5
cluster_info="$(curl_assisted_service "/clusters" GET $USER_AUTH_TOKEN)"
cluster_info="$(curl_assisted_service "/clusters" GET "$USER_AUTH_TOKEN")"
cluster_status=$(printf '%s' "${cluster_info}" | jq -r .[].status)
echo "Cluster status: ${cluster_status}" 1>&2
# Start the cluster install, if it transitions back to Ready due to a failure,
# then it will be restarted
case "${cluster_status}" in
"ready")
echo "Starting cluster installation..." 1>&2
res=$(curl_assisted_service "/clusters/${cluster_id}/actions/install" POST $USER_AUTH_TOKEN -w "%{http_code}" -o /dev/null)
res=$(curl_assisted_service "/clusters/${cluster_id}/actions/install" POST "$USER_AUTH_TOKEN" -w "%{http_code}" -o /dev/null)
if [[ $res = "202" ]]; then
printf '\nCluster installation started\n' 1>&2
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source "common.sh"

echo "Waiting for assisted-service to be ready"

until curl_assisted_service "/infra-envs" GET $USER_AUTH_TOKEN -o /dev/null --silent --fail; do
until curl_assisted_service "/infra-envs" GET "$USER_AUTH_TOKEN" -o /dev/null --silent --fail; do
printf '.'
sleep 5
done
1 change: 0 additions & 1 deletion pkg/asset/agent/gencrypto/auth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func ParseToken(tokenString string) (jwt.MapClaims, error) {
return claims, nil
}


// ParseExpirationFromToken checks if the token is expired or not.
func ParseExpirationFromToken(tokenString string) (time.Time, error) {
claims, err := ParseToken(tokenString)
Expand Down
8 changes: 4 additions & 4 deletions pkg/asset/agent/gencrypto/authconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ var (

// AuthType holds the authenticator type for agent based installer.
const (
AuthType = "agent-installer-local"
agentPersona = "agentAuth"
userPersona = "userAuth"
AuthType = "agent-installer-local"
agentPersona = "agentAuth"
userPersona = "userAuth"
watcherPersona = "watcherAuth"
)

Expand Down Expand Up @@ -99,7 +99,7 @@ func (a *AuthConfig) Generate(_ context.Context, dependencies asset.Parents) err
// Auth tokens expires after 48 hours
expiry := time.Now().UTC().Add(48 * time.Hour)
a.AuthTokenExpiry = expiry.Format(time.RFC3339)

agentAuthToken, err := generateToken(agentPersona, privateKey, &expiry)
if err != nil {
return err
Expand Down
16 changes: 9 additions & 7 deletions pkg/asset/agent/gencrypto/authconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,23 @@ func TestAuthConfig_Generate(t *testing.T) {
assert.NotEqual(t, authConfigAsset.UserAuthToken, authConfigAsset.WatcherAuthToken)

// verify each token is signed with correct persona
claims , err := ParseToken(authConfigAsset.AgentAuthToken)
claims, err := ParseToken(authConfigAsset.AgentAuthToken)
assert.NoError(t, err)
persona, _ := claims["sub"].(string)
persona, ok := claims["sub"].(string)
assert.Equal(t, persona, agentPersona)
assert.Equal(t, ok, true)

claims , err = ParseToken(authConfigAsset.UserAuthToken)
claims, err = ParseToken(authConfigAsset.UserAuthToken)
assert.NoError(t, err)
persona, _ = claims["sub"].(string)
persona, ok = claims["sub"].(string)
assert.Equal(t, persona, userPersona)
assert.Equal(t, ok, true)

claims , err = ParseToken(authConfigAsset.WatcherAuthToken)
claims, err = ParseToken(authConfigAsset.WatcherAuthToken)
assert.NoError(t, err)
persona, _ = claims["sub"].(string)
persona, ok = claims["sub"].(string)
assert.Equal(t, persona, watcherPersona)

assert.Equal(t, ok, true)
})
}
}
17 changes: 11 additions & 6 deletions pkg/asset/agent/image/ignition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ func TestIgnition_getTemplateData(t *testing.T) {
clusterName := "test-agent-cluster-install.test"

publicKey := "-----BEGIN EC PUBLIC KEY-----\nMHcCAQEEIOSCfDNmx0qe6dncV4tg==\n-----END EC PUBLIC KEY-----\n"
token := "someToken"
agentAuthToken := "agentAuthToken"
userAuthToken := "userAuthToken"
watcherAuthToken := "watcherAuthToken"
rendezvousIP := "192.168.111.80"
templateData := getTemplateData(clusterName, pullSecret, releaseImageList, releaseImage, releaseImageMirror, publicContainerRegistries, "minimal-iso", infraEnvID, publicKey, gencrypto.AuthType, token, "", "", haveMirrorConfig, agentClusterInstall.Spec.ProvisionRequirements.ControlPlaneAgents, agentClusterInstall.Spec.ProvisionRequirements.WorkerAgents, osImage, proxy, rendezvousIP)
templateData := getTemplateData(clusterName, pullSecret, releaseImageList, releaseImage, releaseImageMirror, publicContainerRegistries, "minimal-iso", infraEnvID, publicKey, gencrypto.AuthType, agentAuthToken, userAuthToken, watcherAuthToken, "", "", haveMirrorConfig, agentClusterInstall.Spec.ProvisionRequirements.ControlPlaneAgents, agentClusterInstall.Spec.ProvisionRequirements.WorkerAgents, osImage, proxy, rendezvousIP)
assert.Equal(t, clusterName, templateData.ClusterName)
assert.Equal(t, "http", templateData.ServiceProtocol)
assert.Equal(t, pullSecret, templateData.PullSecret)
Expand All @@ -111,17 +113,20 @@ func TestIgnition_getTemplateData(t *testing.T) {
assert.Equal(t, proxy, templateData.Proxy)
assert.Equal(t, publicKey, templateData.PublicKeyPEM)
assert.Equal(t, gencrypto.AuthType, templateData.AuthType)
assert.Equal(t, token, templateData.Token)
assert.Equal(t, agentAuthToken, templateData.AgentAuthToken)
assert.Equal(t, userAuthToken, templateData.UserAuthToken)
assert.Equal(t, watcherAuthToken, templateData.WatcherAuthToken)
assert.Equal(t, rendezvousIP, templateData.RendezvousIP)

}

func TestIgnition_getRendezvousHostEnv(t *testing.T) {
nodeZeroIP := "2001:db8::dead:beef"
token := "someToken"
rendezvousHostEnv := getRendezvousHostEnv("http", nodeZeroIP, token, workflow.AgentWorkflowTypeInstall)
agentAuthtoken := "agentAuthtoken"
userAuthToken := "userAuthToken"
rendezvousHostEnv := getRendezvousHostEnv("http", nodeZeroIP, agentAuthtoken, userAuthToken, workflow.AgentWorkflowTypeInstall)
assert.Equal(t,
"NODE_ZERO_IP="+nodeZeroIP+"\nSERVICE_BASE_URL=http://["+nodeZeroIP+"]:8090/\nIMAGE_SERVICE_BASE_URL=http://["+nodeZeroIP+"]:8888/\nAGENT_AUTH_TOKEN="+token+"\nPULL_SECRET_TOKEN="+token+"\nWORKFLOW_TYPE=install\n",
"NODE_ZERO_IP="+nodeZeroIP+"\nSERVICE_BASE_URL=http://["+nodeZeroIP+"]:8090/\nIMAGE_SERVICE_BASE_URL=http://["+nodeZeroIP+"]:8888/\nPULL_SECRET_TOKEN="+agentAuthtoken+"\nUSER_AUTH_TOKEN="+userAuthToken+"\nWORKFLOW_TYPE=install\n",
rendezvousHostEnv)
}

Expand Down

0 comments on commit 92f3583

Please sign in to comment.