Skip to content
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

lightspeed: use the code value from the 403 #1024

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
18 changes: 18 additions & 0 deletions src/features/lightspeed/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ export class LightSpeedAPI {
vscode.window.showErrorMessage(
`Model ID "${this.settingsManager.settings.lightSpeedService.model}" is invalid. Please contact your administrator.`
);
} else if (
responseErrorData &&
responseErrorData.hasOwnProperty("code") &&
responseErrorData.code ===
"permission_denied__org_ready_user_has_no_seat"
) {
vscode.window.showErrorMessage(
`You do not have a licensed seat for Ansible Lightspeed and your organization is using the paid commercial service. Contact your Red Hat Organization's administrator for more information on how to get a licensed seat.`
);
} else if (
responseErrorData &&
responseErrorData.hasOwnProperty("code") &&
responseErrorData.code ===
"permission_denied__org_not_ready_because_wca_not_configured"
) {
vscode.window.showErrorMessage(
`Contact your administrator to configure IBM watsonx Code Assistant model settings for your organization.`
);
} else {
vscode.window.showErrorMessage(
`User not authorized to access Ansible Lightspeed.`
Expand Down
28 changes: 27 additions & 1 deletion src/features/lightspeed/lightSpeedOAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ export class LightSpeedAuthenticationProvider

const identifier = uuid();
const userName = userinfo.external_username || userinfo.username || "";
const rhOrgHasSubscription = userinfo.rh_org_has_subscription
? userinfo.rh_org_has_subscription
: false;
const rhUserHasSeat = userinfo.rh_user_has_seat
? userinfo.rh_user_has_seat
: false;

let label = userName;
if (rhUserHasSeat) {
label += " (licensed)";
} else if (rhOrgHasSubscription) {
label += " (no seat assigned)";
} else {
label += " (Tech Preview)";
}
Expand Down Expand Up @@ -172,7 +177,8 @@ export class LightSpeedAuthenticationProvider

lightSpeedManager.statusBarProvider.statusBar.text =
await lightSpeedManager.statusBarProvider.getLightSpeedStatusBarText(
rhUserHasSeat
rhUserHasSeat,
rhOrgHasSubscription
);

lightSpeedManager.statusBarProvider.setLightSpeedStatusBarTooltip(
Expand Down Expand Up @@ -630,4 +636,24 @@ export class LightSpeedAuthenticationProvider
return false;
}
}

public async rhOrgHasSubscription(): Promise<boolean | undefined> {
const authSession = await this.getLightSpeedAuthSession();
if (authSession === undefined) {
console.log(
"[ansible-lightspeed-oauth] User authentication session not found."
);
return undefined;
} else if (authSession?.rhOrgHasSubscription) {
console.log(
`[ansible-lightspeed-oauth] User "${authSession?.account?.label}" has an Org with a subscription.`
);
return true;
} else {
console.log(
`[ansible-lightspeed-oauth] User "${authSession?.account?.label}" does not have an Org with a subscription.`
);
return false;
}
}
}
9 changes: 8 additions & 1 deletion src/features/lightspeed/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@ export class LightspeedStatusBar {
}

public async getLightSpeedStatusBarText(
rhUserHasSeat?: boolean
rhUserHasSeat?: boolean,
rhOrgHasSubscription?: boolean
): Promise<string> {
let lightSpeedStatusbarText;
if (rhUserHasSeat === undefined) {
rhUserHasSeat = await this.lightSpeedAuthProvider.rhUserHasSeat();
}
if (rhOrgHasSubscription === undefined) {
rhOrgHasSubscription =
await this.lightSpeedAuthProvider.rhOrgHasSubscription();
}
if (rhUserHasSeat === true) {
lightSpeedStatusbarText = "Lightspeed (licensed)";
} else if (rhOrgHasSubscription === true && rhUserHasSeat === false) {
lightSpeedStatusbarText = "Lightspeed (no seat assigned)";
} else if (rhUserHasSeat === false) {
lightSpeedStatusbarText = "Lightspeed (Tech Preview)";
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/features/lightspeed/utils/webUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export function getLoggedInSessionDetails(
const modelInfo: LightspeedSessionModelInfo = {};
if (sessionData.rhUserHasSeat) {
userInfo.userType = "Licensed";
} else if (sessionData.rhOrgHasSubscription && sessionData.rhUserHasSeat) {
userInfo.userType = "No seat assigned";
} else {
userInfo.userType = "Tech Preview";
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/lightspeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface IAdditionalContext {
}

export interface LightspeedSessionUserInfo {
userType?: "Licensed" | "Tech Preview";
userType?: "Licensed" | "No seat assigned" | "Tech Preview";
role?: string;
subscribed?: boolean;
}
Expand Down
Loading