Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aliyun/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .logitem import LogItem
from .consumer_group_request import *
from .external_store_config import *
from .resource_policy import ResourcePolicyResourceType

# response class
from .consumer_group_response import *
Expand Down Expand Up @@ -55,6 +56,7 @@
from .multimodal_config_response import GetLogStoreMultimodalConfigurationResponse, \
PutLogStoreMultimodalConfigurationResponse
from .object_response import PutObjectResponse, GetObjectResponse
from .resource_policy_response import PutResourcePolicyResponse, GetResourcePolicyResponse, DeleteResourcePolicyResponse

from .store_view import StoreView, StoreViewStore
from .store_view_response import CreateStoreViewResponse, UpdateStoreViewResponse, DeleteStoreViewResponse, ListStoreViewsResponse, GetStoreViewResponse
Expand Down
2 changes: 2 additions & 0 deletions aliyun/log/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from .version import __version__ as __version__
from .logitem import LogItem as LogItem
from .consumer_group_request import CreateConsumerGroupRequest as CreateConsumerGroupRequest, ConsumerGroupGetCheckPointRequest as ConsumerGroupGetCheckPointRequest, ConsumerGroupHeartBeatRequest as ConsumerGroupHeartBeatRequest, ConsumerGroupUpdateCheckPointRequest as ConsumerGroupUpdateCheckPointRequest
from .external_store_config import ExternalStoreConfig as ExternalStoreConfig, ExternalStoreConfigBase as ExternalStoreConfigBase, ExternalStoreCsvConfig as ExternalStoreCsvConfig, ExternalStoreOssConfig as ExternalStoreOssConfig
from .resource_policy import ResourcePolicyResourceType as ResourcePolicyResourceType

from .consumer_group_response import ConsumerGroupEntity as ConsumerGroupEntity, ConsumerGroupCheckPointResponse as ConsumerGroupCheckPointResponse, ConsumerGroupHeartBeatResponse as ConsumerGroupHeartBeatResponse, ConsumerGroupUpdateCheckPointResponse as ConsumerGroupUpdateCheckPointResponse, CreateConsumerGroupResponse as CreateConsumerGroupResponse, DeleteConsumerGroupResponse as DeleteConsumerGroupResponse, ListConsumerGroupResponse as ListConsumerGroupResponse, UpdateConsumerGroupResponse as UpdateConsumerGroupResponse
from .cursor_response import GetCursorResponse as GetCursorResponse
Expand Down Expand Up @@ -54,6 +55,7 @@ from .metering_mode_response import GetLogStoreMeteringModeResponse as GetLogSto
from .multimodal_config_response import GetLogStoreMultimodalConfigurationResponse as GetLogStoreMultimodalConfigurationResponse, \
PutLogStoreMultimodalConfigurationResponse as PutLogStoreMultimodalConfigurationResponse
from .object_response import PutObjectResponse as PutObjectResponse, GetObjectResponse as GetObjectResponse
from .resource_policy_response import PutResourcePolicyResponse as PutResourcePolicyResponse, GetResourcePolicyResponse as GetResourcePolicyResponse, DeleteResourcePolicyResponse as DeleteResourcePolicyResponse

from .store_view import StoreView as StoreView, StoreViewStore as StoreViewStore
from .store_view_response import CreateStoreViewResponse as CreateStoreViewResponse, UpdateStoreViewResponse as UpdateStoreViewResponse, DeleteStoreViewResponse as DeleteStoreViewResponse, ListStoreViewsResponse as ListStoreViewsResponse, GetStoreViewResponse as GetStoreViewResponse
Expand Down
116 changes: 114 additions & 2 deletions aliyun/log/logclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
from .putlogsresponse import PutLogsResponse
from .shard_response import *
from .shipper_response import *
from .resource_response import *
from .resource_params import *
from .resource_response import *
from .resource_params import *
from .resource_policy import ResourcePolicyResourceType
from .resource_policy_response import *
from .tag_response import GetResourceTagsResponse
from .topostore_response import *
from .topostore_params import *
Expand Down Expand Up @@ -3298,6 +3300,116 @@ def delete_project(self, project_name):
(resp, header) = self._send("DELETE", project_name, None, resource, params, headers)
return DeleteProjectResponse(header, resp)

