OpenStack Identity (Keystone)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

98 lines
3.5 KiB

  1. # Copyright 2014 IBM Corp.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. import sqlalchemy as sql
  15. from keystone.common.sql import upgrades
  16. import keystone.conf
  17. CONF = keystone.conf.CONF
  18. _RELAY_STATE_PREFIX = 'relay_state_prefix'
  19. def upgrade(migrate_engine):
  20. try:
  21. extension_version = upgrades.get_db_version(
  22. extension='federation',
  23. engine=migrate_engine)
  24. except Exception:
  25. extension_version = 0
  26. # This migration corresponds to federation extension migration 8. Only
  27. # update if it has not been run.
  28. if extension_version >= 8:
  29. return
  30. # Upgrade operations go here. Don't create your own engine; bind
  31. # migrate_engine to your metadata
  32. meta = sql.MetaData()
  33. meta.bind = migrate_engine
  34. idp_table = sql.Table(
  35. 'identity_provider',
  36. meta,
  37. sql.Column('id', sql.String(64), primary_key=True),
  38. sql.Column('enabled', sql.Boolean, nullable=False),
  39. sql.Column('description', sql.Text(), nullable=True),
  40. mysql_engine='InnoDB',
  41. mysql_charset='utf8')
  42. idp_table.create(migrate_engine, checkfirst=True)
  43. federation_protocol_table = sql.Table(
  44. 'federation_protocol',
  45. meta,
  46. sql.Column('id', sql.String(64), primary_key=True),
  47. sql.Column('idp_id', sql.String(64),
  48. sql.ForeignKey('identity_provider.id', ondelete='CASCADE'),
  49. primary_key=True),
  50. sql.Column('mapping_id', sql.String(64), nullable=False),
  51. mysql_engine='InnoDB',
  52. mysql_charset='utf8')
  53. federation_protocol_table.create(migrate_engine, checkfirst=True)
  54. mapping_table = sql.Table(
  55. 'mapping',
  56. meta,
  57. sql.Column('id', sql.String(64), primary_key=True),
  58. sql.Column('rules', sql.Text(), nullable=False),
  59. mysql_engine='InnoDB',
  60. mysql_charset='utf8')
  61. mapping_table.create(migrate_engine, checkfirst=True)
  62. relay_state_prefix_default = CONF.saml.relay_state_prefix
  63. sp_table = sql.Table(
  64. 'service_provider',
  65. meta,
  66. sql.Column('auth_url', sql.String(256), nullable=False),
  67. sql.Column('id', sql.String(64), primary_key=True),
  68. sql.Column('enabled', sql.Boolean, nullable=False),
  69. sql.Column('description', sql.Text(), nullable=True),
  70. sql.Column('sp_url', sql.String(256), nullable=False),
  71. sql.Column(_RELAY_STATE_PREFIX, sql.String(256), nullable=False,
  72. server_default=relay_state_prefix_default),
  73. mysql_engine='InnoDB',
  74. mysql_charset='utf8')
  75. sp_table.create(migrate_engine, checkfirst=True)
  76. idp_table = sql.Table('identity_provider', meta, autoload=True)
  77. remote_id_table = sql.Table(
  78. 'idp_remote_ids',
  79. meta,
  80. sql.Column('idp_id', sql.String(64),
  81. sql.ForeignKey('identity_provider.id', ondelete='CASCADE')),
  82. sql.Column('remote_id', sql.String(255), primary_key=True),
  83. mysql_engine='InnoDB',
  84. mysql_charset='utf8')
  85. remote_id_table.create(migrate_engine, checkfirst=True)