Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IP Connectivity Checker
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coscine
backend
scripts
IP Connectivity Checker
Merge requests
!5
Release: Sprint/2022 15
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Release: Sprint/2022 15
dev
into
main
Overview
0
Commits
2
Pipelines
0
Changes
9
Merged
Petar Hristov
requested to merge
dev
into
main
2 years ago
Overview
0
Commits
2
Pipelines
0
Changes
9
Expand
This Merge Request is automatically created
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
4ea832dc
2 commits,
2 years ago
9 files
+
582
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
9
Search (e.g. *.vue) (Ctrl+P)
src/IPConnectivityChecker/Implementations/ECSChecker.cs
0 → 100644
+
141
−
0
Options
using
Amazon.S3
;
using
Coscine.Database.DataModel
;
using
Coscine.Database.Models
;
using
Coscine.ECSManager
;
using
Coscine.ResourceTypes
;
using
Coscine.ResourceTypes.Base
;
using
Coscine.ResourceTypes.RdsS3
;
using
Coscine.ResourceTypes.RdsWorm
;
using
ResourceTypes.Rds
;
namespace
IPConnectivityChecker.Implementations
{
public
class
ECSChecker
{
public
async
Task
<
bool
>
CheckECS
()
{
var
resourceTypeModel
=
new
ResourceTypeModel
();
var
resourceTypes
=
resourceTypeModel
.
GetAll
();
var
working
=
true
;
foreach
(
var
resourceType
in
resourceTypes
)
{
if
(
resourceType
.
Type
.
Contains
(
"rds"
))
{
Console
.
WriteLine
(
"Checking resourcetype with type '"
+
resourceType
.
Type
+
"' and specific type '"
+
resourceType
.
SpecificType
+
"'!"
);
BaseResourceType
resourceTypeDefinition
;
try
{
resourceTypeDefinition
=
ResourceTypeFactory
.
Instance
.
GetResourceType
(
resourceType
.
Type
,
resourceType
.
SpecificType
);
}
catch
(
Exception
e
)
{
Console
.
WriteLine
(
"Error on resourcetype with type '"
+
resourceType
.
Type
+
"' and specific type '"
+
resourceType
.
SpecificType
+
"'!"
);
Console
.
WriteLine
(
e
);
working
=
false
;
continue
;
}
if
(
resourceType
.
Type
==
"rds"
)
{
var
rdsResourceTypeDefinition
=
(
RdsResourceType
)
resourceTypeDefinition
;
var
rdsResourceTypeConfiguration
=
rdsResourceTypeDefinition
.
RdsResourceTypeConfiguration
;
working
=
working
&&
await
S3ClientCheck
(
rdsResourceTypeConfiguration
.
Endpoint
,
rdsResourceTypeConfiguration
.
AccessKey
,
rdsResourceTypeConfiguration
.
SecretKey
,
resourceType
);
var
ecsManager
=
new
EcsManager
{
EcsManagerConfiguration
=
rdsResourceTypeConfiguration
.
EcsManagerConfiguration
};
working
=
working
&&
await
LoginToECS
(
ecsManager
.
EcsManagerConfiguration
,
resourceType
);
}
else
if
(
resourceType
.
Type
==
"rdss3"
)
{
var
rdss3ResourceTypeDefinition
=
(
RdsS3ResourceType
)
resourceTypeDefinition
;
var
rdsS3ResourceTypeConfiguration
=
rdss3ResourceTypeDefinition
.
RdsS3ResourceTypeConfiguration
;
working
=
working
&&
await
S3ClientCheck
(
rdsS3ResourceTypeConfiguration
.
Endpoint
,
rdsS3ResourceTypeConfiguration
.
AccessKey
,
rdsS3ResourceTypeConfiguration
.
SecretKey
,
resourceType
);
var
rdsS3EcsManager
=
new
EcsManager
{
EcsManagerConfiguration
=
rdsS3ResourceTypeConfiguration
.
RdsS3EcsManagerConfiguration
};
working
=
working
&&
await
LoginToECS
(
rdsS3EcsManager
.
EcsManagerConfiguration
,
resourceType
);
var
userEcsManager
=
new
EcsManager
{
EcsManagerConfiguration
=
rdsS3ResourceTypeConfiguration
.
UserEcsManagerConfiguration
};
working
=
working
&&
await
LoginToECS
(
userEcsManager
.
EcsManagerConfiguration
,
resourceType
);
}
else
if
(
resourceType
.
Type
==
"rdss3worm"
)
{
var
rdss3wormResourceTypeDefinition
=
(
RdsS3WormResourceType
)
resourceTypeDefinition
;
var
rdsS3WormResourceTypeConfiguration
=
rdss3wormResourceTypeDefinition
.
RdsS3WormResourceTypeConfiguration
;
working
=
working
&&
await
S3ClientCheck
(
rdsS3WormResourceTypeConfiguration
.
Endpoint
,
rdsS3WormResourceTypeConfiguration
.
AccessKey
,
rdsS3WormResourceTypeConfiguration
.
SecretKey
,
resourceType
);
var
rdsS3EcsManager
=
new
EcsManager
{
EcsManagerConfiguration
=
rdsS3WormResourceTypeConfiguration
.
RdsS3EcsManagerConfiguration
};
working
=
working
&&
await
LoginToECS
(
rdsS3EcsManager
.
EcsManagerConfiguration
,
resourceType
);
var
userEcsManager
=
new
EcsManager
{
EcsManagerConfiguration
=
rdsS3WormResourceTypeConfiguration
.
UserEcsManagerConfiguration
};
working
=
working
&&
await
LoginToECS
(
userEcsManager
.
EcsManagerConfiguration
,
resourceType
);
}
Console
.
WriteLine
();
}
}
return
working
;
}
private
async
Task
<
bool
>
S3ClientCheck
(
string
endpoint
,
string
accessKey
,
string
secretKey
,
ResourceType
resourceType
)
{
try
{
var
amazonS3Config
=
new
AmazonS3Config
{
ServiceURL
=
endpoint
,
ForcePathStyle
=
true
};
using
var
_s3client
=
new
AmazonS3Client
(
accessKey
,
secretKey
,
amazonS3Config
);
await
_s3client
.
ListBucketsAsync
();
}
catch
(
Exception
e
)
{
Console
.
WriteLine
(
"S3 Client Check: FAILED for resourcetype with type '"
+
resourceType
.
Type
+
"' and specific type '"
+
resourceType
.
SpecificType
+
"'!"
);
Console
.
WriteLine
(
e
);
return
false
;
}
return
true
;
}
private
async
Task
<
bool
>
LoginToECS
(
EcsManagerConfiguration
EcsManagerConfiguration
,
ResourceType
resourceType
)
{
try
{
// create new management client USING NAMESPACE ADMINISTRATOR to obtain token
using
var
client
=
new
CoscineECSManagementClient
(
EcsManagerConfiguration
.
NamespaceAdminName
,
EcsManagerConfiguration
.
NamespaceAdminPassword
,
EcsManagerConfiguration
.
ManagerApiEndpoint
);
// authenticate
await
client
.
Authenticate
();
// log out
await
client
.
LogOut
();
}
catch
(
Exception
e
)
{
Console
.
WriteLine
(
"Login Check: FAILED for resourcetype with type '"
+
resourceType
.
Type
+
"' and specific type '"
+
resourceType
.
SpecificType
+
"'!"
);
Console
.
WriteLine
(
e
);
return
false
;
}
return
true
;
}
}
}
Loading