@staticmethod
def _validate_resource_policy_target(project_name, resource_type):
if not project_name:
raise LogException("InvalidParameter", "project_name must not be empty")
if resource_type not in (
ResourcePolicyResourceType.PROJECT,
ResourcePolicyResourceType.LOGSTORE):
raise LogException(
"InvalidParameter",
"resource_type must be project or logstore"
)

def put_resource_policy(self, project_name, resource_type, policy_document,
resource_name=None, dry_run=False):
"""Create or update a resource policy for a project or logstore.

:type project_name: string
:param project_name: the project name

:type resource_type: string
:param resource_type: ``project`` or ``logstore``

:type policy_document: string
:param policy_document: the JSON policy document

:type resource_name: string
:param resource_name: optional resource name; required by the service for logstore policies

:type dry_run: bool
:param dry_run: validate the policy without persisting it

:return: PutResourcePolicyResponse

:raise: LogException
"""
self._validate_resource_policy_target(project_name, resource_type)
if not policy_document:
raise LogException("InvalidParameter", "policy_document must not be empty")

body = {
"resourceType": resource_type,
"policyDocument": policy_document,
"dryRun": bool(dry_run),
}
if resource_name:
body["resourceName"] = resource_name

body_str = six.b(json.dumps(body))
headers = {
"Content-Type": "application/json",
"x-log-bodyrawsize": str(len(body_str)),
}
(resp, header) = self._send(
"PUT", project_name, body_str, "/resource-policies", {}, headers
)
return PutResourcePolicyResponse(header, resp)

def get_resource_policy(self, project_name, resource_type, resource_name=None):
"""Get a resource policy for a project or logstore.

:type project_name: string
:param project_name: the project name

:type resource_type: string
:param resource_type: ``project`` or ``logstore``

:type resource_name: string
:param resource_name: optional resource name; required by the service for logstore policies

:return: GetResourcePolicyResponse

:raise: LogException
"""
self._validate_resource_policy_target(project_name, resource_type)
params = {"resourceType": resource_type}
if resource_name:
params["resourceName"] = resource_name

(resp, header) = self._send(
"GET", project_name, None, "/resource-policies", params,
{"Content-Type": "application/json"}
)
return GetResourcePolicyResponse(resp, header)

def delete_resource_policy(self, project_name, resource_type, resource_name=None):
"""Delete a resource policy for a project or logstore.

:type project_name: string
:param project_name: the project name

:type resource_type: string
:param resource_type: ``project`` or ``logstore``

:type resource_name: string
:param resource_name: optional resource name; required by the service for logstore policies

:return: DeleteResourcePolicyResponse

:raise: LogException
"""
self._validate_resource_policy_target(project_name, resource_type)
params = {"resourceType": resource_type}
if resource_name:
params["resourceName"] = resource_name

(resp, header) = self._send(
"DELETE", project_name, None, "/resource-policies", params, {}
)
return DeleteResourcePolicyResponse(header, resp)

