Skip to content

Commit a31d993

Browse files
author
Matthias Prost
authored
fix: new api endpoint for account and added usages of IAM (#23)
* fix: new api endpoint for account and added usages of IAM * fix: build gradle
1 parent 68e2531 commit a31d993

File tree

12 files changed

+72
-58
lines changed

12 files changed

+72
-58
lines changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "com.matthiasprost.scalewaymanager"
77
minSdkVersion rootProject.ext.minSdkVersion
88
targetSdkVersion rootProject.ext.targetSdkVersion
9-
versionCode 20300
10-
versionName "2.3.0"
9+
versionCode 20301
10+
versionName "2.3.1"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {

src/app/pages/account/account.page.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@
3333

3434
<div *ngIf="!isLoading">
3535
<div class="name">
36-
<div class="two-auth-enabled" *ngIf="user.double_auth_enabled">
36+
<div class="two-auth-enabled" *ngIf="user.mfa_enabled">
3737
<ion-chip>
3838
<ion-label color="light">
3939
<fa-icon [icon]="faShieldAlt"></fa-icon>
4040
2FA
4141
</ion-label>
4242
</ion-chip>
4343
</div>
44-
<div class="two-auth-disabled" *ngIf="!user.double_auth_enabled">
44+
<div class="two-auth-disabled" *ngIf="!user.mfa_enabled">
4545
<ion-chip>
4646
<ion-label color="light">
4747
<fa-icon [icon]="danger"></fa-icon>
4848
2FA
4949
</ion-label>
5050
</ion-chip>
5151
</div>
52-
<div class="fullname">{{ user.fullname }}</div>
52+
<div class="fullname">{{ user.first_name + ' ' + user.last_name }}</div>
5353
<div class="email">{{ user.email }}</div>
5454
<div class="current-organization">
5555
<div class="current-organization-text">

src/app/pages/account/tokens/tokens.page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<ion-label>
3333
<div class="information-title-content">{{ token.access_key }}</div>
3434
<div class="description-left">{{ token.creation_ip }}</div>
35-
<div class="description-right">{{ token.creation_date | date }}</div>
35+
<div class="description-right">{{ token.created_at | date }}</div>
3636
</ion-label>
3737
</ion-item>
3838
<ion-item-options>

src/app/services/api/api.service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class ApiService {
120120

121121
const result = await this.httpClient.request<any>(
122122
"POST",
123-
this.getAccountApiUrl() + "/jwt/" + token.jwt.jti + "/renew",
123+
this.getAccountApiUrlV1() + "/jwt/" + token.jwt.jti + "/renew",
124124
{
125125
body: { jwt_renew: token.auth.jwt_renew },
126126
}).toPromise();
@@ -135,10 +135,18 @@ export class ApiService {
135135
}
136136
}
137137

138-
public getAccountApiUrl(): string {
138+
public getAccountApiUrlV1(): string {
139139
return this.api + "/account/v1";
140140
}
141141

142+
public getAccountApiUrlV2(): string {
143+
return this.api + "/account/v2";
144+
}
145+
146+
public getIAMApiUrl(): string {
147+
return this.api + "/iam/v1alpha1";
148+
}
149+
142150
public getInstanceUrl(): string {
143151
return this.api + "/instance/v1/zones/";
144152
}

src/app/services/api/object-api.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,25 @@ export class ObjectApiService {
6363
method: HttpMethods[method.toString()],
6464
};
6565

66+
6667
// We get token in storage
6768
const currentProject = await this.projectService.getCurrentProjectId();
6869
const apiTokenStorage = await this.storage.get("apiTokenByProject");
6970

7071
let apiToken = apiTokenStorage && apiTokenStorage[currentProject];
71-
const currentOrganizationId = await this.storage.get("currentOrganization");
72-
7372
// If aws token doesn't exist we create new and store it
74-
if (!apiToken || apiToken.token.organization_id !== currentOrganizationId) {
73+
if (!apiToken) {
7574
apiToken = await this.renewToken();
7675
}
7776

77+
7878
console.log("AWS-TOKEN", apiToken);
7979

8080
try {
8181
// Create AWS Signature
8282
aws4.sign(opts, {
83-
accessKeyId: apiToken.token.access_key,
84-
secretAccessKey: apiToken.token.secret_key,
83+
accessKeyId: apiToken.access_key,
84+
secretAccessKey: apiToken.secret_key,
8585
});
8686
console.log("AWS-OPTIONS", opts);
8787

src/app/services/user/account/account.dto.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ export interface UsersDto {
33
}
44

55
export interface UserDto {
6-
creation_date: string;
7-
double_auth_enabled: boolean;
6+
created_at: string;
7+
mfa_enabled: boolean;
88
email: string;
9-
firstname: string;
10-
fullname: string;
11-
id: string;
12-
lastname: string;
13-
modification_date: string;
9+
first_name: string;
10+
account_root_user_id: string;
11+
last_name: string;
12+
updated_at: string;
1413
organizations: any;
1514
phone_number: string;
1615
roles: any;

src/app/services/user/account/account.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Storage } from "@ionic/storage";
33

44
import { ApiService } from "../../api/api.service";
55

6-
import { UserDto, UsersDto } from "./account.dto";
6+
import { UserDto } from "./account.dto";
77

88
@Injectable({
99
providedIn: "root",
@@ -14,11 +14,11 @@ export class AccountService {
1414
public async getUserData(): Promise<UserDto> {
1515
try {
1616
const token = await this.storage.get("jwt");
17-
const result = await this.api.get<UsersDto>(
18-
this.api.getAccountApiUrl() + "/users/" + token.jwt.issuer
17+
const result = await this.api.get<UserDto>(
18+
this.api.getAccountApiUrlV2() + "/users/" + token.jwt.issuer
1919
);
2020

21-
return result.user;
21+
return result;
2222
} catch (e) {
2323
throw e;
2424
}

src/app/services/user/auth/auth.service.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NavController } from "@ionic/angular";
33
import { Storage } from "@ionic/storage";
44

55
import { ApiService } from "../../api/api.service";
6+
import {UserDto} from "../account/account.dto";
67
import { AccountService } from "../account/account.service";
78
import { ProjectService } from "../project/project.service";
89

@@ -34,7 +35,7 @@ export class AuthService {
3435
// eslint-disable-next-line no-useless-catch
3536
try {
3637
const result = await this.api.post<any>(
37-
this.api.getAccountApiUrl() + "/jwt",
38+
this.api.getAccountApiUrlV1() + "/jwt",
3839
{
3940
email,
4041
password,
@@ -46,15 +47,16 @@ export class AuthService {
4647

4748
await this.storage.set("jwt", result);
4849

49-
const data = await this.api.get<any>(
50-
this.api.getAccountApiUrl() + "/users/" + result.jwt.issuer
50+
const data = await this.api.get<UserDto>(
51+
this.api.getAccountApiUrlV2() + "/users/" + result.jwt.issuer
5152
);
52-
await this.storage.set("user", data.user);
53+
54+
await this.storage.set("user", data);
5355

5456
const currentOrganization =
55-
data.user.organizations.find(
56-
(organization) => organization.role_name === "owner"
57-
) || data.user.organizations[0];
57+
data.organizations.find(
58+
(organization) => organization.is_owner === true
59+
) || data.organizations[0];
5860
await this.storage.set("currentOrganization", currentOrganization.id);
5961

6062
await this.projectService.setDefaultProject(currentOrganization.id);
@@ -67,7 +69,7 @@ export class AuthService {
6769
console.log("LOGGING OUT");
6870
const token = await this.storage.get("jwt");
6971
await this.api.delete<any>(
70-
this.api.getAccountApiUrl() + "/jwt/" + token.jwt.jti
72+
this.api.getIAMApiUrl() + "/jwts/" + token.jwt.jti
7173
);
7274
await this.storage.clear();
7375
await this.navCtrl.navigateRoot(["/login"]);

src/app/services/user/project/project.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class ProjectService {
1919

2020
// tslint:disable-next-line:max-line-length
2121
const result = await this.api.get<ProjectsDto>(
22-
`${this.api.getApiUrl()}/account/v2/projects?organization_id=${organizationId}&page_size=50&page=1`
22+
`${this.api.getAccountApiUrlV2()}/projects?organization_id=${organizationId}&page_size=50&page=1`
2323
);
2424
return result.projects;
2525
}
@@ -63,7 +63,7 @@ export class ProjectService {
6363
try {
6464
const token = await this.storage.get("jwt");
6565
const result = await this.api.patch<UsersDto>(
66-
this.api.getAccountApiUrl() + "/users/" + token.jwt.issuer,
66+
this.api.getAccountApiUrlV2() + "/users/" + token.jwt.issuer,
6767
{
6868
ssh_public_keys: keys,
6969
}

src/app/services/user/project/ssh-key/ssh-keys.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class SshKeysService {
1818
try {
1919
const currentProject = await this.projectService.getCurrentProject();
2020
const result = await this.api.get<SshKeysDto>(
21-
`${this.api.getApiUrl()}/account/v2alpha1/ssh-keys/?project_id=${
21+
`${this.api.getApiUrl()}/iam/v1alpha1/ssh-keys/?project_id=${
2222
currentProject.id
2323
}`
2424
);
@@ -32,7 +32,7 @@ export class SshKeysService {
3232
public async addSShKey(sshKey: string) {
3333
try {
3434
const currentProject = await this.projectService.getCurrentProject();
35-
await this.api.post(`${this.api.getApiUrl()}/account/v2alpha1/ssh-keys`, {
35+
await this.api.post(`${this.api.getApiUrl()}/iam/v1alpha1/ssh-keys`, {
3636
project_id: currentProject.id,
3737
public_key: sshKey,
3838
});
@@ -44,7 +44,7 @@ export class SshKeysService {
4444
public async deleteSShKey(sshKeyId: string) {
4545
try {
4646
await this.api.delete(
47-
`${this.api.getApiUrl()}/account/v2alpha1/ssh-key/${sshKeyId}`
47+
`${this.api.getApiUrl()}/iam/v1alpha1/ssh-key/${sshKeyId}`
4848
);
4949
} catch (e) {
5050
throw e;

0 commit comments

Comments
 (0)