Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Merge requests
!211
Feature/add sharepoint service
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feature/add sharepoint service
feature/add-sharepoint-service
into
develop
Overview
1
Commits
13
Pipelines
5
Changes
11
Merged
Karel van Klink
requested to merge
feature/add-sharepoint-service
into
develop
11 months ago
Overview
1
Commits
13
Pipelines
5
Changes
11
Expand
Add a SharePoint service that can create new list items for approval checklists.
Edited
11 months ago
by
Karel van Klink
0
0
Merge request reports
Compare
develop
version 4
0fcd4266
11 months ago
version 3
612dc95a
11 months ago
version 2
00c4b526
11 months ago
version 1
0b8b5ea3
11 months ago
develop (base)
and
latest version
latest version
245132e1
13 commits,
11 months ago
version 4
0fcd4266
12 commits,
11 months ago
version 3
612dc95a
12 commits,
11 months ago
version 2
00c4b526
8 commits,
11 months ago
version 1
0b8b5ea3
7 commits,
11 months ago
11 files
+
177
−
46
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
11
Search (e.g. *.vue) (Ctrl+P)
gso/services/sharepoint.py
0 → 100644
+
79
−
0
Options
"""
Sharepoint service used for creating new list items.
"""
import
asyncio
from
azure.identity.aio
import
CertificateCredential
from
msgraph
import
GraphServiceClient
from
msgraph.generated.models.field_value_set
import
FieldValueSet
from
msgraph.generated.models.list_item
import
ListItem
from
msgraph.generated.models.list_item_collection_response
import
ListItemCollectionResponse
from
msgraph.generated.models.site
import
Site
from
msgraph.generated.sites.item.lists.item.items.items_request_builder
import
ItemsRequestBuilder
from
gso.settings
import
load_oss_params
class
SharePointClient
:
"""
A client for interaction with SharePoint lists.
"""
def
__init__
(
self
)
->
None
:
"""
Initialise a new SharePoint client.
"""
sp_params
=
load_oss_params
().
SHAREPOINT
_credentials
=
CertificateCredential
(
tenant_id
=
sp_params
.
tenant_id
,
client_id
=
sp_params
.
client_id
,
certificate_path
=
sp_params
.
certificate_path
,
password
=
sp_params
.
certificate_password
,
)
self
.
client
=
GraphServiceClient
(
_credentials
,
sp_params
.
scopes
)
self
.
site_id
=
sp_params
.
site_id
self
.
list_ids
=
sp_params
.
list_ids
def
get_site
(
self
)
->
Site
|
None
:
"""
Get the SharePoint site that this orchestrator connects to.
"""
async
def
_get_site
()
->
Site
|
None
:
return
await
self
.
client
.
sites
.
by_site_id
(
self
.
site_id
).
get
()
return
asyncio
.
run
(
_get_site
())
def
get_list_items
(
self
,
list_name
:
str
)
->
ListItemCollectionResponse
|
None
:
"""
Get list items from a given list in SharePoint.
:param str list_name: The name of the list.
"""
async
def
_get_list_items
()
->
ListItemCollectionResponse
|
None
:
query_params
=
ItemsRequestBuilder
.
ItemsRequestBuilderGetQueryParameters
(
expand
=
[
"
fields
"
])
request_configuration
=
ItemsRequestBuilder
.
ItemsRequestBuilderGetRequestConfiguration
(
query_parameters
=
query_params
)
return
(
await
self
.
client
.
sites
.
by_site_id
(
self
.
site_id
)
.
lists
.
by_list_id
(
self
.
list_ids
[
list_name
])
.
items
.
get
(
request_configuration
=
request_configuration
)
)
return
asyncio
.
run
(
_get_list_items
())
def
add_list_item
(
self
,
list_name
:
str
,
fields
:
dict
[
str
,
str
])
->
str
:
"""
Add a new entry to a SharePoint list.
:param str list_name: The name of the list.
:param dict[str, str] fields: Any pre-filled fields in the list item. Can be left empty.
:return str: The URL of the list in which a new item has been created.
"""
async
def
_new_list_item
()
->
str
:
request_body
=
ListItem
(
fields
=
FieldValueSet
(
additional_data
=
fields
))
new_item
=
(
await
self
.
client
.
sites
.
by_site_id
(
self
.
site_id
)
.
lists
.
by_list_id
(
self
.
list_ids
[
list_name
])
.
items
.
post
(
request_body
)
)
# Strip the last part of the URL, since we want the link to the list, not the list item.
return
new_item
.
web_url
.
rsplit
(
"
/
"
,
1
)[
0
]
return
asyncio
.
run
(
_new_list_item
())
Loading