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
GitLab 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
Expand sidebar
Merged
Feature/add sharepoint service
feature/add-sharepoint-service
into
develop
Overview
1
Commits
13
Pipelines
5
Changes
11
Merged
Feature/add sharepoint service
Karel van Klink
requested to merge
feature/add-sharepoint-service
into
develop
May 2, 2024
Overview
1
Commits
13
Pipelines
5
Changes
11
Add a SharePoint service that can create new list items for approval checklists.
Edited
May 22, 2024
by
Karel van Klink
0
0
Merge request reports
Compare
develop
version 4
0fcd4266
May 21, 2024
version 3
612dc95a
May 8, 2024
version 2
00c4b526
May 2, 2024
version 1
0b8b5ea3
May 2, 2024
develop (base)
and
latest version
latest version
245132e1
13 commits,
May 22, 2024
version 4
0fcd4266
12 commits,
May 21, 2024
version 3
612dc95a
12 commits,
May 8, 2024
version 2
00c4b526
8 commits,
May 2, 2024
version 1
0b8b5ea3
7 commits,
May 2, 2024
11 files
+
177
−
46
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
11
gso/services/sharepoint.py
0 → 100644
+
79
−
0
View file @ 245132e1
Edit in single-file editor
Open in Web IDE
"""
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