def signalr_create(client, signalr_name, resource_group_name, sku, unit_count=1, location=None, tags=None, service_mode='Default', enable_message_logs=False, allowed_origins=None, default_action="Allow"): sku = ResourceSku(name=sku, capacity=unit_count) service_mode_feature = SignalRFeature(flag="ServiceMode", value=service_mode) enable_message_logs_feature = SignalRFeature(flag="EnableMessagingLogs", value=enable_message_logs) cors_setting = SignalRCorsSettings(allowed_origins=allowed_origins) parameter = SignalRResource( tags=tags, sku=sku, host_name_prefix=signalr_name, features=[service_mode_feature, enable_message_logs_feature], cors=cors_setting, location=location, network_ac_ls=SignalRNetworkACLs(default_action=default_action)) return client.create_or_update(resource_group_name, signalr_name, parameter)
def signalr_msi_assign(client, resource_group_name, signalr_name, identity): msiType, user_identity = _analyze_identity(identity) identity = ManagedIdentity( type=msiType, userAssignedidentity={user_identity, None} if user_identity else None) parameter = SignalRResource(identity=identity) return client.begin_update(resource_group_name, signalr_name, parameter)
def signalr_cors_add(client, resource_group_name, signalr_name, allowed_origins): cors = _get_cors_details(client, resource_group_name, signalr_name) if cors is None: cors = SignalRCorsSettings(allowed_origins=[]) cors.allowed_origins = cors.allowed_origins + allowed_origins parameters = SignalRResource(cors=cors) return client.update(resource_group_name, signalr_name, parameters)
def signalr_cors_remove(client, resource_group_name, signalr_name, allowed_origins): cors = _get_cors_details(client, resource_group_name, signalr_name) if cors is None: cors = SignalRCorsSettings(allowed_origins=[]) cors.allowed_origins = [ x for x in cors.allowed_origins if x not in allowed_origins ] if not cors.allowed_origins: cors.allowed_origins = ['*'] parameters = SignalRResource(cors=cors) return client.update(resource_group_name, signalr_name, parameters)
def update_network_rules(client, signalr_name, resource_group_name, public_network, connection_name=[], allow=[], deny=[]): resource = client.get(resource_group_name, signalr_name) network_acl = resource.network_ac_ls if public_network: network_acl.public_network.allow = allow network_acl.public_network.deny = deny if network_acl.private_endpoints: for x in network_acl.private_endpoints: if x.name in connection_name: x.allow = allow x.deny = deny return client.update(resource_group_name, signalr_name, SignalRResource(network_ac_ls=network_acl))
def signalr_upstream_clear(client, resource_group_name, signalr_name): upstream = ServerlessUpstreamSettings(templates=[]) parameters = SignalRResource(upstream=upstream) return client.update(resource_group_name, signalr_name, parameters)
def signalr_msi_remove(client, resource_group_name, signalr_name): identity = ManagedIdentity(type="None") parameter = SignalRResource(identity=identity) return client.begin_update(resource_group_name, signalr_name, parameter)
def signalr_update_get(): return SignalRResource()
def signalr_cors_update(client, resource_group_name, signalr_name, allowed_origins): cors = SignalRCorsSettings(allowed_origins=allowed_origins) parameters = SignalRResource(cors=cors) return client.begin_update(resource_group_name, signalr_name, parameters)