Skip to content

Commit 075a59b

Browse files
committed
common: sm: iam: move perm handler itf to common iamclient
Signed-off-by: Oleksandr Grytsov <[email protected]>
1 parent 5c4e02d commit 075a59b

File tree

20 files changed

+216
-114
lines changed

20 files changed

+216
-114
lines changed

src/core/common/config.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,10 @@
604604
#endif
605605

606606
/**
607-
* Certificate secret size.
607+
* Secret len.
608608
*/
609-
#ifndef AOS_CONFIG_TYPES_CERT_SECRET_SIZE
610-
#define AOS_CONFIG_TYPES_CERT_SECRET_SIZE 64
609+
#ifndef AOS_CONFIG_TYPES_SECRET_LEN
610+
#define AOS_CONFIG_TYPES_SECRET_LEN 64
611611
#endif
612612

613613
/**
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (C) 2025 EPAM Systems, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef AOS_CORE_COMMON_IAMCLIENT_ITF_PERMHANDLER_HPP_
8+
#define AOS_CORE_COMMON_IAMCLIENT_ITF_PERMHANDLER_HPP_
9+
10+
#include <core/common/types/permissions.hpp>
11+
12+
namespace aos::iamclient {
13+
14+
/**
15+
* Permission handler interface.
16+
*/
17+
class PermHandlerItf {
18+
public:
19+
/**
20+
* Destroys permission handler interface.
21+
*/
22+
virtual ~PermHandlerItf() = default;
23+
24+
/**
25+
* Adds new service instance and its permissions into cache.
26+
*
27+
* @param instanceIdent instance identification.
28+
* @param instancePermissions instance permissions.
29+
* @returns RetWithError<StaticString<cSecretLen>>.
30+
*/
31+
virtual RetWithError<StaticString<cSecretLen>> RegisterInstance(
32+
const InstanceIdent& instanceIdent, const Array<FunctionServicePermissions>& instancePermissions)
33+
= 0;
34+
35+
/**
36+
* Unregisters instance deletes service instance with permissions from cache.
37+
*
38+
* @param instanceIdent instance identification.
39+
* @returns Error.
40+
*/
41+
virtual Error UnregisterInstance(const InstanceIdent& instanceIdent) = 0;
42+
};
43+
44+
} // namespace aos::iamclient
45+
46+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2025 EPAM Systems, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef AOS_CORE_COMMON_IAMCLIENT_ITF_PERMPROVIDER_HPP_
8+
#define AOS_CORE_COMMON_IAMCLIENT_ITF_PERMPROVIDER_HPP_
9+
10+
#include <core/common/types/permissions.hpp>
11+
12+
namespace aos::iamclient {
13+
14+
/**
15+
* Permission provider interface.
16+
*/
17+
class PermProviderItf {
18+
public:
19+
/**
20+
* Destroys permission provider interface.
21+
*/
22+
virtual ~PermProviderItf() = default;
23+
24+
/**
25+
* Returns instance ident and permissions by secret and functional server ID.
26+
*
27+
* @param secret secret.
28+
* @param funcServerID functional server ID.
29+
* @param[out] instanceIdent result instance ident.
30+
* @param[out] servicePermissions result service permission.
31+
* @returns Error.
32+
*/
33+
virtual Error GetPermissions(const String& secret, const String& funcServerID, InstanceIdent& instanceIdent,
34+
Array<FunctionPermissions>& servicePermissions)
35+
= 0;
36+
};
37+
38+
} // namespace aos::iamclient
39+
40+
#endif

src/core/common/tests/mocks/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ set(HEADERS
2525
logprovidermock.hpp
2626
monitoringmock.hpp
2727
ocispecmock.hpp
28+
permhandlermock.hpp
29+
permprovidermock.hpp
2830
spaceallocatormock.hpp
2931
)
3032

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
/*
3+
* Copyright (C) 2025 EPAM Systems, Inc.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#ifndef AOS_CORE_COMMON_TESTS_MOCKS_IAMCLIENTMOCK_HPP_
9+
#define AOS_CORE_COMMON_TESTS_MOCKS_IAMCLIENTMOCK_HPP_
10+
11+
#include <gmock/gmock.h>
12+
13+
#include <core/common/iamclient/itf/certprovider.hpp>
14+
15+
namespace aos::iamclient {
16+
17+
/**
18+
* Certificate listener mock.
19+
*/
20+
class CertListenerMock : public CertListenerItf {
21+
public:
22+
MOCK_METHOD(void, OnCertChanged, (const CertInfo& info), (override));
23+
};
24+
25+
/**
26+
* Mocks certificate provider.
27+
*/
28+
29+
class CertProviderMock : public CertProviderItf {
30+
public:
31+
MOCK_METHOD(Error, GetCert,
32+
(const String& certType, const Array<uint8_t>& issuer, const Array<uint8_t>& serial, CertInfo& resCert),
33+
(const override));
34+
MOCK_METHOD(Error, SubscribeListener, (const String& certType, CertListenerItf& certListener), (override));
35+
MOCK_METHOD(Error, UnsubscribeListener, (CertListenerItf & certListener), (override));
36+
};
37+
38+
} // namespace aos::iamclient
39+
40+
#endif

