Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Fix for issue 471 - non-interactive authentication #473

Merged
merged 3 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions libs/python/btp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def create_subaccount(self):

subaccount = createSubaccountName(self)
subdomain = createSubdomainID(self)

log.success("using subaccount name >" + subaccount + "<")
log.success("using subaccount domain >" + subdomain + "<")

Expand All @@ -469,7 +469,7 @@ def create_subaccount(self):
)

subaccountExist = checkIfSubaccountAlreadyExists(self)

if subaccountExist is None:
command = (
"btp --format json create accounts/subaccount \
Expand Down Expand Up @@ -544,13 +544,13 @@ def create_subaccount(self):
+ "<"
)
self.subaccountid = subaccountid
self.subdomain = subdomain
self.subdomain = subdomain

self.accountMetadata = addKeyValuePair(
accountMetadata, "subaccountid", subaccountid
accountMetadata, "subaccountid", subaccountid
)
self.accountMetadata = addKeyValuePair(
accountMetadata, "subdomain", subdomain
accountMetadata, "subdomain", subdomain
)

self.subaccountid = subaccountid
Expand Down Expand Up @@ -1397,7 +1397,7 @@ def checkIfSubaccountAlreadyExists(btpUsecase: BTPUSECASE):
+ "'"
)
result = runCommandAndGetJsonResult(btpUsecase, command, "INFO", None)

if "subaccount" in accountMetadata:
subaccountName = accountMetadata["subaccount"]

Expand Down
67 changes: 46 additions & 21 deletions libs/python/helperCommandExecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,59 @@ def login_cf(btpUsecase):

cfApiEndpoint = accountMetadata["cfapiendpoint"]

message = (
"Logging-in to your CF environment in the org >"
+ org
+ "< for your user >"
+ myemail
+ "<",
)

command = None
pipe = False
if btpUsecase.loginmethod == "sso":
# Interactive login with SSO
# Limitation: If more than one CF space exists, the execution will fail due to interactive data entry
# error message is: "inappropriate ioctl for device"
# This is an issue with the CF API and not with the script
command = "cf login -a '" + cfApiEndpoint + "' -o '" + org + "' --sso"
pipe = True

runShellCommandFlex(
btpUsecase,
command,
"INFO",
message,
True,
pipe,
)

else:
password = escapePassword(password)

command = (
"cf login -a '"
# NON-Interactive login with user and password
# To avoid failure due to interaction in case of multiple spaces, we use the manual authentication flow
# Step 1 - set api endpoint
command = "cf api " + cfApiEndpoint
message = (
"Non-interactive login step 1: set CF API endpoint to >"
+ cfApiEndpoint
+ "' -o '"
+ org
+ "' -u '"
+ "<"
)
runShellCommandFlex(btpUsecase, command, "INFO", message, True, pipe)

# Step 2 - login
command = "cf auth " + myemail + " " + password
message = (
"Non-interactive login step 2: authenticate to CF with user >"
+ myemail
+ "' -p '"
+ password
+ "'"
+ "<"
)
runShellCommandFlex(
btpUsecase,
command,
"INFO",
"Logging-in to your CF environment in the org >"
+ org
+ "< for your user >"
+ myemail
+ "<",
True,
pipe,
)
runShellCommandFlex(btpUsecase, command, "INFO", message, True, pipe)

# Step 3 - set org
command = "cf target -o " + org
message = "Non-interactive login step 3: set CF org to >" + org + "<"
runShellCommandFlex(btpUsecase, command, "INFO", message, True, pipe)


def login_btp(btpUsecase):
Expand Down Expand Up @@ -143,6 +165,9 @@ def runShellCommandFlex(btpUsecase, command, format, info, exitIfError, noPipe):
log.command(commandToBeLogged)
foundPassword = True
break
if "cf auth" in command:
log.command("cf auth xxxxxxxxxxxxxxxxx")
foundPassword = True
if foundPassword is False:
log.command(command)
p = None
Expand Down