def change_resource_group(self, resource_id, resource_group_id, resource_type="PROJECT"):
"""
Update the resource group of project
Expand Down
4 changes: 4 additions & 0 deletions aliyun/log/logclient.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ from .putlogsresponse import PutLogsResponse
from .rebuild_index_response import CreateRebuildIndexResponse, GetRebuildIndexResponse
from .resource_params import Resource, ResourceRecord
from .resource_response import CreateRecordResponse, CreateResourceResponse, DeleteRecordResponse, DeleteResourceResponse, GetRecordResponse, GetResourceResponse, ListRecordResponse, ListResourcesResponse, UpdateRecordResponse, UpdateResourceResponse, UpsertRecordResponse
from .resource_policy_response import DeleteResourcePolicyResponse, GetResourcePolicyResponse, PutResourcePolicyResponse
from .scheduled_sql import ScheduledSQL, ScheduledSQLConfiguration
from .scheduled_sql_response import CreateScheduledSQLResponse, DeleteScheduledSQLResponse, GetScheduledSQLResponse, GetScheduledSqlJobInstanceResponse, ListScheduledSQLResponse, ListScheduledSqlJobInstancesResponse, ModifyScheduledSqlJobStateResponse, UpdateScheduledSQLResponse
from .shard_response import DeleteShardResponse, ListShardResponse
Expand Down Expand Up @@ -170,6 +171,9 @@ class LogClient(object):
def update_project(self, project_name: str, project_des: str) -> UpdateProjectResponse: ...
def get_project(self, project_name: str) -> GetProjectResponse: ...
def delete_project(self, project_name: str) -> DeleteProjectResponse: ...
def put_resource_policy(self, project_name: str, resource_type: str, policy_document: str, resource_name: Optional[str] = ..., dry_run: bool = ...) -> PutResourcePolicyResponse: ...
def get_resource_policy(self, project_name: str, resource_type: str, resource_name: Optional[str] = ...) -> GetResourcePolicyResponse: ...
def delete_resource_policy(self, project_name: str, resource_type: str, resource_name: Optional[str] = ...) -> DeleteResourcePolicyResponse: ...
def change_resource_group(self, resource_id: str, resource_group_id: str, resource_type: str = ...) -> LogResponse: ...
def tag_project(self, project_name: str, **tags: Any) -> LogResponse: ...
def untag_project(self, project_name: str, *tag_keys: Any) -> LogResponse: ...
Expand Down
12 changes: 12 additions & 0 deletions aliyun/log/resource_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python
# encoding: utf-8

# Copyright (C) Alibaba Cloud Computing
# All rights reserved.


class ResourcePolicyResourceType(object):
"""Resource types supported by the Resource Policy API."""

PROJECT = "project"
LOGSTORE = "logstore"
6 changes: 6 additions & 0 deletions aliyun/log/resource_policy.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-


class ResourcePolicyResourceType:
PROJECT: str
LOGSTORE: str
69 changes: 69 additions & 0 deletions aliyun/log/resource_policy_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python
# encoding: utf-8

# Copyright (C) Alibaba Cloud Computing
# All rights reserved.

from .logresponse import LogResponse
from .util import Util

__all__ = [
"PutResourcePolicyResponse",
"GetResourcePolicyResponse",
"DeleteResourcePolicyResponse",
]


class PutResourcePolicyResponse(LogResponse):
"""The response of the put_resource_policy API."""

def __init__(self, header, resp=""):
LogResponse.__init__(self, header, resp)


class GetResourcePolicyResponse(LogResponse):
"""The response of the get_resource_policy API."""

def __init__(self, resp, header):
LogResponse.__init__(self, header, resp)
self.resource_type = Util.convert_unicode_to_str(resp["resourceType"])
self.resource_name = Util.convert_unicode_to_str(resp.get("resourceName", ""))
self.policy_document = Util.convert_unicode_to_str(resp["policyDocument"])
self.revision = int(resp["revision"])
self.create_time = int(resp["createTime"])
self.update_time = int(resp["updateTime"])

def get_resource_type(self):
return self.resource_type

def get_resource_name(self):
return self.resource_name

def get_policy_document(self):
return self.policy_document

def get_revision(self):
return self.revision

def get_create_time(self):
return self.create_time

def get_update_time(self):
return self.update_time

def log_print(self):
print("GetResourcePolicyResponse:")
print("headers:", self.get_all_headers())
print("resource_type:", self.resource_type)
print("resource_name:", self.resource_name)
print("policy_document:", self.policy_document)
print("revision:", self.revision)
print("create_time:", self.create_time)
print("update_time:", self.update_time)


class DeleteResourcePolicyResponse(LogResponse):
"""The response of the delete_resource_policy API."""

def __init__(self, header, resp=""):
LogResponse.__init__(self, header, resp)
29 changes: 29 additions & 0 deletions aliyun/log/resource_policy_response.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from typing import Any, Dict

from .logresponse import LogResponse


class PutResourcePolicyResponse(LogResponse):
def __init__(self, header: Dict[str, Any], resp: Any = ...) -> None: ...


class GetResourcePolicyResponse(LogResponse):
resource_type: str
resource_name: str
policy_document: str
revision: int
create_time: int
update_time: int
def __init__(self, resp: Dict[str, Any], header: Dict[str, Any]) -> None: ...
def get_resource_type(self) -> str: ...
def get_resource_name(self) -> str: ...
def get_policy_document(self) -> str: ...
def get_revision(self) -> int: ...
def get_create_time(self) -> int: ...
def get_update_time(self) -> int: ...
def log_print(self) -> None: ...


class DeleteResourcePolicyResponse(LogResponse):
def __init__(self, header: Dict[str, Any], resp: Any = ...) -> None: ...
2 changes: 1 addition & 1 deletion aliyun/log/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.9.49'
__version__ = '0.9.50'

import sys
OS_VERSION = str(sys.platform)
Expand Down
Loading
Loading