src/core/iam/tests/mocks/permhandlermock.hpp renamed to src/core/common/tests/mocks/permhandlermock.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
#include <gmock/gmock.h>
1111

12-
#include <core/iam/permhandler/permhandler.hpp>
12+
#include <core/common/iamclient/itf/permhandler.hpp>
1313

14-
namespace aos::iam::permhandler {
14+
namespace aos::iamclient {
1515

1616
/**
1717
* Permission handler mock.
@@ -21,10 +21,8 @@ class PermHandlerMock : public PermHandlerItf {
2121
MOCK_METHOD(RetWithError<StaticString<cSecretLen>>, RegisterInstance,
2222
(const InstanceIdent&, const Array<FunctionServicePermissions>&), (override));
2323
MOCK_METHOD(Error, UnregisterInstance, (const InstanceIdent&), (override));
24-
MOCK_METHOD(
25-
Error, GetPermissions, (const String&, const String&, InstanceIdent&, Array<FunctionPermissions>&), (override));
2624
};
2725

28-
} // namespace aos::iam::permhandler
26+
} // namespace aos::iamclient
2927

3028
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2024 EPAM Systems, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef AOS_CORE_IAM_TESTS_MOCKS_PERMHANDLERMOCK_HPP_
8+
#define AOS_CORE_IAM_TESTS_MOCKS_PERMHANDLERMOCK_HPP_
9+
10+
#include <gmock/gmock.h>
11+
12+
#include <core/common/iamclient/itf/permprovider.hpp>
13+
14+
namespace aos::iamclient {
15+
16+
/**
17+
* Permission provider mock.
18+
*/
19+
class PermProviderMock : public PermProviderItf {
20+
public:
21+
MOCK_METHOD(
22+
Error, GetPermissions, (const String&, const String&, InstanceIdent&, Array<FunctionPermissions>&), (override));
23+
};
24+
25+
} // namespace aos::iamclient
26+
27+
#endif

src/core/common/types/certificates.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ struct CertIdent {
5757
* Node secret.
5858
*/
5959
struct NodeSecret {
60-
StaticString<cIDLen> mNodeID;
61-
StaticString<cCertSecretSize> mSecret;
60+
StaticString<cIDLen> mNodeID;
61+
StaticString<cSecretLen> mSecret;
6262

6363
/**
6464
* Compares node secrets.

src/core/common/types/common.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ constexpr auto cLabelNameLen = AOS_CONFIG_TYPES_LABEL_NAME_LEN;
8989
constexpr auto cMaxNumNodeLabels = AOS_CONFIG_TYPES_MAX_NUM_NODE_LABELS;
9090

9191
/**
92-
* Certificate secret size.
92+
* Secret len.
9393
*/
94-
constexpr auto cCertSecretSize = AOS_CONFIG_TYPES_CERT_SECRET_SIZE;
94+
constexpr auto cSecretLen = AOS_CONFIG_TYPES_SECRET_LEN;
9595

9696
/*
9797
* OS type len.

src/core/common/types/permissions.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ struct FunctionServicePermissions {
7171
StaticArray<FunctionPermissions, cFunctionsMaxCount> mPermissions;
7272
};
7373

74+
/**
75+
* Instance permissions.
76+
*/
77+
struct InstancePermissions : public InstanceIdent {
78+
StaticString<cSecretLen> mSecret;
79+
StaticArray<FunctionServicePermissions, cFuncServiceMaxCount> mFuncServicePerms;
80+
81+
/**
82+
* Creates instance permissions.
83+
*
84+
* @param instanceIdent instance ident.
85+
* @param secret secret.
86+
* @param funcServicePerms functional service permissions.
87+
*/
88+
InstancePermissions(const InstanceIdent& instanceIdent, const String& secret,
89+
const Array<FunctionServicePermissions>& funcServicePerms)
90+
: InstanceIdent(instanceIdent)
91+
, mSecret(secret)
92+
, mFuncServicePerms(funcServicePerms)
93+
{
94+
}
95+
};
96+
7497
} // namespace aos
7598

7699
#endif

0 commit comments

Comments
 (0)