예제 #1
0
def get_or_create_user(user: model.User):
    sdm_user = next(client.accounts.list(f'email:{user.email}'), None)
    if not sdm_user:
        new_user = strongdm.User(
            email=user.email,
            first_name=user.first_name,
            last_name=user.last_name,
        )
        response = client.accounts.create(new_user, timeout=30)
        sdm_user = response.account
    return sdm_user
#
import os
import strongdm

# Load the SDM API keys from the environment.
# If these values are not set in your environment,
# please follow the documentation here:
# https://www.strongdm.com/docs/admin-guide/api-credentials/
api_access_key = os.getenv("SDM_API_ACCESS_KEY")
api_secret_key = os.getenv("SDM_API_SECRET_KEY")
client = strongdm.Client(api_access_key, api_secret_key)

# Create a user
user = strongdm.User(
    email="*****@*****.**",
    first_name="example",
    last_name="example",
)

user_response = client.accounts.create(user, timeout=30)

print("Successfully created user.")
print("\tEmail:", user_response.account.email)
print("\tID:", user_response.account.id)

# Create a role
role = strongdm.Role(name="example role", )

role_response = client.roles.create(role, timeout=30)

print("Successfully created role.")
                         {
                             "tags": {
                                 "example": "grant-access"
                             },
                         },
                     ])

role_response = client.roles.create(role, timeout=30)

print("Successfully created role.")
print("\tID:", role_response.role.id)

# Create a user
user = strongdm.User(
    email="*****@*****.**",
    first_name="example",
    last_name="example",
)

user_response = client.accounts.create(user, timeout=30)

print("Successfully created user.")
print("\tEmail:", user_response.account.email)
print("\tID:", user_response.account.id)

# Attach the user to the role
grant = strongdm.AccountAttachment(account_id=user_response.account.id,
                                   role_id=role_response.role.id)

attachment_response = client.account_attachments.create(grant, timeout=30)
#
import os
import strongdm

# Load the SDM API keys from the environment.
# If these values are not set in your environment,
# please follow the documentation here:
# https://www.strongdm.com/docs/admin-guide/api-credentials/
api_access_key = os.getenv("SDM_API_ACCESS_KEY")
api_secret_key = os.getenv("SDM_API_SECRET_KEY")
client = strongdm.Client(api_access_key, api_secret_key)

# Create an account
user = strongdm.User(
    email="*****@*****.**",
    first_name="example",
    last_name="example",
)
response = client.accounts.create(user, timeout=30)
print("Successfully created user.")
print("\tEmail:", response.account.email)
print("\tID:", response.account.id)

# Get the account
get_response = client.accounts.get(response.account.id, timeout=30)
account = get_response.account

# Set fields
account.suspended = True

# Update the account
import os
import datetime
import strongdm

# Load the SDM API keys from the environment.
# If these values are not set in your environment,
# please follow the documentation here:
# https://www.strongdm.com/docs/admin-guide/api-credentials/
api_access_key = os.getenv("SDM_API_ACCESS_KEY")
api_secret_key = os.getenv("SDM_API_SECRET_KEY")
client = strongdm.Client(api_access_key, api_secret_key)

# Create a user
user = strongdm.User(
    email="*****@*****.**",
    first_name="example",
    last_name="example",
)

user_response = client.accounts.create(user, timeout=30)

print("Successfully created user.")
print("\tEmail:", user_response.account.email)
print("\tID:", user_response.account.id)

# Create a datasource
postgres = strongdm.Postgres(
    name="Example Postgres Datasource for Temp Grant",
    hostname="example.strongdm.com",
    port=5432,
    username="******",
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import strongdm

# Load the SDM API keys from the environment.
# If these values are not set in your environment,
# please follow the documentation here:
# https://www.strongdm.com/docs/admin-guide/api-credentials/
api_access_key = os.getenv("SDM_API_ACCESS_KEY")
api_secret_key = os.getenv("SDM_API_SECRET_KEY")
client = strongdm.Client(api_access_key, api_secret_key)

# Create an account
user = strongdm.User(
    email="*****@*****.**",
    first_name="example",
    last_name="example",
)
response = client.accounts.create(user, timeout=30)
print("Successfully created user.")
print("\tEmail:", response.account.email)
print("\tID:", response.account.id)

# Delete an account
client.accounts.delete(response.account.id, timeout=30)
print("Successfully deleted account.")