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

[Question] Each Operation API & API policy in each environment #732

Closed
Setthawut-Peace opened this issue Feb 19, 2025 · 3 comments
Closed

Comments

@Setthawut-Peace
Copy link

Setthawut-Peace commented Feb 19, 2025

Release version

v6.0.1.4

Question Details

How to handle if i have a specific policy in each environment. Example

Operation API 001 - Policy [DEV]

<policies>
	<inbound>
		<base />
			<rewrite-uri template="/api/get/0010" copy-unmatched-params="true" />
	</inbound>
	<backend>
		<base />
	</backend>
	<outbound>
		<base />
	</outbound>
	<on-error>
		<base />
	</on-error>
</policies>

Operation API 001 - Policy [PRD]

<policies>
	<inbound>
		<base />
			<set-backend-service base-url="https://api.openweathermap.org/data/2.5/weather" />
			<rewrite-uri template="/api/" copy-unmatched-params="true" />
			<set-header name="x-rapidapi-key" exists-action="override">
				<value>abc1234</value>
			</set-header>
	</inbound>
	<backend>
		<base />
	</backend>
	<outbound>
		<base />
	</outbound>
	<on-error>
		<base />
	</on-error>
</policies>

Expected behavior

I need to using APIs & Operation APIs policy in each environment.

Actual behavior

Not able to find solution on how to override policy in each environment

Reproduction Steps

Not able to find solution on how to override policy in each environment

Copy link

  Thank you for opening this issue! Please be patient while we will look into it and get back to you as this is an open source project. In the meantime make sure you take a look at the [closed issues](https://github.com/Azure/apiops/issues?q=is%3Aissue+is%3Aclosed) in case your question has already been answered. Don't forget to provide any additional information if needed (e.g. scrubbed logs, detailed feature requests,etc.).
  Whenever it's feasible, please don't hesitate to send a Pull Request (PR) our way. We'd greatly appreciate it, and we'll gladly assess and incorporate your changes.

@JamesProant
Copy link

JamesProant commented Feb 20, 2025

Hi @Setthawut-Peace
I don't believe it is possible to acheive this in APIOps. But here is a workaround that you can use until there is a better solution. It is not the most elegant solution, but this will acheive what you are looking for.
Add this statement below to your policy and replace the "apim-dev" and "apim-prd" with the actual name of your DEV and PRD apim names. Hope this helps.

        <choose>
            <when condition="@(context.Deployment.ServiceId == "apim-dev")">
                <rewrite-uri template="/api/get/0010" copy-unmatched-params="true" />
            </when>
            <when condition="@(context.Deployment.ServiceId == "apim-prd")">
                <set-backend-service base-url="https://api.openweathermap.org/data/2.5/weather" />
                <rewrite-uri template="/api/" copy-unmatched-params="true" />
                <set-header name="x-rapidapi-key" exists-action="override">
                    <value>abc1234</value>
                </set-header>
            </when>
        </choose>

@Setthawut-Peace
Copy link
Author

Hi @Setthawut-Peace I don't believe it is possible to acheive this in APIOps. But here is a workaround that you can use until there is a better solution. It is not the most elegant solution, but this will acheive what you are looking for. Add this statement below to your policy and replace the "apim-dev" and "apim-prd" with the actual name of your DEV and PRD apim names. Hope this helps.

    <choose>
        <when condition="@(context.Deployment.ServiceId == "apim-dev")">
            <rewrite-uri template="/api/get/0010" copy-unmatched-params="true" />
        </when>
        <when condition="@(context.Deployment.ServiceId == "apim-prd")">
            <set-backend-service base-url="https://api.openweathermap.org/data/2.5/weather" />
            <rewrite-uri template="/api/" copy-unmatched-params="true" />
            <set-header name="x-rapidapi-key" exists-action="override">
                <value>abc1234</value>
            </set-header>
        </when>
    </choose>

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants