Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data-plane] refresh synapse-access-control-rest #31636

Merged
merged 2 commits into from
Dec 20, 2024
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: 1 addition & 1 deletion sdk/synapse/synapse-access-control-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"dependencies": {
"@azure-rest/core-client": "^2.3.1",
"@azure/core-auth": "^1.9.0",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.18.0",
"tslib": "^2.8.1"
},
Expand Down Expand Up @@ -38,6 +37,7 @@
"module": "./dist/esm/index.js",
"types": "./dist/commonjs/index.d.ts",
"devDependencies": {
"@azure/logger": "^1.0.0",
"@azure-tools/test-credential": "^2.0.0",
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@

import type { ClientOptions } from "@azure-rest/core-client";
import { getClient } from "@azure-rest/core-client";
import { logger } from "./logger.js";
import type { TokenCredential } from "@azure/core-auth";
import type { AccessControlRestClient } from "./clientDefinitions.js";

/** The optional parameters for the client */
export interface AccessControlRestClientOptions extends ClientOptions {
/** The api version option of the client */
apiVersion?: string;
}

/**
* Initialize a new instance of `AccessControlRestClient`
* @param endpoint - The workspace development endpoint, for example `https://myworkspace.dev.azuresynapse.net`.
* @param credentials - uniquely identify client credential
* @param options - the parameter for all optional parameters
*/
export default function createClient(
endpoint: string,
credentials: TokenCredential,
options: ClientOptions = {},
{ apiVersion = "2020-12-01", ...options }: AccessControlRestClientOptions = {},
): AccessControlRestClient {
const baseUrl = options.baseUrl ?? `${endpoint}`;
options.apiVersion = options.apiVersion ?? "2020-12-01";
options = {
...options,
credentials: {
scopes: ["https://dev.azuresynapse.net/.default"],
},
};

const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}`;
const userAgentInfo = `azsdk-js-synapse-access-control-rest/1.0.0-beta.1`;
const userAgentPrefix =
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
Expand All @@ -30,9 +35,31 @@ export default function createClient(
userAgentOptions: {
userAgentPrefix,
},
loggingOptions: {
logger: options.loggingOptions?.logger ?? logger.info,
},
credentials: {
scopes: options.credentials?.scopes ?? ["https://dev.azuresynapse.net/.default"],
},
};
const client = getClient(endpointUrl, credentials, options) as AccessControlRestClient;

client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
client.pipeline.addPolicy({
name: "ClientApiVersionPolicy",
sendRequest: (req, next) => {
// Use the apiVersion defined in request url directly
// Append one if there is no apiVersion and we have one at client options
const url = new URL(req.url);
if (!url.searchParams.get("api-version") && apiVersion) {
req.url = `${req.url}${
Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"
}api-version=${apiVersion}`;
}

const client = getClient(baseUrl, credentials, options) as AccessControlRestClient;
return next(req);
},
});

return client;
}
32 changes: 16 additions & 16 deletions sdk/synapse/synapse-access-control-rest/src/clientDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ import type {
} from "./parameters.js";
import type {
RoleAssignmentsCheckPrincipalAccess200Response,
RoleAssignmentsCheckPrincipalAccessdefaultResponse,
RoleAssignmentsCheckPrincipalAccessDefaultResponse,
RoleAssignmentsListRoleAssignments200Response,
RoleAssignmentsListRoleAssignmentsdefaultResponse,
RoleAssignmentsListRoleAssignmentsDefaultResponse,
RoleAssignmentsCreateRoleAssignment200Response,
RoleAssignmentsCreateRoleAssignmentdefaultResponse,
RoleAssignmentsCreateRoleAssignmentDefaultResponse,
RoleAssignmentsGetRoleAssignmentById200Response,
RoleAssignmentsGetRoleAssignmentByIddefaultResponse,
RoleAssignmentsGetRoleAssignmentByIdDefaultResponse,
RoleAssignmentsDeleteRoleAssignmentById200Response,
RoleAssignmentsDeleteRoleAssignmentById204Response,
RoleAssignmentsDeleteRoleAssignmentByIddefaultResponse,
RoleAssignmentsDeleteRoleAssignmentByIdDefaultResponse,
RoleDefinitionsListRoleDefinitions200Response,
RoleDefinitionsListRoleDefinitionsdefaultResponse,
RoleDefinitionsListRoleDefinitionsDefaultResponse,
RoleDefinitionsGetRoleDefinitionById200Response,
RoleDefinitionsGetRoleDefinitionByIddefaultResponse,
RoleDefinitionsGetRoleDefinitionByIdDefaultResponse,
RoleDefinitionsListScopes200Response,
RoleDefinitionsListScopesdefaultResponse,
RoleDefinitionsListScopesDefaultResponse,
} from "./responses.js";
import type { Client, StreamableMethod } from "@azure-rest/core-client";

Expand All @@ -38,7 +38,7 @@ export interface RoleAssignmentsCheckPrincipalAccess {
options: RoleAssignmentsCheckPrincipalAccessParameters,
): StreamableMethod<
| RoleAssignmentsCheckPrincipalAccess200Response
| RoleAssignmentsCheckPrincipalAccessdefaultResponse
| RoleAssignmentsCheckPrincipalAccessDefaultResponse
>;
}

Expand All @@ -48,7 +48,7 @@ export interface RoleAssignmentsListRoleAssignments {
options?: RoleAssignmentsListRoleAssignmentsParameters,
): StreamableMethod<
| RoleAssignmentsListRoleAssignments200Response
| RoleAssignmentsListRoleAssignmentsdefaultResponse
| RoleAssignmentsListRoleAssignmentsDefaultResponse
>;
}

Expand All @@ -58,22 +58,22 @@ export interface RoleAssignmentsCreateRoleAssignment {
options: RoleAssignmentsCreateRoleAssignmentParameters,
): StreamableMethod<
| RoleAssignmentsCreateRoleAssignment200Response
| RoleAssignmentsCreateRoleAssignmentdefaultResponse
| RoleAssignmentsCreateRoleAssignmentDefaultResponse
>;
/** Get role assignment by role assignment Id. */
get(
options?: RoleAssignmentsGetRoleAssignmentByIdParameters,
): StreamableMethod<
| RoleAssignmentsGetRoleAssignmentById200Response
| RoleAssignmentsGetRoleAssignmentByIddefaultResponse
| RoleAssignmentsGetRoleAssignmentByIdDefaultResponse
>;
/** Delete role assignment by role assignment Id. */
delete(
options?: RoleAssignmentsDeleteRoleAssignmentByIdParameters,
): StreamableMethod<
| RoleAssignmentsDeleteRoleAssignmentById200Response
| RoleAssignmentsDeleteRoleAssignmentById204Response
| RoleAssignmentsDeleteRoleAssignmentByIddefaultResponse
| RoleAssignmentsDeleteRoleAssignmentByIdDefaultResponse
>;
}

Expand All @@ -83,7 +83,7 @@ export interface RoleDefinitionsListRoleDefinitions {
options?: RoleDefinitionsListRoleDefinitionsParameters,
): StreamableMethod<
| RoleDefinitionsListRoleDefinitions200Response
| RoleDefinitionsListRoleDefinitionsdefaultResponse
| RoleDefinitionsListRoleDefinitionsDefaultResponse
>;
}

Expand All @@ -93,7 +93,7 @@ export interface RoleDefinitionsGetRoleDefinitionById {
options?: RoleDefinitionsGetRoleDefinitionByIdParameters,
): StreamableMethod<
| RoleDefinitionsGetRoleDefinitionById200Response
| RoleDefinitionsGetRoleDefinitionByIddefaultResponse
| RoleDefinitionsGetRoleDefinitionByIdDefaultResponse
>;
}

Expand All @@ -102,7 +102,7 @@ export interface RoleDefinitionsListScopes {
get(
options?: RoleDefinitionsListScopesParameters,
): StreamableMethod<
RoleDefinitionsListScopes200Response | RoleDefinitionsListScopesdefaultResponse
RoleDefinitionsListScopes200Response | RoleDefinitionsListScopesDefaultResponse
>;
}

Expand Down
Loading
Loading